mirror of
https://github.com/gohugoio/hugo.git
synced 2025-02-20 01:41:52 +00:00
hugolib: Simplify some test loops
This commit is contained in:
parent
8aaec644a9
commit
1f55cb767d
3 changed files with 53 additions and 61 deletions
|
@ -28,9 +28,9 @@ func TestPageTargetPath(t *testing.T) {
|
||||||
pathSpec := newTestDefaultPathSpec()
|
pathSpec := newTestDefaultPathSpec()
|
||||||
|
|
||||||
for _, langPrefix := range []string{"", "no"} {
|
for _, langPrefix := range []string{"", "no"} {
|
||||||
t.Run(fmt.Sprintf("langPrefix=%q", langPrefix), func(t *testing.T) {
|
for _, uglyURLs := range []bool{false, true} {
|
||||||
for _, uglyURLs := range []bool{false, true} {
|
t.Run(fmt.Sprintf("langPrefix=%q,uglyURLs=%t", langPrefix, uglyURLs),
|
||||||
t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) {
|
func(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -171,8 +171,6 @@ func TestPageTargetPath(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,58 +206,55 @@ func TestPaginationURLFactory(t *testing.T) {
|
||||||
cfg.Set("paginatePath", "zoo")
|
cfg.Set("paginatePath", "zoo")
|
||||||
|
|
||||||
for _, uglyURLs := range []bool{false, true} {
|
for _, uglyURLs := range []bool{false, true} {
|
||||||
t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) {
|
for _, canonifyURLs := range []bool{false, true} {
|
||||||
for _, canonifyURLs := range []bool{false, true} {
|
t.Run(fmt.Sprintf("uglyURLs=%t,canonifyURLs=%t", uglyURLs, canonifyURLs), func(t *testing.T) {
|
||||||
t.Run(fmt.Sprintf("canonifyURLs=%t", canonifyURLs), func(t *testing.T) {
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
d targetPathDescriptor
|
d targetPathDescriptor
|
||||||
baseURL string
|
baseURL string
|
||||||
page int
|
page int
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{"HTML home page 32",
|
{"HTML home page 32",
|
||||||
targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/", 32, "/zoo/32/"},
|
targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/", 32, "/zoo/32/"},
|
||||||
{"JSON home page 42",
|
{"JSON home page 42",
|
||||||
targetPathDescriptor{Kind: KindHome, Type: output.JSONFormat}, "http://example.com/", 42, "/zoo/42/"},
|
targetPathDescriptor{Kind: KindHome, Type: output.JSONFormat}, "http://example.com/", 42, "/zoo/42/"},
|
||||||
// Issue #1252
|
// Issue #1252
|
||||||
{"BaseURL with sub path",
|
{"BaseURL with sub path",
|
||||||
targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/sub/", 999, "/sub/zoo/999/"},
|
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 {
|
if uglyURLs {
|
||||||
d := test.d
|
expected = expected[:len(expected)-1] + "." + test.d.Type.MediaType.Suffix
|
||||||
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)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
pathSpec := newTestPathSpec(fs, cfg)
|
||||||
})
|
d.PathSpec = pathSpec
|
||||||
|
|
||||||
|
factory := newPaginationURLFactory(d)
|
||||||
|
|
||||||
|
got := factory(test.page)
|
||||||
|
|
||||||
|
require.Equal(t, expected, got)
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPaginator(t *testing.T) {
|
func TestPaginator(t *testing.T) {
|
||||||
|
|
|
@ -53,14 +53,11 @@ func TestByCountOrderOfTaxonomies(t *testing.T) {
|
||||||
//
|
//
|
||||||
func TestTaxonomiesWithAndWithoutContentFile(t *testing.T) {
|
func TestTaxonomiesWithAndWithoutContentFile(t *testing.T) {
|
||||||
for _, uglyURLs := range []bool{false, true} {
|
for _, uglyURLs := range []bool{false, true} {
|
||||||
t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) {
|
for _, preserveTaxonomyNames := range []bool{false, true} {
|
||||||
for _, preserveTaxonomyNames := range []bool{false, true} {
|
t.Run(fmt.Sprintf("uglyURLs=%t,preserveTaxonomyNames=%t", uglyURLs, preserveTaxonomyNames), func(t *testing.T) {
|
||||||
t.Run(fmt.Sprintf("preserveTaxonomyNames=%t", preserveTaxonomyNames), func(t *testing.T) {
|
doTestTaxonomiesWithAndWithoutContentFile(t, preserveTaxonomyNames, uglyURLs)
|
||||||
doTestTaxonomiesWithAndWithoutContentFile(t, preserveTaxonomyNames, uglyURLs)
|
})
|
||||||
})
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue