tests: Address deprecation warnings and errors

This commit is contained in:
Joe Mooring
2024-09-28 13:15:53 -07:00
committed by Bjørn Erik Pedersen
parent d0dca65625
commit d1ba52f3c3
18 changed files with 71 additions and 82 deletions

View File

@@ -103,31 +103,7 @@ suffixes = ["html", "xhtml"]
b.Assert(contentTypes.Markdown.Suffixes(), qt.DeepEquals, []string{"md", "mdown", "markdown"}) b.Assert(contentTypes.Markdown.Suffixes(), qt.DeepEquals, []string{"md", "mdown", "markdown"})
} }
func TestPaginationConfigOld(t *testing.T) { func TestPaginationConfig(t *testing.T) {
files := `
-- hugo.toml --
[languages.en]
weight = 1
paginatePath = "page-en"
[languages.de]
weight = 2
paginatePath = "page-de"
paginate = 20
`
b := hugolib.Test(t, files)
confEn := b.H.Sites[0].Conf.Pagination()
confDe := b.H.Sites[1].Conf.Pagination()
b.Assert(confEn.Path, qt.Equals, "page-en")
b.Assert(confEn.PagerSize, qt.Equals, 10)
b.Assert(confDe.Path, qt.Equals, "page-de")
b.Assert(confDe.PagerSize, qt.Equals, 20)
}
func TestPaginationConfigNew(t *testing.T) {
files := ` files := `
-- hugo.toml -- -- hugo.toml --
[languages.en] [languages.en]

View File

@@ -276,11 +276,13 @@ func TestLoadMultiConfig(t *testing.T) {
// Add a random config variable for testing. // Add a random config variable for testing.
// side = page in Norwegian. // side = page in Norwegian.
configContentBase := ` configContentBase := `
Paginate = 32 [pagination]
PaginatePath = "side" pagerSize = 32
path = "side"
` `
configContentSub := ` configContentSub := `
PaginatePath = "top" [pagination]
path = "top"
` `
mm := afero.NewMemMapFs() mm := afero.NewMemMapFs()
@@ -292,8 +294,8 @@ func TestLoadMultiConfig(t *testing.T) {
c.Assert(err, qt.IsNil) c.Assert(err, qt.IsNil)
cfg := all.Base cfg := all.Base
c.Assert(cfg.PaginatePath, qt.Equals, "top") c.Assert(cfg.Pagination.Path, qt.Equals, "top")
c.Assert(cfg.Paginate, qt.Equals, 32) c.Assert(cfg.Pagination.PagerSize, qt.Equals, 32)
} }
func TestLoadConfigFromThemes(t *testing.T) { func TestLoadConfigFromThemes(t *testing.T) {
@@ -698,10 +700,6 @@ func TestHugoConfig(t *testing.T) {
filesTemplate := ` filesTemplate := `
-- hugo.toml -- -- hugo.toml --
theme = "mytheme" theme = "mytheme"
[social]
twitter = "bepsays"
[author]
name = "bep"
[params] [params]
rootparam = "rootvalue" rootparam = "rootvalue"
-- config/_default/hugo.toml -- -- config/_default/hugo.toml --
@@ -718,9 +716,6 @@ rootparam: {{ site.Params.rootparam }}
rootconfigparam: {{ site.Params.rootconfigparam }} rootconfigparam: {{ site.Params.rootconfigparam }}
themeparam: {{ site.Params.themeparam }} themeparam: {{ site.Params.themeparam }}
themeconfigdirparam: {{ site.Params.themeconfigdirparam }} themeconfigdirparam: {{ site.Params.themeconfigdirparam }}
social: {{ site.Social }}
author: {{ site.Author }}
` `
@@ -744,8 +739,6 @@ author: {{ site.Author }}
"rootconfigparam: rootconfigvalue", "rootconfigparam: rootconfigvalue",
"themeparam: themevalue", "themeparam: themevalue",
"themeconfigdirparam: themeconfigdirvalue", "themeconfigdirparam: themeconfigdirvalue",
"social: map[twitter:bepsays]",
"author: map[name:bep]",
) )
}) })
} }
@@ -918,11 +911,9 @@ title: "My Swedish Section"
-- layouts/index.html -- -- layouts/index.html --
LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Language.LanguageCode }}| LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Language.LanguageCode }}|
{{ range $i, $e := (slice site .Site) }} {{ range $i, $e := (slice site .Site) }}
{{ $i }}|AllPages: {{ len .AllPages }}|Sections: {{ if .Sections }}true{{ end }}| Author: {{ .Authors }}|BuildDrafts: {{ .BuildDrafts }}|IsMultilingual: {{ .IsMultiLingual }}|Param: {{ .Language.Params.myparam }}|Language string: {{ .Language }}|Languages: {{ .Languages }} {{ $i }}|AllPages: {{ len .AllPages }}|Sections: {{ if .Sections }}true{{ end }}|BuildDrafts: {{ .BuildDrafts }}|Param: {{ .Language.Params.myparam }}|Language string: {{ .Language }}|Languages: {{ .Languages }}
{{ end }} {{ end }}
` `
b := NewIntegrationTestBuilder( b := NewIntegrationTestBuilder(
IntegrationTestConfig{ IntegrationTestConfig{
@@ -940,7 +931,6 @@ AllPages: 4|
Sections: true| Sections: true|
Param: enParamValue Param: enParamValue
Param: enParamValue Param: enParamValue
IsMultilingual: true
LanguageCode: true|en-US| LanguageCode: true|en-US|
`) `)

View File

@@ -100,7 +100,7 @@ func TestEmbeddedPaginationTemplate(t *testing.T) {
test := func(variant string, expectedOutput string) { test := func(variant string, expectedOutput string) {
b := newTestSitesBuilder(t) b := newTestSitesBuilder(t)
b.WithConfigFile("toml", `paginate = 1`) b.WithConfigFile("toml", `pagination.pagerSize = 1`)
b.WithContent( b.WithContent(
"s1/p01.md", "---\ntitle: p01\n---", "s1/p01.md", "---\ntitle: p01\n---",
"s1/p02.md", "---\ntitle: p02\n---", "s1/p02.md", "---\ntitle: p02\n---",

View File

@@ -11,12 +11,14 @@ func TestMultihost(t *testing.T) {
files := ` files := `
-- hugo.toml -- -- hugo.toml --
paginate = 1
defaultContentLanguage = "fr" defaultContentLanguage = "fr"
defaultContentLanguageInSubdir = false defaultContentLanguageInSubdir = false
staticDir = ["s1", "s2"] staticDir = ["s1", "s2"]
enableRobotsTXT = true enableRobotsTXT = true
[pagination]
pagerSize = 1
[permalinks] [permalinks]
other = "/somewhere/else/:filename" other = "/somewhere/else/:filename"

View File

@@ -107,10 +107,13 @@ func TestSmoke(t *testing.T) {
baseURL = "https://example.com" baseURL = "https://example.com"
title = "Smoke Site" title = "Smoke Site"
rssLimit = 3 rssLimit = 3
paginate = 1
defaultContentLanguage = "en" defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true defaultContentLanguageInSubdir = true
enableRobotsTXT = true enableRobotsTXT = true
[pagination]
pagerSize = 1
[taxonomies] [taxonomies]
category = 'categories' category = 'categories'
tag = 'tags' tag = 'tags'
@@ -434,10 +437,10 @@ func TestDataRace(t *testing.T) {
--- ---
title: "The Page" title: "The Page"
outputs: ["HTML", "JSON"] outputs: ["HTML", "JSON"]
--- ---
The content. The content.
` `
@@ -450,10 +453,10 @@ The content.
--- ---
title: "The Home" title: "The Home"
outputs: ["HTML", "JSON", "CSV", "RSS"] outputs: ["HTML", "JSON", "CSV", "RSS"]
--- ---
The content. The content.
`) `)

View File

@@ -24,8 +24,10 @@ import (
func TestPaginator(t *testing.T) { func TestPaginator(t *testing.T) {
configFile := ` configFile := `
baseURL = "https://example.com/foo/" baseURL = "https://example.com/foo/"
paginate = 3
paginatepath = "thepage" [pagination]
pagerSize = 3
path = "thepage"
[languages.en] [languages.en]
weight = 1 weight = 1
@@ -161,10 +163,11 @@ Len Pag: {{ len $pag.Pages }}
func TestPaginatorNodePagesOnly(t *testing.T) { func TestPaginatorNodePagesOnly(t *testing.T) {
files := ` files := `
-- hugo.toml -- -- hugo.toml --
paginate = 1 [pagination]
pagerSize = 1
-- content/p1.md -- -- content/p1.md --
-- layouts/_default/single.html -- -- layouts/_default/single.html --
Paginator: {{ .Paginator }} Paginator: {{ .Paginator }}
` `
b, err := TestE(t, files) b, err := TestE(t, files)
b.Assert(err, qt.IsNotNil) b.Assert(err, qt.IsNotNil)

View File

@@ -559,7 +559,8 @@ baseURL = "https://example.com"
disableKinds = ["term", "taxonomy"] disableKinds = ["term", "taxonomy"]
disableLiveReload = true disableLiveReload = true
defaultContentLanguage = "nn" defaultContentLanguage = "nn"
paginate = 20 [pagination]
pagerSize = 20
[security] [security]
enableInlineShortcodes = true enableInlineShortcodes = true
[languages] [languages]
@@ -1431,7 +1432,7 @@ title: "My Sect"
--- ---
title: "P%d" title: "P%d"
--- ---
P%d Content. P%d Content.
` `
for i := 0; i < count; i++ { for i := 0; i < count; i++ {

View File

@@ -123,7 +123,7 @@ func TestSecurityPolicies(t *testing.T) {
c.Skip() c.Skip()
} }
cb := func(b *sitesBuilder) { cb := func(b *sitesBuilder) {
b.WithTemplatesAdded("index.html", `{{ $scss := "body { color: #333; }" | resources.FromString "foo.scss" | resources.ToCSS (dict "transpiler" "dartsass") }}`) b.WithTemplatesAdded("index.html", `{{ $scss := "body { color: #333; }" | resources.FromString "foo.scss" | css.Sass (dict "transpiler" "dartsass") }}`)
} }
testVariant(c, cb, "") testVariant(c, cb, "")
}) })
@@ -137,10 +137,10 @@ func TestSecurityPolicies(t *testing.T) {
b.WithConfigFile("toml", ` b.WithConfigFile("toml", `
[security] [security]
[security.exec] [security.exec]
allow="none" allow="none"
`) `)
b.WithTemplatesAdded("index.html", `{{ $scss := "body { color: #333; }" | resources.FromString "foo.scss" | resources.ToCSS (dict "transpiler" "dartsass") }}`) b.WithTemplatesAdded("index.html", `{{ $scss := "body { color: #333; }" | resources.FromString "foo.scss" | css.Sass (dict "transpiler" "dartsass") }}`)
} }
testVariant(c, cb, `(?s).*sass(-embedded)?" is not whitelisted in policy "security\.exec\.allow".*`) testVariant(c, cb, `(?s).*sass(-embedded)?" is not whitelisted in policy "security\.exec\.allow".*`)
}) })
@@ -160,7 +160,7 @@ allow="none"
httpTestVariant(c, `{{ $json := resources.GetRemote "%[1]s/fruits.json" }}{{ $json.Content }}`, `(?s).*is not whitelisted in policy "security\.http\.urls".*`, httpTestVariant(c, `{{ $json := resources.GetRemote "%[1]s/fruits.json" }}{{ $json.Content }}`, `(?s).*is not whitelisted in policy "security\.http\.urls".*`,
func(b *sitesBuilder) { func(b *sitesBuilder) {
b.WithConfigFile("toml", ` b.WithConfigFile("toml", `
[security] [security]
[security.http] [security.http]
urls="none" urls="none"
`) `)
@@ -181,7 +181,7 @@ urls="none"
httpTestVariant(c, `{{ $json := resources.GetRemote "%[1]s/fakejson.json" }}{{ $json.Content }}`, ``, httpTestVariant(c, `{{ $json := resources.GetRemote "%[1]s/fakejson.json" }}{{ $json.Content }}`, ``,
func(b *sitesBuilder) { func(b *sitesBuilder) {
b.WithConfigFile("toml", ` b.WithConfigFile("toml", `
[security] [security]
[security.http] [security.http]
mediaTypes=["application/json"] mediaTypes=["application/json"]

View File

@@ -126,10 +126,11 @@ func TestShortcodeMultipleOutputFormats(t *testing.T) {
siteConfig := ` siteConfig := `
baseURL = "http://example.com/blog" baseURL = "http://example.com/blog"
paginate = 1
disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"] disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"]
[pagination]
pagerSize = 1
[outputs] [outputs]
home = [ "HTML", "AMP", "Calendar" ] home = [ "HTML", "AMP", "Calendar" ]
page = [ "HTML", "AMP", "JSON" ] page = [ "HTML", "AMP", "JSON" ]

View File

@@ -15,7 +15,6 @@ package hugolib
import ( import (
"fmt" "fmt"
"html/template"
"strings" "strings"
"testing" "testing"
@@ -45,11 +44,13 @@ func doTestSiteWithPageOutputs(t *testing.T, outputs []string) {
siteConfig := ` siteConfig := `
baseURL = "http://example.com/blog" baseURL = "http://example.com/blog"
paginate = 1
defaultContentLanguage = "en" defaultContentLanguage = "en"
disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"] disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"]
[pagination]
pagerSize = 1
[Taxonomies] [Taxonomies]
tag = "tags" tag = "tags"
category = "categories" category = "categories"
@@ -221,11 +222,13 @@ func TestRedefineRSSOutputFormat(t *testing.T) {
siteConfig := ` siteConfig := `
baseURL = "http://example.com/blog" baseURL = "http://example.com/blog"
paginate = 1
defaultContentLanguage = "en" defaultContentLanguage = "en"
disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"] disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"]
[pagination]
pagerSize = 1
[outputFormats] [outputFormats]
[outputFormats.RSS] [outputFormats.RSS]
mediatype = "application/rss" mediatype = "application/rss"
@@ -249,7 +252,7 @@ baseName = "feed"
s := h.Sites[0] s := h.Sites[0]
// Issue #3450 // Issue #3450
c.Assert(s.RSSLink(), qt.Equals, template.URL("http://example.com/blog/feed.xml")) c.Assert(s.Home().OutputFormats().Get("rss").Permalink(), qt.Equals, "http://example.com/blog/feed.xml")
} }
// Issue #3614 // Issue #3614
@@ -257,11 +260,13 @@ func TestDotLessOutputFormat(t *testing.T) {
siteConfig := ` siteConfig := `
baseURL = "http://example.com/blog" baseURL = "http://example.com/blog"
paginate = 1
defaultContentLanguage = "en" defaultContentLanguage = "en"
disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"] disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"]
[pagination]
pagerSize = 1
[mediaTypes] [mediaTypes]
[mediaTypes."text/nodot"] [mediaTypes."text/nodot"]
delimiter = "" delimiter = ""

View File

@@ -115,7 +115,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
{{ $sections := (.Site.GetPage "section" .Section).Sections.ByWeight }} {{ $sections := (.Site.GetPage "section" .Section).Sections.ByWeight }}
</html>`) </html>`)
cfg.Set("paginate", 2) cfg.Set("pagination.pagerSize", 2)
th, configs := newTestHelperFromProvider(cfg, fs, t) th, configs := newTestHelperFromProvider(cfg, fs, t)

View File

@@ -32,9 +32,11 @@ func TestSiteStats(t *testing.T) {
siteConfig := ` siteConfig := `
baseURL = "http://example.com/blog" baseURL = "http://example.com/blog"
paginate = 1
defaultContentLanguage = "nn" defaultContentLanguage = "nn"
[pagination]
pagerSize = 1
[languages] [languages]
[languages.nn] [languages.nn]
languageName = "Nynorsk" languageName = "Nynorsk"

View File

@@ -91,7 +91,7 @@ Do not go gentle into that good night.
` `
cfg, fs := newTestCfg() cfg, fs := newTestCfg()
cfg.Set("paginate", 1) cfg.Set("pagination.pagerSize", 1)
th, configs := newTestHelperFromProvider(cfg, fs, t) th, configs := newTestHelperFromProvider(cfg, fs, t)
writeSource(t, fs, filepath.Join("content", "sect1", "_index.md"), fmt.Sprintf(st, "/ss1/")) writeSource(t, fs, filepath.Join("content", "sect1", "_index.md"), fmt.Sprintf(st, "/ss1/"))

View File

@@ -80,8 +80,9 @@ func doTestTaxonomiesWithAndWithoutContentFile(t *testing.T, uglyURLs bool) {
baseURL = "http://example.com/blog" baseURL = "http://example.com/blog"
titleCaseStyle = "firstupper" titleCaseStyle = "firstupper"
uglyURLs = %t uglyURLs = %t
paginate = 1
defaultContentLanguage = "en" defaultContentLanguage = "en"
[pagination]
pagerSize = 1
[Taxonomies] [Taxonomies]
tag = "tags" tag = "tags"
category = "categories" category = "categories"

View File

@@ -377,7 +377,7 @@ func TestTemplateFuncs(t *testing.T) {
b := newTestSitesBuilder(t).WithDefaultMultiSiteConfig() b := newTestSitesBuilder(t).WithDefaultMultiSiteConfig()
homeTpl := `Site: {{ site.Language.Lang }} / {{ .Site.Language.Lang }} / {{ site.BaseURL }} homeTpl := `Site: {{ site.Language.Lang }} / {{ .Site.Language.Lang }} / {{ site.BaseURL }}
Sites: {{ site.Sites.First.Home.Language.Lang }} Sites: {{ site.Sites.Default.Home.Language.Lang }}
Hugo: {{ hugo.Generator }} Hugo: {{ hugo.Generator }}
` `
@@ -460,7 +460,7 @@ complex: 80: 80
func TestPartialWithZeroedArgs(t *testing.T) { func TestPartialWithZeroedArgs(t *testing.T) {
b := newTestSitesBuilder(t) b := newTestSitesBuilder(t)
b.WithTemplatesAdded("index.html", b.WithTemplatesAdded("index.html",
` `
X{{ partial "retval" dict }}X X{{ partial "retval" dict }}X
X{{ partial "retval" slice }}X X{{ partial "retval" slice }}X
X{{ partial "retval" "" }}X X{{ partial "retval" "" }}X
@@ -696,7 +696,7 @@ func TestApplyWithNamespace(t *testing.T) {
b.WithTemplates( b.WithTemplates(
"index.html", ` "index.html", `
{{ $b := slice " a " " b " " c" }} {{ $b := slice " a " " b " " c" }}
{{ $a := apply $b "strings.Trim" "." " " }} {{ $a := apply $b "strings.Trim" "." " " }}
a: {{ $a }} a: {{ $a }}
`, `,

View File

@@ -292,11 +292,13 @@ func (s *sitesBuilder) WithDefaultMultiSiteConfig() *sitesBuilder {
defaultMultiSiteConfig := ` defaultMultiSiteConfig := `
baseURL = "http://example.com/blog" baseURL = "http://example.com/blog"
paginate = 1
disablePathToLower = true disablePathToLower = true
defaultContentLanguage = "en" defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true defaultContentLanguageInSubdir = true
[pagination]
pagerSize = 1
[permalinks] [permalinks]
other = "/somewhere/else/:filename" other = "/somewhere/else/:filename"
@@ -324,7 +326,8 @@ plaque = "plaques"
weight = 30 weight = 30
title = "På nynorsk" title = "På nynorsk"
languageName = "Nynorsk" languageName = "Nynorsk"
paginatePath = "side" [Languages.nn.pagination]
path = "side"
[Languages.nn.Taxonomies] [Languages.nn.Taxonomies]
lag = "lag" lag = "lag"
[[Languages.nn.menu.main]] [[Languages.nn.menu.main]]
@@ -336,7 +339,8 @@ weight = 1
weight = 40 weight = 40
title = "På bokmål" title = "På bokmål"
languageName = "Bokmål" languageName = "Bokmål"
paginatePath = "side" [Languages.nb.pagination]
path = "side"
[Languages.nb.Taxonomies] [Languages.nb.Taxonomies]
lag = "lag" lag = "lag"
` + commonConfigSections ` + commonConfigSections

View File

@@ -396,7 +396,7 @@ h3 {
{{ range $stylesheets }} {{ range $stylesheets }}
{{ with . | resources.ToCSS | fingerprint }} {{ with . | css.Sass | fingerprint }}
<link as="style" href="{{ .RelPermalink }}" rel="preload stylesheet"> <link as="style" href="{{ .RelPermalink }}" rel="preload stylesheet">
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@@ -29,8 +29,9 @@ func TestThatPageIsAvailableEverywhere(t *testing.T) {
baseURL = 'http://example.com/' baseURL = 'http://example.com/'
disableKinds = ["taxonomy", "term"] disableKinds = ["taxonomy", "term"]
enableInlineShortcodes = true enableInlineShortcodes = true
paginate = 1
enableRobotsTXT = true enableRobotsTXT = true
[pagination]
pagerSize = 1
LANG_CONFIG LANG_CONFIG
-- content/_index.md -- -- content/_index.md --
--- ---
@@ -191,7 +192,7 @@ title: "P1"
# Heading 1 # Heading 1
-- layouts/shortcodes/toc.html -- -- layouts/shortcodes/toc.html --
{{ page.TableOfContents }} {{ page.TableOfContents }}
-- layouts/_default/single.html -- -- layouts/_default/single.html --
{{ .Content }} {{ .Content }}
` `