hugolib: Test helper cleanup

This commit is contained in:
Bjørn Erik Pedersen 2017-02-17 20:52:50 +01:00
parent 10c13f5d79
commit ed847ed93d
14 changed files with 214 additions and 208 deletions

View file

@ -36,7 +36,7 @@ func TestAlias(t *testing.T) {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias) writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias)
@ -45,9 +45,9 @@ func TestAlias(t *testing.T) {
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
// the real page // the real page
th.assertFileContent(t, fs, filepath.Join("public", "page", "index.html"), false, "For some moments the old man") th.assertFileContent(filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
// the alias redirector // the alias redirector
th.assertFileContent(t, fs, filepath.Join("public", "foo", "bar", "index.html"), false, "<meta http-equiv=\"refresh\" content=\"0; ") th.assertFileContent(filepath.Join("public", "foo", "bar", "index.html"), false, "<meta http-equiv=\"refresh\" content=\"0; ")
} }
func TestAliasTemplate(t *testing.T) { func TestAliasTemplate(t *testing.T) {
@ -55,7 +55,7 @@ func TestAliasTemplate(t *testing.T) {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias) writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias)
@ -69,7 +69,7 @@ func TestAliasTemplate(t *testing.T) {
require.NoError(t, sites.Build(BuildCfg{})) require.NoError(t, sites.Build(BuildCfg{}))
// the real page // the real page
th.assertFileContent(t, fs, filepath.Join("public", "page", "index.html"), false, "For some moments the old man") th.assertFileContent(filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
// the alias redirector // the alias redirector
th.assertFileContent(t, fs, filepath.Join("public", "foo", "bar", "index.html"), false, "ALIASTEMPLATE") th.assertFileContent(filepath.Join("public", "foo", "bar", "index.html"), false, "ALIASTEMPLATE")
} }

View file

@ -154,7 +154,7 @@ func TestCaseInsensitiveConfigurationVariations(t *testing.T) {
fs := hugofs.NewFrom(mm, cfg) fs := hugofs.NewFrom(mm, cfg)
th := testHelper{cfg} th := testHelper{cfg, fs, t}
writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), ` writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `
Block Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }} Block Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}
@ -191,7 +191,7 @@ Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
t.Fatalf("Failed to build sites: %s", err) t.Fatalf("Failed to build sites: %s", err)
} }
th.assertFileContent(t, sites.Fs, filepath.Join("public", "nn", "sect1", "page1", "index.html"), true, th.assertFileContent(filepath.Join("public", "nn", "sect1", "page1", "index.html"), true,
"Page Colors: red|heavenly", "Page Colors: red|heavenly",
"Site Colors: green|yellow", "Site Colors: green|yellow",
"Site Lang Mood: Happy", "Site Lang Mood: Happy",
@ -204,7 +204,7 @@ Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
"&laquo;Hi&raquo;", // angled quotes "&laquo;Hi&raquo;", // angled quotes
) )
th.assertFileContent(t, sites.Fs, filepath.Join("public", "en", "sect1", "page1", "index.html"), true, th.assertFileContent(filepath.Join("public", "en", "sect1", "page1", "index.html"), true,
"Site Colors: Pink|golden", "Site Colors: Pink|golden",
"Page Colors: black|bluesy", "Page Colors: black|bluesy",
"Site Lang Mood: Thoughtful", "Site Lang Mood: Thoughtful",
@ -213,7 +213,7 @@ Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
"&ldquo;Hi&rdquo;", "&ldquo;Hi&rdquo;",
) )
th.assertFileContent(t, sites.Fs, filepath.Join("public", "nn", "sect2", "page2", "index.html"), true, th.assertFileContent(filepath.Join("public", "nn", "sect2", "page2", "index.html"), true,
"Page Colors: black|sky", "Page Colors: black|sky",
"Site Colors: green|yellow", "Site Colors: green|yellow",
"Shortcode Page: black|sky", "Shortcode Page: black|sky",
@ -265,7 +265,7 @@ func doTestCaseInsensitiveConfigurationForTemplateEngine(t *testing.T, suffix st
fs := hugofs.NewFrom(mm, cfg) fs := hugofs.NewFrom(mm, cfg)
th := testHelper{cfg} th := testHelper{cfg, fs, t}
t.Log("Testing", suffix) t.Log("Testing", suffix)
@ -296,7 +296,7 @@ p
t.Fatalf("Failed to build sites: %s", err) t.Fatalf("Failed to build sites: %s", err)
} }
th.assertFileContent(t, sites.Fs, filepath.Join("public", "nn", "sect1", "page1", "index.html"), true, th.assertFileContent(filepath.Join("public", "nn", "sect1", "page1", "index.html"), true,
"Page Colors: red|heavenly", "Page Colors: red|heavenly",
"Site Colors: green|yellow", "Site Colors: green|yellow",
"Shortcode Page: red|heavenly", "Shortcode Page: red|heavenly",

View file

@ -101,7 +101,7 @@ void do();
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("pygmentsStyle", "bw") cfg.Set("pygmentsStyle", "bw")
@ -115,7 +115,7 @@ title: Shorty
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th.assertFileContentRegexp(t, fs, filepath.Join("public", "simple", "index.html"), false, this.expected) th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), false, this.expected)
} }
} }
@ -149,7 +149,7 @@ func TestShortcodeFigure(t *testing.T) {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`---
@ -160,7 +160,7 @@ title: Shorty
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th.assertFileContentRegexp(t, fs, filepath.Join("public", "simple", "index.html"), false, this.expected) th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), false, this.expected)
} }
} }
@ -179,7 +179,7 @@ func TestShortcodeSpeakerdeck(t *testing.T) {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`---
@ -190,7 +190,7 @@ title: Shorty
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th.assertFileContentRegexp(t, fs, filepath.Join("public", "simple", "index.html"), false, this.expected) th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), false, this.expected)
} }
} }
@ -217,7 +217,7 @@ func TestShortcodeYoutube(t *testing.T) {
} { } {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`---
@ -228,7 +228,7 @@ title: Shorty
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th.assertFileContentRegexp(t, fs, filepath.Join("public", "simple", "index.html"), false, this.expected) th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), false, this.expected)
} }
} }
@ -256,7 +256,7 @@ func TestShortcodeVimeo(t *testing.T) {
} { } {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`---
@ -267,7 +267,7 @@ title: Shorty
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th.assertFileContentRegexp(t, fs, filepath.Join("public", "simple", "index.html"), false, this.expected) th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), false, this.expected)
} }
} }
@ -289,7 +289,7 @@ func TestShortcodeGist(t *testing.T) {
} { } {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`--- writeSource(t, fs, filepath.Join("content", "simple.md"), fmt.Sprintf(`---
@ -300,7 +300,7 @@ title: Shorty
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th.assertFileContentRegexp(t, fs, filepath.Join("public", "simple", "index.html"), false, this.expected) th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), false, this.expected)
} }
} }
@ -332,7 +332,7 @@ func TestShortcodeTweet(t *testing.T) {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
withTemplate := func(templ tpl.Template) error { withTemplate := func(templ tpl.Template) error {
@ -348,7 +348,7 @@ title: Shorty
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg, WithTemplate: withTemplate}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg, WithTemplate: withTemplate}, BuildCfg{})
th.assertFileContentRegexp(t, fs, filepath.Join("public", "simple", "index.html"), false, this.expected) th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), false, this.expected)
} }
} }
@ -387,7 +387,7 @@ func TestShortcodeInstagram(t *testing.T) {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
withTemplate := func(templ tpl.Template) error { withTemplate := func(templ tpl.Template) error {
@ -403,7 +403,7 @@ title: Shorty
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg, WithTemplate: withTemplate}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg, WithTemplate: withTemplate}, BuildCfg{})
th.assertFileContentRegexp(t, fs, filepath.Join("public", "simple", "index.html"), false, this.expected) th.assertFileContentRegexp(filepath.Join("public", "simple", "index.html"), false, this.expected)
} }
} }

