From 67684065426a5efe47ed392e9b8b326c02253554 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 | 71 +++++++++++++++---------------------- hugolib/testhelpers_test.go | 38 +++++++++++++++----- 3 files changed, 62 insertions(+), 66 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..a04844bbe4b 100644 --- a/hugolib/alias_test.go +++ b/hugolib/alias_test.go @@ -18,7 +18,6 @@ import ( "runtime" "testing" - "github.com/gohugoio/hugo/deps" "github.com/stretchr/testify/require" ) @@ -42,73 +41,59 @@ const aliasTemplate = "ALIASTEMPLATE" func TestAlias(t *testing.T) { t.Parallel() + assert := require.New(t) - var ( - cfg, fs = newTestCfg() - th = testHelper{cfg, fs, t} - ) + b := newTestSitesBuilder(t) + b.WithSimpleConfig().WithContent("page.md", pageWithAlias) + b.CreateSites().Build(BuildCfg{}) - 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{}) - - 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) @@ -316,6 +334,10 @@ func (s *sitesBuilder) AssertFileContentRe(filename string, matches ...string) { } } +func (s *sitesBuilder) CheckExists(filename string) bool { + return destinationExists(s.Fs, filepath.Clean(filename)) +} + type testHelper struct { Cfg config.Provider Fs *hugofs.Fs