From 1f55cb767db5839ce8fd1de64cda0959d6bfac58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 6 Jun 2017 08:43:33 +0200 Subject: [PATCH] hugolib: Simplify some test loops --- hugolib/page_paths_test.go | 10 ++--- hugolib/pagination_test.go | 91 ++++++++++++++++++-------------------- hugolib/taxonomy_test.go | 13 +++--- 3 files changed, 53 insertions(+), 61 deletions(-) diff --git a/hugolib/page_paths_test.go b/hugolib/page_paths_test.go index 1270ce712..1d14b92fd 100644 --- a/hugolib/page_paths_test.go +++ b/hugolib/page_paths_test.go @@ -28,9 +28,9 @@ func TestPageTargetPath(t *testing.T) { pathSpec := newTestDefaultPathSpec() for _, langPrefix := range []string{"", "no"} { - t.Run(fmt.Sprintf("langPrefix=%q", langPrefix), func(t *testing.T) { - for _, uglyURLs := range []bool{false, true} { - t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) { + for _, uglyURLs := range []bool{false, true} { + t.Run(fmt.Sprintf("langPrefix=%q,uglyURLs=%t", langPrefix, uglyURLs), + func(t *testing.T) { tests := []struct { name string @@ -171,8 +171,6 @@ func TestPageTargetPath(t *testing.T) { } } }) - } - }) + } } - } diff --git a/hugolib/pagination_test.go b/hugolib/pagination_test.go index bd459e9d2..3307667e9 100644 --- a/hugolib/pagination_test.go +++ b/hugolib/pagination_test.go @@ -206,58 +206,55 @@ func TestPaginationURLFactory(t *testing.T) { cfg.Set("paginatePath", "zoo") for _, uglyURLs := range []bool{false, true} { - t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) { - for _, canonifyURLs := range []bool{false, true} { - t.Run(fmt.Sprintf("canonifyURLs=%t", canonifyURLs), func(t *testing.T) { + for _, canonifyURLs := range []bool{false, true} { + t.Run(fmt.Sprintf("uglyURLs=%t,canonifyURLs=%t", uglyURLs, canonifyURLs), func(t *testing.T) { - tests := []struct { - name string - d targetPathDescriptor - baseURL string - page int - expected string - }{ - {"HTML home page 32", - targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/", 32, "/zoo/32/"}, - {"JSON home page 42", - targetPathDescriptor{Kind: KindHome, Type: output.JSONFormat}, "http://example.com/", 42, "/zoo/42/"}, - // Issue #1252 - {"BaseURL with sub path", - targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/sub/", 999, "/sub/zoo/999/"}, + tests := []struct { + name string + d targetPathDescriptor + baseURL string + page int + expected string + }{ + {"HTML home page 32", + targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/", 32, "/zoo/32/"}, + {"JSON home page 42", + targetPathDescriptor{Kind: KindHome, Type: output.JSONFormat}, "http://example.com/", 42, "/zoo/42/"}, + // Issue #1252 + {"BaseURL with sub path", + targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/sub/", 999, "/sub/zoo/999/"}, + } + + for _, test := range tests { + d := test.d + cfg.Set("baseURL", test.baseURL) + cfg.Set("canonifyURLs", canonifyURLs) + cfg.Set("uglyURLs", uglyURLs) + d.UglyURLs = uglyURLs + + expected := test.expected + + if canonifyURLs { + expected = strings.Replace(expected, "/sub", "", 1) } - for _, test := range tests { - d := test.d - cfg.Set("baseURL", test.baseURL) - cfg.Set("canonifyURLs", canonifyURLs) - cfg.Set("uglyURLs", uglyURLs) - d.UglyURLs = uglyURLs - - expected := test.expected - - if canonifyURLs { - expected = strings.Replace(expected, "/sub", "", 1) - } - - if uglyURLs { - expected = expected[:len(expected)-1] + "." + test.d.Type.MediaType.Suffix - } - - pathSpec := newTestPathSpec(fs, cfg) - d.PathSpec = pathSpec - - factory := newPaginationURLFactory(d) - - got := factory(test.page) - - require.Equal(t, expected, got) - + if uglyURLs { + expected = expected[:len(expected)-1] + "." + test.d.Type.MediaType.Suffix } - }) - } - }) + + pathSpec := newTestPathSpec(fs, cfg) + d.PathSpec = pathSpec + + factory := newPaginationURLFactory(d) + + got := factory(test.page) + + require.Equal(t, expected, got) + + } + }) + } } - } func TestPaginator(t *testing.T) { diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go index 421fde81d..b592d4e64 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -53,14 +53,11 @@ func TestByCountOrderOfTaxonomies(t *testing.T) { // func TestTaxonomiesWithAndWithoutContentFile(t *testing.T) { for _, uglyURLs := range []bool{false, true} { - t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) { - for _, preserveTaxonomyNames := range []bool{false, true} { - t.Run(fmt.Sprintf("preserveTaxonomyNames=%t", preserveTaxonomyNames), func(t *testing.T) { - doTestTaxonomiesWithAndWithoutContentFile(t, preserveTaxonomyNames, uglyURLs) - }) - } - }) - + for _, preserveTaxonomyNames := range []bool{false, true} { + t.Run(fmt.Sprintf("uglyURLs=%t,preserveTaxonomyNames=%t", uglyURLs, preserveTaxonomyNames), func(t *testing.T) { + doTestTaxonomiesWithAndWithoutContentFile(t, preserveTaxonomyNames, uglyURLs) + }) + } } }