View file

@ -3,7 +3,6 @@ package hugolib
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"regexp"
"strings" "strings"
"testing" "testing"
@ -14,7 +13,6 @@ import (
"github.com/fortytw2/leaktest" "github.com/fortytw2/leaktest"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/spf13/hugo/config"
"github.com/spf13/hugo/deps" "github.com/spf13/hugo/deps"
"github.com/spf13/hugo/helpers" "github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/hugofs" "github.com/spf13/hugo/hugofs"
@ -41,8 +39,8 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) {
siteConfig := testSiteConfig{Fs: afero.NewMemMapFs(), DefaultContentLanguage: "fr", DefaultContentLanguageInSubdir: defaultInSubDir} siteConfig := testSiteConfig{Fs: afero.NewMemMapFs(), DefaultContentLanguage: "fr", DefaultContentLanguageInSubdir: defaultInSubDir}
sites := createMultiTestSites(t, siteConfig, multiSiteTOMLConfigTemplate) sites := createMultiTestSites(t, siteConfig, multiSiteTOMLConfigTemplate)
th := testHelper{sites.Cfg}
fs := sites.Fs fs := sites.Fs
th := testHelper{sites.Cfg, fs, t}
err := sites.Build(BuildCfg{}) err := sites.Build(BuildCfg{})
@ -79,68 +77,64 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) {
require.Equal(t, th.replaceDefaultContentLanguageValue("http://example.com/blog/fr/sect/doc1/", defaultInSubDir), frPerm) require.Equal(t, th.replaceDefaultContentLanguageValue("http://example.com/blog/fr/sect/doc1/", defaultInSubDir), frPerm)
require.Equal(t, th.replaceDefaultContentLanguageValue("/blog/fr/sect/doc1/", defaultInSubDir), frRelPerm) require.Equal(t, th.replaceDefaultContentLanguageValue("/blog/fr/sect/doc1/", defaultInSubDir), frRelPerm)
th.assertFileContent(t, fs, "public/fr/sect/doc1/index.html", defaultInSubDir, "Single", "Bonjour") th.assertFileContent("public/fr/sect/doc1/index.html", defaultInSubDir, "Single", "Bonjour")
th.assertFileContent(t, fs, "public/en/sect/doc1-slug/index.html", defaultInSubDir, "Single", "Hello") th.assertFileContent("public/en/sect/doc1-slug/index.html", defaultInSubDir, "Single", "Hello")
// Check home // Check home
if defaultInSubDir { if defaultInSubDir {
// should have a redirect on top level. // should have a redirect on top level.
th.assertFileContent(t, fs, "public/index.html", true, `<meta http-equiv="refresh" content="0; url=http://example.com/blog/fr" />`) th.assertFileContent("public/index.html", true, `<meta http-equiv="refresh" content="0; url=http://example.com/blog/fr" />`)
} else { } else {
// should have redirect back to root // should have redirect back to root
th.assertFileContent(t, fs, "public/fr/index.html", true, `<meta http-equiv="refresh" content="0; url=http://example.com/blog" />`) th.assertFileContent("public/fr/index.html", true, `<meta http-equiv="refresh" content="0; url=http://example.com/blog" />`)
} }
th.assertFileContent(t, fs, "public/fr/index.html", defaultInSubDir, "Home", "Bonjour") th.assertFileContent("public/fr/index.html", defaultInSubDir, "Home", "Bonjour")
th.assertFileContent(t, fs, "public/en/index.html", defaultInSubDir, "Home", "Hello") th.assertFileContent("public/en/index.html", defaultInSubDir, "Home", "Hello")
// Check list pages // Check list pages
th.assertFileContent(t, fs, "public/fr/sect/index.html", defaultInSubDir, "List", "Bonjour") th.assertFileContent("public/fr/sect/index.html", defaultInSubDir, "List", "Bonjour")
th.assertFileContent(t, fs, "public/en/sect/index.html", defaultInSubDir, "List", "Hello") th.assertFileContent("public/en/sect/index.html", defaultInSubDir, "List", "Hello")
th.assertFileContent(t, fs, "public/fr/plaques/frtag1/index.html", defaultInSubDir, "List", "Bonjour") th.assertFileContent("public/fr/plaques/frtag1/index.html", defaultInSubDir, "List", "Bonjour")
th.assertFileContent(t, fs, "public/en/tags/tag1/index.html", defaultInSubDir, "List", "Hello") th.assertFileContent("public/en/tags/tag1/index.html", defaultInSubDir, "List", "Hello")
// Check sitemaps // Check sitemaps
// Sitemaps behaves different: In a multilanguage setup there will always be a index file and // Sitemaps behaves different: In a multilanguage setup there will always be a index file and
// one sitemap in each lang folder. // one sitemap in each lang folder.
th.assertFileContent(t, fs, "public/sitemap.xml", true, th.assertFileContent("public/sitemap.xml", true,
"<loc>http://example.com/blog/en/sitemap.xml</loc>", "<loc>http://example.com/blog/en/sitemap.xml</loc>",
"<loc>http://example.com/blog/fr/sitemap.xml</loc>") "<loc>http://example.com/blog/fr/sitemap.xml</loc>")
if defaultInSubDir { if defaultInSubDir {
th.assertFileContent(t, fs, "public/fr/sitemap.xml", true, "<loc>http://example.com/blog/fr/</loc>") th.assertFileContent("public/fr/sitemap.xml", true, "<loc>http://example.com/blog/fr/</loc>")
} else { } else {
th.assertFileContent(t, fs, "public/fr/sitemap.xml", true, "<loc>http://example.com/blog/</loc>") th.assertFileContent("public/fr/sitemap.xml", true, "<loc>http://example.com/blog/</loc>")
} }
th.assertFileContent(t, fs, "public/en/sitemap.xml", true, "<loc>http://example.com/blog/en/</loc>") th.assertFileContent("public/en/sitemap.xml", true, "<loc>http://example.com/blog/en/</loc>")
// Check rss // Check rss
th.assertFileContent(t, fs, "public/fr/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/index.xml"`) th.assertFileContent("public/fr/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/index.xml"`)
th.assertFileContent(t, fs, "public/en/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/index.xml"`) th.assertFileContent("public/en/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/index.xml"`)
th.assertFileContent(t, fs, "public/fr/sect/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/sect/index.xml"`) th.assertFileContent("public/fr/sect/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/sect/index.xml"`)
th.assertFileContent(t, fs, "public/en/sect/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/sect/index.xml"`) th.assertFileContent("public/en/sect/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/sect/index.xml"`)
th.assertFileContent(t, fs, "public/fr/plaques/frtag1/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/plaques/frtag1/index.xml"`) th.assertFileContent("public/fr/plaques/frtag1/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/plaques/frtag1/index.xml"`)
th.assertFileContent(t, fs, "public/en/tags/tag1/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/tags/tag1/index.xml"`) th.assertFileContent("public/en/tags/tag1/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/tags/tag1/index.xml"`)
// Check paginators // Check paginators
th.assertFileContent(t, fs, "public/fr/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/"`) th.assertFileContent("public/fr/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/"`)
th.assertFileContent(t, fs, "public/en/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/"`) th.assertFileContent("public/en/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/"`)
th.assertFileContent(t, fs, "public/fr/page/2/index.html", defaultInSubDir, "Home Page 2", "Bonjour", "http://example.com/blog/fr/") th.assertFileContent("public/fr/page/2/index.html", defaultInSubDir, "Home Page 2", "Bonjour", "http://example.com/blog/fr/")
th.assertFileContent(t, fs, "public/en/page/2/index.html", defaultInSubDir, "Home Page 2", "Hello", "http://example.com/blog/en/") th.assertFileContent("public/en/page/2/index.html", defaultInSubDir, "Home Page 2", "Hello", "http://example.com/blog/en/")
th.assertFileContent(t, fs, "public/fr/sect/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/sect/"`) th.assertFileContent("public/fr/sect/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/sect/"`)
th.assertFileContent(t, fs, "public/en/sect/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/sect/"`) th.assertFileContent("public/en/sect/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/sect/"`)
th.assertFileContent(t, fs, "public/fr/sect/page/2/index.html", defaultInSubDir, "List Page 2", "Bonjour", "http://example.com/blog/fr/sect/") th.assertFileContent("public/fr/sect/page/2/index.html", defaultInSubDir, "List Page 2", "Bonjour", "http://example.com/blog/fr/sect/")
th.assertFileContent(t, fs, "public/en/sect/page/2/index.html", defaultInSubDir, "List Page 2", "Hello", "http://example.com/blog/en/sect/") th.assertFileContent("public/en/sect/page/2/index.html", defaultInSubDir, "List Page 2", "Hello", "http://example.com/blog/en/sect/")
th.assertFileContent(t, fs, "public/fr/plaques/frtag1/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/plaques/frtag1/"`) th.assertFileContent("public/fr/plaques/frtag1/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/plaques/frtag1/"`)
th.assertFileContent(t, fs, "public/en/tags/tag1/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/tags/tag1/"`) th.assertFileContent("public/en/tags/tag1/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/tags/tag1/"`)
th.assertFileContent(t, fs, "public/fr/plaques/frtag1/page/2/index.html", defaultInSubDir, "List Page 2", "Bonjour", "http://example.com/blog/fr/plaques/frtag1/") th.assertFileContent("public/fr/plaques/frtag1/page/2/index.html", defaultInSubDir, "List Page 2", "Bonjour", "http://example.com/blog/fr/plaques/frtag1/")
th.assertFileContent(t, fs, "public/en/tags/tag1/page/2/index.html", defaultInSubDir, "List Page 2", "Hello", "http://example.com/blog/en/tags/tag1/") th.assertFileContent("public/en/tags/tag1/page/2/index.html", defaultInSubDir, "List Page 2", "Hello", "http://example.com/blog/en/tags/tag1/")
// nn (Nynorsk) and nb (Bokmål) have custom pagePath: side ("page" in Norwegian) // nn (Nynorsk) and nb (Bokmål) have custom pagePath: side ("page" in Norwegian)
th.assertFileContent(t, fs, "public/nn/side/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/nn/"`) th.assertFileContent("public/nn/side/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/nn/"`)
th.assertFileContent(t, fs, "public/nb/side/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/nb/"`) th.assertFileContent("public/nb/side/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/nb/"`)
}
type testHelper struct {
Cfg config.Provider
} }
func (th testHelper) replaceDefaultContentLanguageValue(value string, defaultInSubDir bool) string { func (th testHelper) replaceDefaultContentLanguageValue(value string, defaultInSubDir bool) string {
@ -153,25 +147,6 @@ func (th testHelper) replaceDefaultContentLanguageValue(value string, defaultInS
} }
func (th testHelper) assertFileContent(t *testing.T, fs *hugofs.Fs, filename string, defaultInSubDir bool, matches ...string) {
filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir)
content := readDestination(t, fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir)
require.True(t, strings.Contains(content, match), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1)))
}
}
func (th testHelper) assertFileContentRegexp(t *testing.T, fs *hugofs.Fs, filename string, defaultInSubDir bool, matches ...string) {
filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir)
content := readDestination(t, fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir)
r := regexp.MustCompile(match)
require.True(t, r.MatchString(content), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1)))
}
}
func TestMultiSitesWithTwoLanguages(t *testing.T) { func TestMultiSitesWithTwoLanguages(t *testing.T) {
t.Parallel() t.Parallel()
mm := afero.NewMemMapFs() mm := afero.NewMemMapFs()
@ -243,7 +218,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
require.Len(t, sites.Sites, 4) require.Len(t, sites.Sites, 4)
fs := sites.Fs fs := sites.Fs
th := testHelper{sites.Cfg} th := testHelper{sites.Cfg, fs, t}
err := sites.Build(BuildCfg{}) err := sites.Build(BuildCfg{})
if err != nil { if err != nil {
@ -287,7 +262,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
require.Equal(t, "http://example.com/blog/superbob", permalink, "invalid doc3 permalink") require.Equal(t, "http://example.com/blog/superbob", permalink, "invalid doc3 permalink")
require.Equal(t, "/superbob", doc3.URL(), "invalid url, was specified on doc3") require.Equal(t, "/superbob", doc3.URL(), "invalid url, was specified on doc3")
th.assertFileContent(t, fs, "public/superbob/index.html", true, "doc3|Hello|en") th.assertFileContent("public/superbob/index.html", true, "doc3|Hello|en")
require.Equal(t, doc2.Next, doc3, "doc3 should follow doc2, in .Next") require.Equal(t, doc2.Next, doc3, "doc3 should follow doc2, in .Next")
doc1fr := doc1en.Translations()[0] doc1fr := doc1en.Translations()[0]
@ -331,12 +306,12 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
require.True(t, strings.Contains(languageRedirect, "0; url=http://example.com/blog/fr"), languageRedirect) require.True(t, strings.Contains(languageRedirect, "0; url=http://example.com/blog/fr"), languageRedirect)
// check home page content (including data files rendering) // check home page content (including data files rendering)
th.assertFileContent(t, fs, "public/en/index.html", true, "Home Page 1", "Hello", "Hugo Rocks!") th.assertFileContent("public/en/index.html", true, "Home Page 1", "Hello", "Hugo Rocks!")
th.assertFileContent(t, fs, "public/fr/index.html", true, "Home Page 1", "Bonjour", "Hugo Rocks!") th.assertFileContent("public/fr/index.html", true, "Home Page 1", "Bonjour", "Hugo Rocks!")
// check single page content // check single page content
th.assertFileContent(t, fs, "public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour") th.assertFileContent("public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour")
th.assertFileContent(t, fs, "public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello") th.assertFileContent("public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello")
// Check node translations // Check node translations
homeEn := enSite.getPage(KindHome) homeEn := enSite.getPage(KindHome)
@ -414,7 +389,7 @@ func TestMultiSitesRebuild(t *testing.T) {
sites := createMultiTestSites(t, siteConfig, multiSiteTOMLConfigTemplate) sites := createMultiTestSites(t, siteConfig, multiSiteTOMLConfigTemplate)
fs := sites.Fs fs := sites.Fs
cfg := BuildCfg{Watching: true} cfg := BuildCfg{Watching: true}
th := testHelper{sites.Cfg} th := testHelper{sites.Cfg, fs, t}
err := sites.Build(cfg) err := sites.Build(cfg)
@ -435,12 +410,12 @@ func TestMultiSitesRebuild(t *testing.T) {
require.Len(t, frSite.RegularPages, 3) require.Len(t, frSite.RegularPages, 3)
// Verify translations // Verify translations
th.assertFileContent(t, fs, "public/en/sect/doc1-slug/index.html", true, "Hello") th.assertFileContent("public/en/sect/doc1-slug/index.html", true, "Hello")
th.assertFileContent(t, fs, "public/fr/sect/doc1/index.html", true, "Bonjour") th.assertFileContent("public/fr/sect/doc1/index.html", true, "Bonjour")
// check single page content // check single page content
th.assertFileContent(t, fs, "public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour") th.assertFileContent("public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour")
th.assertFileContent(t, fs, "public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello") th.assertFileContent("public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello")
for i, this := range []struct { for i, this := range []struct {
preFunc func(t *testing.T) preFunc func(t *testing.T)
@ -578,8 +553,8 @@ func TestMultiSitesRebuild(t *testing.T) {
require.Len(t, enSite.RegularPages, 5) require.Len(t, enSite.RegularPages, 5)
require.Len(t, enSite.AllPages, 30) require.Len(t, enSite.AllPages, 30)
require.Len(t, frSite.RegularPages, 4) require.Len(t, frSite.RegularPages, 4)
th.assertFileContent(t, fs, "public/fr/sect/doc1/index.html", true, "Single", "Modified Shortcode: Salut") th.assertFileContent("public/fr/sect/doc1/index.html", true, "Single", "Modified Shortcode: Salut")
th.assertFileContent(t, fs, "public/en/sect/doc1-slug/index.html", true, "Single", "Modified Shortcode: Hello") th.assertFileContent("public/en/sect/doc1-slug/index.html", true, "Single", "Modified Shortcode: Hello")
}, },
}, },
} { } {
@ -700,7 +675,8 @@ func TestChangeDefaultLanguage(t *testing.T) {
require.Equal(t, mf, sites.Fs.Source) require.Equal(t, mf, sites.Fs.Source)
cfg := BuildCfg{} cfg := BuildCfg{}
th := testHelper{sites.Cfg} fs := sites.Fs
th := testHelper{sites.Cfg, fs, t}
err := sites.Build(cfg) err := sites.Build(cfg)
@ -708,10 +684,8 @@ func TestChangeDefaultLanguage(t *testing.T) {
t.Fatalf("Failed to build sites: %s", err) t.Fatalf("Failed to build sites: %s", err)
} }
fs := sites.Fs th.assertFileContent("public/sect/doc1/index.html", false, "Single", "Bonjour")
th.assertFileContent("public/en/sect/doc2/index.html", false, "Single", "Hello")
th.assertFileContent(t, fs, "public/sect/doc1/index.html", false, "Single", "Bonjour")
th.assertFileContent(t, fs, "public/en/sect/doc2/index.html", false, "Single", "Hello")
newConfig := createConfig(t, testSiteConfig{Fs: mf, DefaultContentLanguage: "en", DefaultContentLanguageInSubdir: false}, multiSiteTOMLConfigTemplate) newConfig := createConfig(t, testSiteConfig{Fs: mf, DefaultContentLanguage: "en", DefaultContentLanguageInSubdir: false}, multiSiteTOMLConfigTemplate)
@ -728,8 +702,8 @@ func TestChangeDefaultLanguage(t *testing.T) {
} }
// Default language is now en, so that should now be the "root" language // Default language is now en, so that should now be the "root" language
th.assertFileContent(t, fs, "public/fr/sect/doc1/index.html", false, "Single", "Bonjour") th.assertFileContent("public/fr/sect/doc1/index.html", false, "Single", "Bonjour")
th.assertFileContent(t, fs, "public/sect/doc2/index.html", false, "Single", "Hello") th.assertFileContent("public/sect/doc2/index.html", false, "Single", "Hello")
} }
func TestTableOfContentsInShortcodes(t *testing.T) { func TestTableOfContentsInShortcodes(t *testing.T) {
@ -750,11 +724,11 @@ func TestTableOfContentsInShortcodes(t *testing.T) {
t.Fatalf("Failed to build sites: %s", err) t.Fatalf("Failed to build sites: %s", err)
} }
th := testHelper{sites.Cfg}
fs := sites.Fs fs := sites.Fs
th := testHelper{sites.Cfg, fs, t}
th.assertFileContent(t, fs, "public/en/post/simple/index.html", true, tocPageSimpleExpected) th.assertFileContent("public/en/post/simple/index.html", true, tocPageSimpleExpected)
th.assertFileContent(t, fs, "public/en/post/withSCInHeading/index.html", true, tocPageWithShortcodesInHeadingsExpected) th.assertFileContent("public/en/post/withSCInHeading/index.html", true, tocPageWithShortcodesInHeadingsExpected)
} }
var tocShortcode = ` var tocShortcode = `
@ -1280,7 +1254,7 @@ func writeToFs(t *testing.T, fs afero.Fs, filename, content string) {
} }
} }
func readDestination(t *testing.T, fs *hugofs.Fs, filename string) string { func readDestination(t testing.TB, fs *hugofs.Fs, filename string) string {
return readFileFromFs(t, fs.Destination, filename) return readFileFromFs(t, fs.Destination, filename)
} }
@ -1296,7 +1270,7 @@ func readSource(t *testing.T, fs *hugofs.Fs, filename string) string {
return readFileFromFs(t, fs.Source, filename) return readFileFromFs(t, fs.Source, filename)
} }
func readFileFromFs(t *testing.T, fs afero.Fs, filename string) string { func readFileFromFs(t testing.TB, fs afero.Fs, filename string) string {
filename = filepath.FromSlash(filename) filename = filepath.FromSlash(filename)
b, err := afero.ReadFile(fs, filename) b, err := afero.ReadFile(fs, filename)
if err != nil { if err != nil {

View file

@ -58,7 +58,7 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("uglyURLs", ugly) cfg.Set("uglyURLs", ugly)
@ -81,7 +81,7 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
// date order: home, sect1, sect2, cat/hugo, cat/web, categories // date order: home, sect1, sect2, cat/hugo, cat/web, categories
th.assertFileContent(t, fs, filepath.Join("public", "index.html"), false, th.assertFileContent(filepath.Join("public", "index.html"), false,
"Index Title: Home Sweet Home!", "Index Title: Home Sweet Home!",
"Home <strong>Content!</strong>", "Home <strong>Content!</strong>",
"# Pages: 4", "# Pages: 4",
@ -90,7 +90,7 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
"GetPage: Section1 ", "GetPage: Section1 ",
) )
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "sect1", "regular1"), false, "Single Title: Page 01", "Content Page 01") th.assertFileContent(expectedFilePath(ugly, "public", "sect1", "regular1"), false, "Single Title: Page 01", "Content Page 01")
nodes := sites.findAllPagesByKindNotIn(KindPage) nodes := sites.findAllPagesByKindNotIn(KindPage)
@ -116,24 +116,24 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
require.True(t, first.IsPage()) require.True(t, first.IsPage())
// Check Home paginator // Check Home paginator
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "page", "2"), false, th.assertFileContent(expectedFilePath(ugly, "public", "page", "2"), false,
"Pag: Page 02") "Pag: Page 02")
// Check Sections // Check Sections
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "sect1"), false, th.assertFileContent(expectedFilePath(ugly, "public", "sect1"), false,
"Section Title: Section", "Section1 <strong>Content!</strong>", "Section Title: Section", "Section1 <strong>Content!</strong>",
"Date: 2009-01-04", "Date: 2009-01-04",
"Lastmod: 2009-01-05", "Lastmod: 2009-01-05",
) )
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "sect2"), false, th.assertFileContent(expectedFilePath(ugly, "public", "sect2"), false,
"Section Title: Section", "Section2 <strong>Content!</strong>", "Section Title: Section", "Section2 <strong>Content!</strong>",
"Date: 2009-01-06", "Date: 2009-01-06",
"Lastmod: 2009-01-07", "Lastmod: 2009-01-07",
) )
// Check Sections paginator // Check Sections paginator
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "sect1", "page", "2"), false, th.assertFileContent(expectedFilePath(ugly, "public", "sect1", "page", "2"), false,
"Pag: Page 02") "Pag: Page 02")
sections := sites.findAllPagesByKind(KindSection) sections := sites.findAllPagesByKind(KindSection)
@ -141,13 +141,13 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
require.Len(t, sections, 2) require.Len(t, sections, 2)
// Check taxonomy lists // Check taxonomy lists
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories", "hugo"), false, th.assertFileContent(expectedFilePath(ugly, "public", "categories", "hugo"), false,
"Taxonomy Title: Taxonomy Hugo", "Taxonomy Hugo <strong>Content!</strong>", "Taxonomy Title: Taxonomy Hugo", "Taxonomy Hugo <strong>Content!</strong>",
"Date: 2009-01-08", "Date: 2009-01-08",
"Lastmod: 2009-01-09", "Lastmod: 2009-01-09",
) )
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories", "hugo-rocks"), false, th.assertFileContent(expectedFilePath(ugly, "public", "categories", "hugo-rocks"), false,
"Taxonomy Title: Taxonomy Hugo Rocks", "Taxonomy Title: Taxonomy Hugo Rocks",
) )
@ -157,7 +157,7 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
require.NotNil(t, web) require.NotNil(t, web)
require.Len(t, web.Data["Pages"].(Pages), 4) require.Len(t, web.Data["Pages"].(Pages), 4)
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories", "web"), false, th.assertFileContent(expectedFilePath(ugly, "public", "categories", "web"), false,
"Taxonomy Title: Taxonomy Web", "Taxonomy Title: Taxonomy Web",
"Taxonomy Web <strong>Content!</strong>", "Taxonomy Web <strong>Content!</strong>",
"Date: 2009-01-10", "Date: 2009-01-10",
@ -165,12 +165,12 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
) )
// Check taxonomy list paginator // Check taxonomy list paginator
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories", "hugo", "page", "2"), false, th.assertFileContent(expectedFilePath(ugly, "public", "categories", "hugo", "page", "2"), false,
"Taxonomy Title: Taxonomy Hugo", "Taxonomy Title: Taxonomy Hugo",
"Pag: Page 02") "Pag: Page 02")
// Check taxonomy terms // Check taxonomy terms
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories"), false, th.assertFileContent(expectedFilePath(ugly, "public", "categories"), false,
"Taxonomy Terms Title: Taxonomy Term Categories", "Taxonomy Term Categories <strong>Content!</strong>", "k/v: hugo", "Taxonomy Terms Title: Taxonomy Term Categories", "Taxonomy Term Categories <strong>Content!</strong>", "k/v: hugo",
"Date: 2009-01-14", "Date: 2009-01-14",
"Lastmod: 2009-01-15", "Lastmod: 2009-01-15",
@ -179,11 +179,11 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
// There are no pages to paginate over in the taxonomy terms. // There are no pages to paginate over in the taxonomy terms.
// RSS // RSS
th.assertFileContent(t, fs, filepath.Join("public", "customrss.xml"), false, "Recent content in Home Sweet Home! on Hugo Rocks", "<rss") th.assertFileContent(filepath.Join("public", "customrss.xml"), false, "Recent content in Home Sweet Home! on Hugo Rocks", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "sect1", "customrss.xml"), false, "Recent content in Section1 on Hugo Rocks", "<rss") th.assertFileContent(filepath.Join("public", "sect1", "customrss.xml"), false, "Recent content in Section1 on Hugo Rocks", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "sect2", "customrss.xml"), false, "Recent content in Section2 on Hugo Rocks", "<rss") th.assertFileContent(filepath.Join("public", "sect2", "customrss.xml"), false, "Recent content in Section2 on Hugo Rocks", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", "customrss.xml"), false, "Recent content in Taxonomy Hugo on Hugo Rocks", "<rss") th.assertFileContent(filepath.Join("public", "categories", "hugo", "customrss.xml"), false, "Recent content in Taxonomy Hugo on Hugo Rocks", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "categories", "web", "customrss.xml"), false, "Recent content in Taxonomy Web on Hugo Rocks", "<rss") th.assertFileContent(filepath.Join("public", "categories", "web", "customrss.xml"), false, "Recent content in Taxonomy Web on Hugo Rocks", "<rss")
} }
@ -198,7 +198,7 @@ func doTestNodesWithNoContentFile(t *testing.T, ugly bool) {
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("uglyURLs", ugly) cfg.Set("uglyURLs", ugly)
@ -226,21 +226,21 @@ func doTestNodesWithNoContentFile(t *testing.T, ugly bool) {
require.Len(t, homePage.Pages, 4) require.Len(t, homePage.Pages, 4)
require.True(t, homePage.Path() == "") require.True(t, homePage.Path() == "")
th.assertFileContent(t, fs, filepath.Join("public", "index.html"), false, th.assertFileContent(filepath.Join("public", "index.html"), false,
"Index Title: Hugo Rocks!", "Index Title: Hugo Rocks!",
"Date: 2010-06-12", "Date: 2010-06-12",
"Lastmod: 2010-06-13", "Lastmod: 2010-06-13",
) )
// Taxonomy list // Taxonomy list
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories", "hugo"), false, th.assertFileContent(expectedFilePath(ugly, "public", "categories", "hugo"), false,
"Taxonomy Title: Hugo", "Taxonomy Title: Hugo",
"Date: 2010-06-12", "Date: 2010-06-12",
"Lastmod: 2010-06-13", "Lastmod: 2010-06-13",
) )
// Taxonomy terms // Taxonomy terms
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories"), false, th.assertFileContent(expectedFilePath(ugly, "public", "categories"), false,
"Taxonomy Terms Title: Categories", "Taxonomy Terms Title: Categories",
) )
@ -258,24 +258,24 @@ func doTestNodesWithNoContentFile(t *testing.T, ugly bool) {
} }
// Sections // Sections
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "sect1"), false, th.assertFileContent(expectedFilePath(ugly, "public", "sect1"), false,
"Section Title: Sect1s", "Section Title: Sect1s",
"Date: 2010-06-12", "Date: 2010-06-12",
"Lastmod: 2010-06-13", "Lastmod: 2010-06-13",
) )
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "sect2"), false, th.assertFileContent(expectedFilePath(ugly, "public", "sect2"), false,
"Section Title: Sect2s", "Section Title: Sect2s",
"Date: 2008-07-06", "Date: 2008-07-06",
"Lastmod: 2008-07-09", "Lastmod: 2008-07-09",
) )
// RSS // RSS
th.assertFileContent(t, fs, filepath.Join("public", "customrss.xml"), false, "Hugo Rocks!", "<rss") th.assertFileContent(filepath.Join("public", "customrss.xml"), false, "Hugo Rocks!", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "sect1", "customrss.xml"), false, "Recent content in Sect1s on Hugo Rocks!", "<rss") th.assertFileContent(filepath.Join("public", "sect1", "customrss.xml"), false, "Recent content in Sect1s on Hugo Rocks!", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "sect2", "customrss.xml"), false, "Recent content in Sect2s on Hugo Rocks!", "<rss") th.assertFileContent(filepath.Join("public", "sect2", "customrss.xml"), false, "Recent content in Sect2s on Hugo Rocks!", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", "customrss.xml"), false, "Recent content in Hugo on Hugo Rocks!", "<rss") th.assertFileContent(filepath.Join("public", "categories", "hugo", "customrss.xml"), false, "Recent content in Hugo on Hugo Rocks!", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "categories", "web", "customrss.xml"), false, "Recent content in Web on Hugo Rocks!", "<rss") th.assertFileContent(filepath.Join("public", "categories", "web", "customrss.xml"), false, "Recent content in Web on Hugo Rocks!", "<rss")
} }
@ -329,7 +329,7 @@ title = "Deutsche Hugo"
writeRegularPagesForNodeAsPageTestsWithLang(t, fs, lang) writeRegularPagesForNodeAsPageTestsWithLang(t, fs, lang)
} }
th := testHelper{cfg} th := testHelper{cfg, fs, t}
sites, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg}) sites, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg})
@ -376,53 +376,53 @@ title = "Deutsche Hugo"
require.Equal(t, expetedPermalink(ugly, "/en/sect1/"), enSect.Permalink()) require.Equal(t, expetedPermalink(ugly, "/en/sect1/"), enSect.Permalink())
th.assertFileContent(t, fs, filepath.Join("public", "nn", "index.html"), true, th.assertFileContent(filepath.Join("public", "nn", "index.html"), true,
"Index Title: Hugo på norsk") "Index Title: Hugo på norsk")
th.assertFileContent(t, fs, filepath.Join("public", "en", "index.html"), true, th.assertFileContent(filepath.Join("public", "en", "index.html"), true,
"Index Title: Home Sweet Home!", "<strong>Content!</strong>") "Index Title: Home Sweet Home!", "<strong>Content!</strong>")
th.assertFileContent(t, fs, filepath.Join("public", "de", "index.html"), true, th.assertFileContent(filepath.Join("public", "de", "index.html"), true,
"Index Title: Home Sweet Home!", "<strong>Content!</strong>") "Index Title: Home Sweet Home!", "<strong>Content!</strong>")
// Taxonomy list // Taxonomy list
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "categories", "hugo"), true, th.assertFileContent(expectedFilePath(ugly, "public", "nn", "categories", "hugo"), true,
"Taxonomy Title: Hugo") "Taxonomy Title: Hugo")
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "categories", "hugo"), true, th.assertFileContent(expectedFilePath(ugly, "public", "en", "categories", "hugo"), true,
"Taxonomy Title: Taxonomy Hugo") "Taxonomy Title: Taxonomy Hugo")
// Taxonomy terms // Taxonomy terms
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "categories"), true, th.assertFileContent(expectedFilePath(ugly, "public", "nn", "categories"), true,
"Taxonomy Terms Title: Categories") "Taxonomy Terms Title: Categories")
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "categories"), true, th.assertFileContent(expectedFilePath(ugly, "public", "en", "categories"), true,
"Taxonomy Terms Title: Taxonomy Term Categories") "Taxonomy Terms Title: Taxonomy Term Categories")
// Sections // Sections
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "sect1"), true, th.assertFileContent(expectedFilePath(ugly, "public", "nn", "sect1"), true,
"Section Title: Sect1s") "Section Title: Sect1s")
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "sect2"), true, th.assertFileContent(expectedFilePath(ugly, "public", "nn", "sect2"), true,
"Section Title: Sect2s") "Section Title: Sect2s")
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "sect1"), true, th.assertFileContent(expectedFilePath(ugly, "public", "en", "sect1"), true,
"Section Title: Section1") "Section Title: Section1")
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "sect2"), true, th.assertFileContent(expectedFilePath(ugly, "public", "en", "sect2"), true,
"Section Title: Section2") "Section Title: Section2")
// Regular pages // Regular pages
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "sect1", "regular1"), true, th.assertFileContent(expectedFilePath(ugly, "public", "en", "sect1", "regular1"), true,
"Single Title: Page 01") "Single Title: Page 01")
th.assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "sect1", "regular2"), true, th.assertFileContent(expectedFilePath(ugly, "public", "nn", "sect1", "regular2"), true,
"Single Title: Page 02") "Single Title: Page 02")
// RSS // RSS
th.assertFileContent(t, fs, filepath.Join("public", "nn", "customrss.xml"), true, "Hugo på norsk", "<rss") th.assertFileContent(filepath.Join("public", "nn", "customrss.xml"), true, "Hugo på norsk", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "nn", "sect1", "customrss.xml"), true, "Recent content in Sect1s on Hugo på norsk", "<rss") th.assertFileContent(filepath.Join("public", "nn", "sect1", "customrss.xml"), true, "Recent content in Sect1s on Hugo på norsk", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "nn", "sect2", "customrss.xml"), true, "Recent content in Sect2s on Hugo på norsk", "<rss") th.assertFileContent(filepath.Join("public", "nn", "sect2", "customrss.xml"), true, "Recent content in Sect2s on Hugo på norsk", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "nn", "categories", "hugo", "customrss.xml"), true, "Recent content in Hugo on Hugo på norsk", "<rss") th.assertFileContent(filepath.Join("public", "nn", "categories", "hugo", "customrss.xml"), true, "Recent content in Hugo on Hugo på norsk", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "nn", "categories", "web", "customrss.xml"), true, "Recent content in Web on Hugo på norsk", "<rss") th.assertFileContent(filepath.Join("public", "nn", "categories", "web", "customrss.xml"), true, "Recent content in Web on Hugo på norsk", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "en", "customrss.xml"), true, "Recent content in Home Sweet Home! on Hugo in English", "<rss") th.assertFileContent(filepath.Join("public", "en", "customrss.xml"), true, "Recent content in Home Sweet Home! on Hugo in English", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "en", "sect1", "customrss.xml"), true, "Recent content in Section1 on Hugo in English", "<rss") th.assertFileContent(filepath.Join("public", "en", "sect1", "customrss.xml"), true, "Recent content in Section1 on Hugo in English", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "en", "sect2", "customrss.xml"), true, "Recent content in Section2 on Hugo in English", "<rss") th.assertFileContent(filepath.Join("public", "en", "sect2", "customrss.xml"), true, "Recent content in Section2 on Hugo in English", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "en", "categories", "hugo", "customrss.xml"), true, "Recent content in Taxonomy Hugo on Hugo in English", "<rss") th.assertFileContent(filepath.Join("public", "en", "categories", "hugo", "customrss.xml"), true, "Recent content in Taxonomy Hugo on Hugo in English", "<rss")
th.assertFileContent(t, fs, filepath.Join("public", "en", "categories", "web", "customrss.xml"), true, "Recent content in Taxonomy Web on Hugo in English", "<rss") th.assertFileContent(filepath.Join("public", "en", "categories", "web", "customrss.xml"), true, "Recent content in Taxonomy Web on Hugo in English", "<rss")
} }
@ -430,7 +430,7 @@ func TestNodesWithTaxonomies(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("paginate", 1) cfg.Set("paginate", 1)
@ -454,8 +454,8 @@ categories: [
require.NoError(t, h.Build(BuildCfg{})) require.NoError(t, h.Build(BuildCfg{}))
th.assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy Title: Hugo", "# Pages: 5") th.assertFileContent(filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy Title: Hugo", "# Pages: 5")
th.assertFileContent(t, fs, filepath.Join("public", "categories", "home", "index.html"), true, "Taxonomy Title: Home", "# Pages: 1") th.assertFileContent(filepath.Join("public", "categories", "home", "index.html"), true, "Taxonomy Title: Home", "# Pages: 1")
} }
@ -463,7 +463,7 @@ func TestNodesWithMenu(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("paginate", 1) cfg.Set("paginate", 1)
@ -502,9 +502,9 @@ menu:
require.NoError(t, h.Build(BuildCfg{})) require.NoError(t, h.Build(BuildCfg{}))
th.assertFileContent(t, fs, filepath.Join("public", "index.html"), true, "Home With Menu", "Home Menu Item: Go Home!: /") th.assertFileContent(filepath.Join("public", "index.html"), true, "Home With Menu", "Home Menu Item: Go Home!: /")
th.assertFileContent(t, fs, filepath.Join("public", "sect1", "index.html"), true, "Sect1 With Menu", "Section Menu Item: Go Sect1!: /sect1/") th.assertFileContent(filepath.Join("public", "sect1", "index.html"), true, "Sect1 With Menu", "Section Menu Item: Go Sect1!: /sect1/")
th.assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy With Menu", "Taxonomy Menu Item: Go Tax Hugo!: /categories/hugo/") th.assertFileContent(filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy With Menu", "Taxonomy Menu Item: Go Tax Hugo!: /categories/hugo/")
} }
@ -512,7 +512,7 @@ func TestNodesWithAlias(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("paginate", 1) cfg.Set("paginate", 1)
@ -535,8 +535,8 @@ aliases:
require.NoError(t, h.Build(BuildCfg{})) require.NoError(t, h.Build(BuildCfg{}))
th.assertFileContent(t, fs, filepath.Join("public", "index.html"), true, "Home With Alias") th.assertFileContent(filepath.Join("public", "index.html"), true, "Home With Alias")
th.assertFileContent(t, fs, filepath.Join("public", "my", "new", "home.html"), true, "content=\"0; url=http://base/") th.assertFileContent(filepath.Join("public", "my", "new", "home.html"), true, "content=\"0; url=http://base/")
} }
@ -544,7 +544,7 @@ func TestNodesWithSectionWithIndexPageOnly(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("paginate", 1) cfg.Set("paginate", 1)
@ -564,7 +564,7 @@ My Section Content
require.NoError(t, h.Build(BuildCfg{})) require.NoError(t, h.Build(BuildCfg{}))
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), true, "My Section") th.assertFileContent(filepath.Join("public", "sect", "index.html"), true, "My Section")
} }
@ -572,7 +572,7 @@ func TestNodesWithURLs(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("paginate", 1) cfg.Set("paginate", 1)
@ -595,7 +595,7 @@ My Section Content
require.NoError(t, h.Build(BuildCfg{})) require.NoError(t, h.Build(BuildCfg{}))
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), true, "My Section") th.assertFileContent(filepath.Join("public", "sect", "index.html"), true, "My Section")
s := h.Sites[0] s := h.Sites[0]

