Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources/page: Let GroupByParam return nil instead of error #12579

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions hugolib/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ mainSections=["a", "b"]
{{/* Behaviour before Hugo 0.112.0. */}}
MainSections Params: {{ site.Params.mainSections }}|
MainSections Site method: {{ site.MainSections }}|


`

b := Test(t, files)
Expand Down Expand Up @@ -478,8 +478,8 @@ disableKinds = ['RSS','sitemap','taxonomy','term']
-- layouts/index.html --
MainSections Params: {{ site.Params.mainSections }}|
MainSections Site method: {{ site.MainSections }}|


`

b := Test(t, files)
Expand Down Expand Up @@ -787,9 +787,12 @@ func TestGroupedPages(t *testing.T) {
t.Errorf("PageGroup has unexpected number of pages. First group should have '%d' pages, got '%d' pages", 2, len(byparam[0].Pages))
}

_, err = s.RegularPages().GroupByParam("not_exist")
if err == nil {
t.Errorf("GroupByParam didn't return an expected error")
byNonExistentParam, err := s.RegularPages().GroupByParam("not_exist")
if err != nil {
t.Errorf("GroupByParam returned an error when it shouldn't")
}
if len(byNonExistentParam) != 0 {
t.Errorf("PageGroup array has unexpected elements. Group length should be '%d', got '%d'", 0, len(byNonExistentParam))
}

byOnlyOneParam, err := s.RegularPages().GroupByParam("only_one")
Expand Down
2 changes: 1 addition & 1 deletion resources/page/pagegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error) {
}
}
if !tmp.IsValid() {
return nil, errors.New("there is no such param")
return nil, nil
}

for _, e := range p {
Expand Down
13 changes: 2 additions & 11 deletions resources/page/pagegroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@ func TestGroupByCalledWithEmptyPages(t *testing.T) {
}
}

func TestGroupByParamCalledWithUnavailableKey(t *testing.T) {
t.Parallel()
pages := preparePageGroupTestPages(t)
_, err := pages.GroupByParam("UnavailableKey")
if err == nil {
t.Errorf("GroupByParam should return an error but didn't")
}
}

func TestReverse(t *testing.T) {
t.Parallel()
pages := preparePageGroupTestPages(t)
Expand Down Expand Up @@ -256,8 +247,8 @@ func TestGroupByParamCalledWithUnavailableParam(t *testing.T) {
t.Parallel()
pages := preparePageGroupTestPages(t)
_, err := pages.GroupByParam("unavailable_param")
if err == nil {
t.Errorf("GroupByParam should return an error but didn't")
if err != nil {
t.Errorf("GroupByParam returned an error when it shouldn't")
}
}

Expand Down
Loading