diff --git a/hugolib/helpers_for_test.go b/hugolib/helpers_for_test.go
deleted file mode 100644
index 7c41376a545..00000000000
--- a/hugolib/helpers_for_test.go
+++ /dev/null
@@ -1,80 +0,0 @@
-package hugolib
-
-import (
- "testing"
-
- "github.com/spf13/afero"
- "github.com/spf13/hugo/hugofs"
- "github.com/spf13/hugo/source"
- "github.com/spf13/hugo/tpl"
- "github.com/spf13/viper"
-)
-
-func siteFromByteSources(bs []source.ByteSource) *Site {
-
- viper.SetDefault("baseurl", "http://auth/bub")
- hugofs.DestinationFS = new(afero.MemMapFs)
-
- s := &Site{
- Source: &source.InMemorySource{ByteSource: bs},
- }
- s.initializeSiteInfo()
- return s
-}
-
-func buildSiteFromByteSources(bs []source.ByteSource, t *testing.T) *Site {
- s := siteFromByteSources(bs)
-
- if err := s.CreatePages(); err != nil {
- t.Fatalf("Unable to create pages: %s", err)
- }
-
- if err := s.BuildSiteMeta(); err != nil {
- t.Fatalf("Unable to build site metadata: %s", err)
- }
-
- return s
-}
-
-func setHugoDefaultTaxonomies() {
- taxonomies := make(map[string]string)
- taxonomies["tag"] = "tags"
- taxonomies["category"] = "categories"
-
- viper.Set("taxonomies", taxonomies)
-}
-
-func createAndRenderPages(t *testing.T, s *Site) {
- if err := s.CreatePages(); err != nil {
- t.Fatalf("Unable to create pages: %s", err)
- }
-
- if err := s.BuildSiteMeta(); err != nil {
- t.Fatalf("Unable to build site metadata: %s", err)
- }
-
- if err := s.RenderPages(); err != nil {
- t.Fatalf("Unable to render pages. %s", err)
- }
-}
-
-func testRenderPages(t *testing.T, s *Site) {
- if err := s.RenderPages(); err != nil {
- t.Fatalf("Unable to render pages. %s", err)
- }
-}
-
-func templatePrep(s *Site) {
- s.Tmpl = tpl.New()
- s.Tmpl.LoadTemplates(s.absLayoutDir())
- if s.hasTheme() {
- s.Tmpl.LoadTemplatesWithPrefix(s.absThemeDir()+"/layouts", "theme")
- }
-}
-
-func pageMust(p *Page, err error) *Page {
- if err != nil {
- panic(err)
- }
- return p
-}
diff --git a/hugolib/site_test.go b/hugolib/site_test.go
index 5b1bb0df240..22db1eaf2c8 100644
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -15,6 +15,7 @@ import (
"github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/target"
+ "github.com/spf13/hugo/tpl"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
@@ -49,6 +50,35 @@ more text
`
)
+func createAndRenderPages(t *testing.T, s *Site) {
+ if err := s.CreatePages(); err != nil {
+ t.Fatalf("Unable to create pages: %s", err)
+ }
+
+ if err := s.BuildSiteMeta(); err != nil {
+ t.Fatalf("Unable to build site metadata: %s", err)
+ }
+
+ if err := s.RenderPages(); err != nil {
+ t.Fatalf("Unable to render pages. %s", err)
+ }
+}
+
+func templatePrep(s *Site) {
+ s.Tmpl = tpl.New()
+ s.Tmpl.LoadTemplates(s.absLayoutDir())
+ if s.hasTheme() {
+ s.Tmpl.LoadTemplatesWithPrefix(s.absThemeDir()+"/layouts", "theme")
+ }
+}
+
+func pageMust(p *Page, err error) *Page {
+ if err != nil {
+ panic(err)
+ }
+ return p
+}
+
func TestDegenerateRenderThingMissingTemplate(t *testing.T) {
p, _ := NewPageFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
p.Convert()
@@ -197,16 +227,30 @@ func TestDraftAndFutureRender(t *testing.T) {
{filepath.FromSlash("sect/doc4.md"), []byte("---\ntitle: doc4\ndraft: false\npublishdate: \"2012-05-29\"\n---\n# doc4\n*some content*")},
}
+ siteSetup := func() *Site {
+ s := &Site{
+ Source: &source.InMemorySource{ByteSource: sources},
+ }
+
+ s.initializeSiteInfo()
+
+ if err := s.CreatePages(); err != nil {
+ t.Fatalf("Unable to create pages: %s", err)
+ }
+ return s
+ }
+
+ viper.Set("baseurl", "http://auth/bub")
+
// Testing Defaults.. Only draft:true and publishDate in the past should be rendered
- s := buildSiteFromByteSources(sources, t)
+ s := siteSetup()
if len(s.Pages) != 1 {
t.Fatal("Draft or Future dated content published unexpectedly")
}
// only publishDate in the past should be rendered
viper.Set("BuildDrafts", true)
-
- s = buildSiteFromByteSources(sources, t)
+ s = siteSetup()
if len(s.Pages) != 2 {
t.Fatal("Future Dated Posts published unexpectedly")
}
@@ -214,8 +258,7 @@ func TestDraftAndFutureRender(t *testing.T) {
// drafts should not be rendered, but all dates should
viper.Set("BuildDrafts", false)
viper.Set("BuildFuture", true)
-
- s = buildSiteFromByteSources(sources, t)
+ s = siteSetup()
if len(s.Pages) != 2 {
t.Fatal("Draft posts published unexpectedly")
}
@@ -223,11 +266,14 @@ func TestDraftAndFutureRender(t *testing.T) {
// all 4 should be included
viper.Set("BuildDrafts", true)
viper.Set("BuildFuture", true)
-
- s = buildSiteFromByteSources(sources, t)
+ s = siteSetup()
if len(s.Pages) != 4 {
t.Fatal("Drafts or Future posts not included as expected")
}
+
+ //setting defaults back
+ viper.Set("BuildDrafts", false)
+ viper.Set("BuildFuture", false)
}
// Issue #957
@@ -339,8 +385,12 @@ func doTest404ShouldAlwaysHaveUglyUrls(t *testing.T, uglyURLs bool) {
{filepath.FromSlash("sect/doc1.html"), []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")},
}
- s := buildSiteFromByteSources(sources, t)
+ s := &Site{
+ Source: &source.InMemorySource{ByteSource: sources},
+ Targets: targetList{Page: &target.PagePub{UglyURLs: uglyURLs}},
+ }
+ s.initializeSiteInfo()
templatePrep(s)
must(s.addTemplate("index.html", "Home Sweet Home"))
@@ -351,8 +401,7 @@ func doTest404ShouldAlwaysHaveUglyUrls(t *testing.T, uglyURLs bool) {
must(s.addTemplate("rss.xml", "