View file

@ -320,9 +320,9 @@ Pages: {{ .Paginator.TotalPages }}
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th := testHelper{s.Cfg} th := testHelper{s.Cfg, s.Fs, t}
th.assertFileContent(t, fs, filepath.Join("public", "阅读", "testing", "2", "index.html"), false, "2: /%E9%98%85%E8%AF%BB/testing/2/") th.assertFileContent(filepath.Join("public", "阅读", "testing", "2", "index.html"), false, "2: /%E9%98%85%E8%AF%BB/testing/2/")
} }

View file

@ -30,7 +30,7 @@ func TestRobotsTXTOutput(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
cfg.Set("baseURL", "http://auth/bub/") cfg.Set("baseURL", "http://auth/bub/")
@ -41,6 +41,6 @@ func TestRobotsTXTOutput(t *testing.T) {
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th.assertFileContent(t, fs, "public/robots.txt", true, "User-agent: Googlebot") th.assertFileContent("public/robots.txt", true, "User-agent: Googlebot")
} }

View file

@ -25,7 +25,7 @@ func TestRSSOutput(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
) )
rssLimit := len(weightedSources) - 1 rssLimit := len(weightedSources) - 1
@ -44,11 +44,11 @@ func TestRSSOutput(t *testing.T) {
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
// Home RSS // Home RSS
th.assertFileContent(t, fs, filepath.Join("public", rssURI), true, "<?xml", "rss version", "RSSTest") th.assertFileContent(filepath.Join("public", rssURI), true, "<?xml", "rss version", "RSSTest")
// Section RSS // Section RSS
th.assertFileContent(t, fs, filepath.Join("public", "sect", rssURI), true, "<?xml", "rss version", "Sects on RSSTest") th.assertFileContent(filepath.Join("public", "sect", rssURI), true, "<?xml", "rss version", "Sects on RSSTest")
// Taxonomy RSS // Taxonomy RSS
th.assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", rssURI), true, "<?xml", "rss version", "Hugo on RSSTest") th.assertFileContent(filepath.Join("public", "categories", "hugo", rssURI), true, "<?xml", "rss version", "Hugo on RSSTest")
// RSS Item Limit // RSS Item Limit
content := readDestination(t, fs, filepath.Join("public", rssURI)) content := readDestination(t, fs, filepath.Join("public", rssURI))

View file

@ -541,7 +541,7 @@ tags:
writeSourcesToSource(t, "content", fs, sources...) writeSourcesToSource(t, "content", fs, sources...)
s := buildSingleSite(t, deps.DepsCfg{WithTemplate: addTemplates, Fs: fs, Cfg: cfg}, BuildCfg{}) s := buildSingleSite(t, deps.DepsCfg{WithTemplate: addTemplates, Fs: fs, Cfg: cfg}, BuildCfg{})
th := testHelper{s.Cfg} th := testHelper{s.Cfg, s.Fs, t}
for _, test := range tests { for _, test := range tests {
if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() { if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() {
@ -555,7 +555,7 @@ tags:
continue continue
} }
th.assertFileContent(t, fs, test.outFile, true, test.expected) th.assertFileContent(test.outFile, true, test.expected)
} }
} }

