From 1a0fb684edaeb2f5e68149532481db1547678831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 17 Mar 2018 19:24:02 +0100 Subject: [PATCH] Spring test cleaning #2 --- hugolib/404_test.go | 19 ++++--------------- hugolib/alias_test.go | 20 ++++++++------------ hugolib/testhelpers_test.go | 34 ++++++++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/hugolib/404_test.go b/hugolib/404_test.go index bbaed61d757..cd19e44d98b 100644 --- a/hugolib/404_test.go +++ b/hugolib/404_test.go @@ -14,30 +14,19 @@ package hugolib import ( - "path/filepath" - "testing" - - "github.com/gohugoio/hugo/deps" ) func Test404(t *testing.T) { t.Parallel() - var ( - cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} - ) - - cfg.Set("baseURL", "http://auth/bub/") - - writeSource(t, fs, filepath.Join("layouts", "404.html"), "Not Found!") - writeSource(t, fs, filepath.Join("content", "page.md"), "A page") - buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) + b := newTestSitesBuilder(t) + b.WithSimpleConfig().WithTemplatesAdded("404.html", "Not Found!") + b.CreateSites().Build(BuildCfg{}) // Note: We currently have only 1 404 page. One might think that we should have // multiple, to follow the Custom Output scheme, but I don't see how that wold work // right now. - th.assertFileContent("public/404.html", "Not Found") + b.AssertFileContent("public/404.html", "Not Found") } diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go index abbda5f355f..a5a9efd1a88 100644 --- a/hugolib/alias_test.go +++ b/hugolib/alias_test.go @@ -42,23 +42,19 @@ const aliasTemplate = "ALIASTEMPLATE" func TestAlias(t *testing.T) { t.Parallel() + assert := require.New(t) - var ( - cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} - ) - - writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias) - writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), basicTemplate) - - s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) + b := newTestSitesBuilder(t) + b.WithSimpleConfig().WithContent("page.md", pageWithAlias) + b.CreateSites().Build(BuildCfg{}) - require.Len(t, s.rawAllPages, 1) + assert.Equal(1, len(b.H.Sites)) + require.Len(t, b.H.Sites[0].RegularPages, 1) // the real page - th.assertFileContent(filepath.Join("public", "page", "index.html"), "For some moments the old man") + b.AssertFileContent("public/page/index.html", "For some moments the old man") // the alias redirector - th.assertFileContent(filepath.Join("public", "foo", "bar", "index.html"), " 0 { + s.WithContent(s.additionalContent...) + } + if len(s.additionalTemplates) > 0 { + s.WithTemplates(s.additionalTemplates...) + } if s.Cfg == nil { cfg, err := LoadConfig(s.Fs.Source, "", "config."+s.configFormat)