mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables the use if `t.Parallel` in tests. Updates #2701 Fixes #3016
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/hugo/deps"
|
||||
"github.com/spf13/hugo/hugofs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -33,38 +32,44 @@ const basicTemplate = "<html><body>{{.Content}}</body></html>"
|
||||
const aliasTemplate = "<html><body>ALIASTEMPLATE</body></html>"
|
||||
|
||||
func TestAlias(t *testing.T) {
|
||||
testCommonResetState()
|
||||
t.Parallel()
|
||||
|
||||
fs := hugofs.NewMem()
|
||||
var (
|
||||
cfg, fs = newTestCfg()
|
||||
th = testHelper{cfg}
|
||||
)
|
||||
|
||||
writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias)
|
||||
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), basicTemplate)
|
||||
|
||||
buildSingleSite(t, deps.DepsCfg{Fs: fs}, BuildCfg{})
|
||||
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
||||
|
||||
// the real page
|
||||
assertFileContent(t, fs, filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
|
||||
th.assertFileContent(t, fs, filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
|
||||
// the alias redirector
|
||||
assertFileContent(t, fs, filepath.Join("public", "foo", "bar", "index.html"), false, "<meta http-equiv=\"refresh\" content=\"0; ")
|
||||
th.assertFileContent(t, fs, filepath.Join("public", "foo", "bar", "index.html"), false, "<meta http-equiv=\"refresh\" content=\"0; ")
|
||||
}
|
||||
|
||||
func TestAliasTemplate(t *testing.T) {
|
||||
testCommonResetState()
|
||||
t.Parallel()
|
||||
|
||||
fs := hugofs.NewMem()
|
||||
var (
|
||||
cfg, fs = newTestCfg()
|
||||
th = testHelper{cfg}
|
||||
)
|
||||
|
||||
writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias)
|
||||
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), basicTemplate)
|
||||
writeSource(t, fs, filepath.Join("layouts", "alias.html"), aliasTemplate)
|
||||
|
||||
sites, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
|
||||
sites, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg})
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, sites.Build(BuildCfg{}))
|
||||
|
||||
// the real page
|
||||
assertFileContent(t, fs, filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
|
||||
th.assertFileContent(t, fs, filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
|
||||
// the alias redirector
|
||||
assertFileContent(t, fs, filepath.Join("public", "foo", "bar", "index.html"), false, "ALIASTEMPLATE")
|
||||
th.assertFileContent(t, fs, filepath.Join("public", "foo", "bar", "index.html"), false, "ALIASTEMPLATE")
|
||||
}
|
||||
|
Reference in New Issue
Block a user