View file

@ -263,7 +263,7 @@ THE END.`, refShortcode)),
t.Fatalf("Expected 3 got %d pages", len(s.AllPages)) t.Fatalf("Expected 3 got %d pages", len(s.AllPages))
} }
th := testHelper{s.Cfg} th := testHelper{s.Cfg, s.Fs, t}
tests := []struct { tests := []struct {
doc string doc string
@ -275,7 +275,7 @@ THE END.`, refShortcode)),
} }
for _, test := range tests { for _, test := range tests {
th.assertFileContent(t, fs, test.doc, true, test.expected) th.assertFileContent(test.doc, true, test.expected)
} }
@ -409,7 +409,7 @@ func doTestSectionNaming(t *testing.T, canonify, uglify, pluralize bool) {
writeSource(t, fs, filepath.Join("layouts", "_default/list.html"), "{{.Title}}") writeSource(t, fs, filepath.Join("layouts", "_default/list.html"), "{{.Title}}")
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th := testHelper{s.Cfg} th := testHelper{s.Cfg, s.Fs, t}
tests := []struct { tests := []struct {
doc string doc string
pluralAware bool pluralAware bool
@ -429,7 +429,7 @@ func doTestSectionNaming(t *testing.T, canonify, uglify, pluralize bool) {
test.expected = inflect.Pluralize(test.expected) test.expected = inflect.Pluralize(test.expected)
} }
th.assertFileContent(t, fs, filepath.Join("public", test.doc), true, test.expected) th.assertFileContent(filepath.Join("public", test.doc), true, test.expected)
} }
} }
@ -521,7 +521,7 @@ func TestAbsURLify(t *testing.T) {
writeSource(t, fs, filepath.Join("layouts", "blue/single.html"), templateWithURLAbs) writeSource(t, fs, filepath.Join("layouts", "blue/single.html"), templateWithURLAbs)
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th := testHelper{s.Cfg} th := testHelper{s.Cfg, s.Fs, t}
tests := []struct { tests := []struct {
file, expected string file, expected string
@ -542,7 +542,7 @@ func TestAbsURLify(t *testing.T) {
expected = strings.Replace(expected, baseURL, "", -1) expected = strings.Replace(expected, baseURL, "", -1)
} }
th.assertFileContent(t, fs, test.file, true, expected) th.assertFileContent(test.file, true, expected)
} }
} }

