Skip to content

Commit

Permalink
hugolib: Add test for no 404 in sitemap
Browse files Browse the repository at this point in the history
Closes #3563
  • Loading branch information
bep committed Jun 6, 2017
1 parent 55c53ae commit 8aaec64
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions hugolib/sitemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

"reflect"

"github.com/stretchr/testify/require"

"github.com/spf13/hugo/deps"
"github.com/spf13/hugo/tpl"
)
Expand Down Expand Up @@ -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
" <loc>http://auth/bub/sect/doc1/</loc>",
// Home page
Expand All @@ -71,6 +79,9 @@ func doTestSitemapOutput(t *testing.T, internal bool) {
"<loc>http://auth/bub/categories/hugo/</loc>",
)

content := readDestination(th.T, th.Fs, outputSitemap)
require.NotContains(t, content, "404")

}

func TestParseSitemap(t *testing.T) {
Expand Down

0 comments on commit 8aaec64

Please sign in to comment.