shithub: hugo

Download patch

ref: 8aaec644a90d09bd7f079d35d382f76bb4ed35db
parent: 55c53ae9be4f8b4bcff61347cb553b7e694e9fac
author: Bjørn Erik Pedersen <[email protected]>
date: Tue Jun 6 04:09:25 EDT 2017

hugolib: Add test for no 404 in sitemap

Closes #3563

--- a/hugolib/sitemap_test.go
+++ b/hugolib/sitemap_test.go
@@ -18,6 +18,8 @@
 
 	"reflect"
 
+	"github.com/stretchr/testify/require"
+
 	"github.com/spf13/hugo/deps"
 	"github.com/spf13/hugo/tpl"
 )
@@ -47,18 +49,24 @@
 
 	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
@@ -70,6 +78,9 @@
 		// Tax list
 		"<loc>http://auth/bub/categories/hugo/</loc>",
 	)
+
+	content := readDestination(th.T, th.Fs, outputSitemap)
+	require.NotContains(t, content, "404")
 
 }