Skip to content

Commit

Permalink
tests: Address deprecation warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored and bep committed Sep 29, 2024
1 parent d0dca65 commit d1ba52f
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 82 deletions.
26 changes: 1 addition & 25 deletions config/allconfig/allconfig_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,7 @@ suffixes = ["html", "xhtml"]
b.Assert(contentTypes.Markdown.Suffixes(), qt.DeepEquals, []string{"md", "mdown", "markdown"})
}

func TestPaginationConfigOld(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) {
func TestPaginationConfig(t *testing.T) {
files := `
-- hugo.toml --
[languages.en]
Expand Down
26 changes: 8 additions & 18 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ func TestLoadMultiConfig(t *testing.T) {
// Add a random config variable for testing.
// side = page in Norwegian.
configContentBase := `
Paginate = 32
PaginatePath = "side"
[pagination]
pagerSize = 32
path = "side"
`
configContentSub := `
PaginatePath = "top"
[pagination]
path = "top"
`
mm := afero.NewMemMapFs()

Expand All @@ -292,8 +294,8 @@ func TestLoadMultiConfig(t *testing.T) {
c.Assert(err, qt.IsNil)
cfg := all.Base

c.Assert(cfg.PaginatePath, qt.Equals, "top")
c.Assert(cfg.Paginate, qt.Equals, 32)
c.Assert(cfg.Pagination.Path, qt.Equals, "top")
c.Assert(cfg.Pagination.PagerSize, qt.Equals, 32)
}

func TestLoadConfigFromThemes(t *testing.T) {
Expand Down Expand Up @@ -698,10 +700,6 @@ func TestHugoConfig(t *testing.T) {
filesTemplate := `
-- hugo.toml --
theme = "mytheme"
[social]
twitter = "bepsays"
[author]
name = "bep"
[params]
rootparam = "rootvalue"
-- config/_default/hugo.toml --
Expand All @@ -718,9 +716,6 @@ rootparam: {{ site.Params.rootparam }}
rootconfigparam: {{ site.Params.rootconfigparam }}
themeparam: {{ site.Params.themeparam }}
themeconfigdirparam: {{ site.Params.themeconfigdirparam }}
social: {{ site.Social }}
author: {{ site.Author }}
`

Expand All @@ -744,8 +739,6 @@ author: {{ site.Author }}
"rootconfigparam: rootconfigvalue",
"themeparam: themevalue",
"themeconfigdirparam: themeconfigdirvalue",
"social: map[twitter:bepsays]",
"author: map[name:bep]",
)
})
}
Expand Down Expand Up @@ -918,11 +911,9 @@ title: "My Swedish Section"
-- layouts/index.html --
LanguageCode: {{ eq site.LanguageCode site.Language.LanguageCode }}|{{ site.Language.LanguageCode }}|
{{ 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 }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
Expand All @@ -940,7 +931,6 @@ AllPages: 4|
Sections: true|
Param: enParamValue
Param: enParamValue
IsMultilingual: true
LanguageCode: true|en-US|
`)

Expand Down
2 changes: 1 addition & 1 deletion hugolib/embedded_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestEmbeddedPaginationTemplate(t *testing.T) {

test := func(variant string, expectedOutput string) {
b := newTestSitesBuilder(t)
b.WithConfigFile("toml", `paginate = 1`)
b.WithConfigFile("toml", `pagination.pagerSize = 1`)
b.WithContent(
"s1/p01.md", "---\ntitle: p01\n---",
"s1/p02.md", "---\ntitle: p02\n---",
Expand Down
4 changes: 3 additions & 1 deletion hugolib/hugo_sites_multihost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ func TestMultihost(t *testing.T) {

files := `
-- hugo.toml --
paginate = 1
defaultContentLanguage = "fr"
defaultContentLanguageInSubdir = false
staticDir = ["s1", "s2"]
enableRobotsTXT = true
[pagination]
pagerSize = 1
[permalinks]
other = "/somewhere/else/:filename"
Expand Down
13 changes: 8 additions & 5 deletions hugolib/hugo_smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ func TestSmoke(t *testing.T) {
baseURL = "https://example.com"
title = "Smoke Site"
rssLimit = 3
paginate = 1
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true
enableRobotsTXT = true
[pagination]
pagerSize = 1
[taxonomies]
category = 'categories'
tag = 'tags'
Expand Down Expand Up @@ -434,10 +437,10 @@ func TestDataRace(t *testing.T) {
---
title: "The Page"
outputs: ["HTML", "JSON"]
---
---
The content.
`

Expand All @@ -450,10 +453,10 @@ The content.
---
title: "The Home"
outputs: ["HTML", "JSON", "CSV", "RSS"]
---
---
The content.
`)

Expand Down
11 changes: 7 additions & 4 deletions hugolib/paginator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
func TestPaginator(t *testing.T) {
configFile := `
baseURL = "https://example.com/foo/"
paginate = 3
paginatepath = "thepage"
[pagination]
pagerSize = 3
path = "thepage"
[languages.en]
weight = 1
Expand Down Expand Up @@ -161,10 +163,11 @@ Len Pag: {{ len $pag.Pages }}
func TestPaginatorNodePagesOnly(t *testing.T) {
files := `
-- hugo.toml --
paginate = 1
[pagination]
pagerSize = 1
-- content/p1.md --
-- layouts/_default/single.html --
Paginator: {{ .Paginator }}
Paginator: {{ .Paginator }}
`
b, err := TestE(t, files)
b.Assert(err, qt.IsNotNil)
Expand Down
5 changes: 3 additions & 2 deletions hugolib/rebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ baseURL = "https://example.com"
disableKinds = ["term", "taxonomy"]
disableLiveReload = true
defaultContentLanguage = "nn"
paginate = 20
[pagination]
pagerSize = 20
[security]
enableInlineShortcodes = true
[languages]
Expand Down Expand Up @@ -1431,7 +1432,7 @@ title: "My Sect"
---
title: "P%d"
---
P%d Content.
P%d Content.
`

for i := 0; i < count; i++ {
Expand Down
12 changes: 6 additions & 6 deletions hugolib/securitypolicies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestSecurityPolicies(t *testing.T) {
c.Skip()
}
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, "")
})
Expand All @@ -137,10 +137,10 @@ func TestSecurityPolicies(t *testing.T) {
b.WithConfigFile("toml", `
[security]
[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".*`)
})
Expand All @@ -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".*`,
func(b *sitesBuilder) {
b.WithConfigFile("toml", `
[security]
[security]
[security.http]
urls="none"
`)
Expand All @@ -181,7 +181,7 @@ urls="none"
httpTestVariant(c, `{{ $json := resources.GetRemote "%[1]s/fakejson.json" }}{{ $json.Content }}`, ``,
func(b *sitesBuilder) {
b.WithConfigFile("toml", `
[security]
[security]
[security.http]
mediaTypes=["application/json"]
Expand Down
5 changes: 3 additions & 2 deletions hugolib/shortcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ func TestShortcodeMultipleOutputFormats(t *testing.T) {
siteConfig := `
baseURL = "http://example.com/blog"
paginate = 1
disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"]
[pagination]
pagerSize = 1
[outputs]
home = [ "HTML", "AMP", "Calendar" ]
page = [ "HTML", "AMP", "JSON" ]
Expand Down
15 changes: 10 additions & 5 deletions hugolib/site_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package hugolib

import (
"fmt"
"html/template"
"strings"
"testing"

Expand Down Expand Up @@ -45,11 +44,13 @@ func doTestSiteWithPageOutputs(t *testing.T, outputs []string) {
siteConfig := `
baseURL = "http://example.com/blog"
paginate = 1
defaultContentLanguage = "en"
disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"]
[pagination]
pagerSize = 1
[Taxonomies]
tag = "tags"
category = "categories"
Expand Down Expand Up @@ -221,11 +222,13 @@ func TestRedefineRSSOutputFormat(t *testing.T) {
siteConfig := `
baseURL = "http://example.com/blog"
paginate = 1
defaultContentLanguage = "en"
disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"]
[pagination]
pagerSize = 1
[outputFormats]
[outputFormats.RSS]
mediatype = "application/rss"
Expand All @@ -249,19 +252,21 @@ baseName = "feed"
s := h.Sites[0]

// 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
func TestDotLessOutputFormat(t *testing.T) {
siteConfig := `
baseURL = "http://example.com/blog"
paginate = 1
defaultContentLanguage = "en"
disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"]
[pagination]
pagerSize = 1
[mediaTypes]
[mediaTypes."text/nodot"]
delimiter = ""
Expand Down
2 changes: 1 addition & 1 deletion hugolib/site_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
{{ $sections := (.Site.GetPage "section" .Section).Sections.ByWeight }}
</html>`)

cfg.Set("paginate", 2)
cfg.Set("pagination.pagerSize", 2)

th, configs := newTestHelperFromProvider(cfg, fs, t)

Expand Down
4 changes: 3 additions & 1 deletion hugolib/site_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ func TestSiteStats(t *testing.T) {
siteConfig := `
baseURL = "http://example.com/blog"
paginate = 1
defaultContentLanguage = "nn"
[pagination]
pagerSize = 1
[languages]
[languages.nn]
languageName = "Nynorsk"
Expand Down
2 changes: 1 addition & 1 deletion hugolib/site_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Do not go gentle into that good night.
`

cfg, fs := newTestCfg()
cfg.Set("paginate", 1)
cfg.Set("pagination.pagerSize", 1)
th, configs := newTestHelperFromProvider(cfg, fs, t)

writeSource(t, fs, filepath.Join("content", "sect1", "_index.md"), fmt.Sprintf(st, "/ss1/"))
Expand Down
3 changes: 2 additions & 1 deletion hugolib/taxonomy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func doTestTaxonomiesWithAndWithoutContentFile(t *testing.T, uglyURLs bool) {
baseURL = "http://example.com/blog"
titleCaseStyle = "firstupper"
uglyURLs = %t
paginate = 1
defaultContentLanguage = "en"
[pagination]
pagerSize = 1
[Taxonomies]
tag = "tags"
category = "categories"
Expand Down
Loading

0 comments on commit d1ba52f

Please sign in to comment.