View file

@ -56,9 +56,9 @@ func doTestSitemapOutput(t *testing.T, internal bool) {
writeSourcesToSource(t, "content", fs, weightedSources...) writeSourcesToSource(t, "content", fs, weightedSources...)
s := buildSingleSite(t, depsCfg, BuildCfg{}) s := buildSingleSite(t, depsCfg, BuildCfg{})
th := testHelper{s.Cfg} th := testHelper{s.Cfg, s.Fs, t}
th.assertFileContent(t, s.Fs, "public/sitemap.xml", true, th.assertFileContent("public/sitemap.xml", true,
// Regular page // Regular page
" <loc>http://auth/bub/sect/doc1/</loc>", " <loc>http://auth/bub/sect/doc1/</loc>",
// Home page // Home page

View file

@ -84,9 +84,9 @@ p
writeSource(t, fs, filepath.Join("layouts", "_default", fmt.Sprintf("single.%s", suffix)), templ) writeSource(t, fs, filepath.Join("layouts", "_default", fmt.Sprintf("single.%s", suffix)), templ)
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
th := testHelper{s.Cfg} th := testHelper{s.Cfg, s.Fs, t}
th.assertFileContent(t, fs, filepath.Join("public", "p", "index.html"), true, th.assertFileContent(filepath.Join("public", "p", "index.html"), true,
"Page Title: My Title", "Page Title: My Title",
"My Content", "My Content",
"Hello World", "Hello World",

View file

@ -48,7 +48,7 @@ func TestBaseGoTemplate(t *testing.T) {
}, },
func(t *testing.T) { func(t *testing.T) {
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: sect") th.assertFileContent(filepath.Join("public", "sect", "index.html"), false, "Base: sect")
}, },
}, },
{ {
@ -59,7 +59,7 @@ func TestBaseGoTemplate(t *testing.T) {
}, },
func(t *testing.T) { func(t *testing.T) {
th.assertFileContent(t, fs, filepath.Join("public", "index.html"), false, "Base: index") th.assertFileContent(filepath.Join("public", "index.html"), false, "Base: index")
}, },
}, },
{ {
@ -70,7 +70,7 @@ func TestBaseGoTemplate(t *testing.T) {
}, },
func(t *testing.T) { func(t *testing.T) {
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: list") th.assertFileContent(filepath.Join("public", "sect", "index.html"), false, "Base: list")
}, },
}, },
{ {
@ -81,7 +81,7 @@ func TestBaseGoTemplate(t *testing.T) {
}, },
func(t *testing.T) { func(t *testing.T) {
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: list") th.assertFileContent(filepath.Join("public", "sect", "index.html"), false, "Base: list")
}, },
}, },
{ {
@ -94,7 +94,7 @@ func TestBaseGoTemplate(t *testing.T) {
}, },
func(t *testing.T) { func(t *testing.T) {
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: sect") th.assertFileContent(filepath.Join("public", "sect", "index.html"), false, "Base: sect")
}, },
}, },
{ {
@ -106,7 +106,7 @@ func TestBaseGoTemplate(t *testing.T) {
}, },
func(t *testing.T) { func(t *testing.T) {
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base Theme: sect") th.assertFileContent(filepath.Join("public", "sect", "index.html"), false, "Base Theme: sect")
}, },
}, },
{ {
@ -119,7 +119,7 @@ func TestBaseGoTemplate(t *testing.T) {
}, },
func(t *testing.T) { func(t *testing.T) {
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: list") th.assertFileContent(filepath.Join("public", "sect", "index.html"), false, "Base: list")
}, },
}, },
{ {
@ -131,13 +131,13 @@ func TestBaseGoTemplate(t *testing.T) {
}, },
func(t *testing.T) { func(t *testing.T) {
th.assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base Theme: list") th.assertFileContent(filepath.Join("public", "sect", "index.html"), false, "Base Theme: list")
}, },
}, },
} { } {
cfg, fs = newTestCfg() cfg, fs = newTestCfg()
th = testHelper{cfg} th = testHelper{cfg, fs, t}
writeSource(t, fs, filepath.Join("content", "sect", "page.md"), `--- writeSource(t, fs, filepath.Join("content", "sect", "page.md"), `---
title: Template test title: Template test

View file

@ -4,7 +4,14 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"regexp"
"github.com/spf13/hugo/config"
"github.com/spf13/hugo/deps" "github.com/spf13/hugo/deps"
"fmt"
"strings"
"github.com/spf13/hugo/helpers" "github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/source" "github.com/spf13/hugo/source"
"github.com/spf13/hugo/tpl" "github.com/spf13/hugo/tpl"
@ -20,6 +27,31 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
type testHelper struct {
Cfg config.Provider
Fs *hugofs.Fs
T testing.TB
}
func (th testHelper) assertFileContent(filename string, defaultInSubDir bool, matches ...string) {
filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir)
content := readDestination(th.T, th.Fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir)
require.True(th.T, strings.Contains(content, match), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1)))
}
}
func (th testHelper) assertFileContentRegexp(filename string, defaultInSubDir bool, matches ...string) {
filename = th.replaceDefaultContentLanguageValue(filename, defaultInSubDir)
content := readDestination(th.T, th.Fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match, defaultInSubDir)
r := regexp.MustCompile(match)
require.True(th.T, r.MatchString(content), fmt.Sprintf("File no match for\n%q in\n%q:\n%s", strings.Replace(match, "%", "%%", -1), filename, strings.Replace(content, "%", "%%", -1)))
}
}
func newTestPathSpec(fs *hugofs.Fs, v *viper.Viper) *helpers.PathSpec { func newTestPathSpec(fs *hugofs.Fs, v *viper.Viper) *helpers.PathSpec {
l := helpers.NewDefaultLanguage(v) l := helpers.NewDefaultLanguage(v)
return helpers.NewPathSpec(fs, l) return helpers.NewPathSpec(fs, l)