Today, I started writing tests commented at http://discuss.gohugo.io/t/hugo-testing-how-to-contribute-and-help/259/4 and found some problems with GroupBy
function of master repository. Here is the list
- Can’t access fields and methods specified in
GroupBy
call -
PagesGroup
doesn’t containPages
. It’s always empty. - When
GroupBy
is called withSection
key, it doesn’t work as expected
No. 1 is caused by https://github.com/spf13/hugo/blob/master/hugolib/pageGroup.go#L83. Go’s field and method names are case sensitive and only those which start with upper case character were exported and accessible. Now the key is forcibly converted into lower case string so GroupBy
tries to call an unexported field or method. One of the way to fix it to convert the first character to upper case but it would cause another problem when it called with a camel cased field or method like PublishDate
so I think simply removing the line is better.
No. 2 is easily fixed by adding tmp.SetMapIndex(fv, reflect.Append(tmp.MapIndex(fv), ppv))
after https://github.com/spf13/hugo/blob/master/hugolib/pageGroup.go#L134 if
block.
No. 3 is more complex. It seems to be caused by “Section” name conflict between field and method. The Page
structure has both of them. The “Section” method is newly introduced one and “Section” field seems to be defined in UrlPath
strcuture, included in Page
. I think “Section” method is what we need but how should it be fixed? Should I rename UrlPath.Section
or change name resolving order (now first search field then method)?
I’d like to hear an opinion or those have already been fixed in someones local repo?