diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-20 09:33:35 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-20 22:20:02 +0100 |
commit | a3af4fe46e1e1d184538a83bc8375154a9669316 (patch) | |
tree | ed05300e0c60da957067777334ae2cd266e5fe8b /hugolib/testhelpers_test.go | |
parent | 2a6b26a7a520bf88af1413f3f00c7e2782abe8cd (diff) |
hugolib: Finish menu vs section content pages
This commit also fixes the default menu sort when the weight is 0.
Closes #2974
Diffstat (limited to 'hugolib/testhelpers_test.go')
-rw-r--r-- | hugolib/testhelpers_test.go | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 668b46b1d..92af07a46 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -6,12 +6,13 @@ import ( "regexp" - "github.com/spf13/hugo/config" - "github.com/spf13/hugo/deps" - "fmt" "strings" + "github.com/spf13/afero" + "github.com/spf13/hugo/config" + "github.com/spf13/hugo/deps" + "github.com/spf13/hugo/helpers" "github.com/spf13/hugo/source" "github.com/spf13/hugo/tpl" @@ -113,6 +114,39 @@ func newTestSite(t testing.TB, configKeyValues ...interface{}) *Site { return s } +func newTestSitesFromConfig(t testing.TB, tomlConfig string, layoutPathContentPairs ...string) (testHelper, *HugoSites) { + if len(layoutPathContentPairs)%2 != 0 { + t.Fatalf("Layouts must be provided in pairs") + } + mf := afero.NewMemMapFs() + + writeToFs(t, mf, "config.toml", tomlConfig) + + cfg, err := LoadConfig(mf, "", "config.toml") + require.NoError(t, err) + + fs := hugofs.NewFrom(mf, cfg) + th := testHelper{cfg, fs, t} + + for i := 0; i < len(layoutPathContentPairs); i += 2 { + writeSource(t, fs, layoutPathContentPairs[i], layoutPathContentPairs[i+1]) + } + + h, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg}) + + require.NoError(t, err) + + return th, h +} + +func newTestSitesFromConfigWithDefaultTemplates(t testing.TB, tomlConfig string) (testHelper, *HugoSites) { + return newTestSitesFromConfig(t, tomlConfig, + "layouts/_default/single.html", "Single|{{ .Title }}|{{ .Content }}", + "layouts/_default/list.html", "List|{{ .Title }}|{{ .Content }}", + "layouts/_default/terms.html", "Terms List|{{ .Title }}|{{ .Content }}", + ) +} + func newDebugLogger() *jww.Notepad { return jww.NewNotepad(jww.LevelDebug, jww.LevelError, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime) } |