From 8aaec644a90d09bd7f079d35d382f76bb4ed35db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 6 Jun 2017 08:09:25 +0200 Subject: [PATCH] hugolib: Add test for no 404 in sitemap Closes #3563 --- hugolib/sitemap_test.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/hugolib/sitemap_test.go b/hugolib/sitemap_test.go index 47f29c94774..a59d097569e 100644 --- a/hugolib/sitemap_test.go +++ b/hugolib/sitemap_test.go @@ -18,6 +18,8 @@ import ( "reflect" + "github.com/stretchr/testify/require" + "github.com/spf13/hugo/deps" "github.com/spf13/hugo/tpl" ) @@ -47,18 +49,24 @@ func doTestSitemapOutput(t *testing.T, internal bool) { depsCfg := deps.DepsCfg{Fs: fs, Cfg: cfg} - if !internal { - depsCfg.WithTemplate = func(templ tpl.TemplateHandler) error { + depsCfg.WithTemplate = func(templ tpl.TemplateHandler) error { + if !internal { templ.AddTemplate("sitemap.xml", sitemapTemplate) - return nil } + + // We want to check that the 404 page is not included in the sitemap + // output. This template should have no effect either way, but include + // it for the clarity. + templ.AddTemplate("404.html", "Not found") + return nil } writeSourcesToSource(t, "content", fs, weightedSources...) s := buildSingleSite(t, depsCfg, BuildCfg{}) th := testHelper{s.Cfg, s.Fs, t} + outputSitemap := "public/sitemap.xml" - th.assertFileContent("public/sitemap.xml", + th.assertFileContent(outputSitemap, // Regular page " http://auth/bub/sect/doc1/", // Home page @@ -71,6 +79,9 @@ func doTestSitemapOutput(t *testing.T, internal bool) { "http://auth/bub/categories/hugo/", ) + content := readDestination(th.T, th.Fs, outputSitemap) + require.NotContains(t, content, "404") + } func TestParseSitemap(t *testing.T) {