summaryrefslogtreecommitdiffstats
path: root/hugolib/node_as_page_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-01-10 10:55:03 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-04 11:37:25 +0700
commitc71e1b106e6011d148cac899f83c4685dee33a22 (patch)
treec5c7090f0c2398c7771e4908ebcc97aa7714ffd2 /hugolib/node_as_page_test.go
parent0ada40591216572b0e4c6a8ab986b0aa4fb13c13 (diff)
all: Refactor to nonglobal file systems
Updates #2701 Fixes #2951
Diffstat (limited to 'hugolib/node_as_page_test.go')
-rw-r--r--hugolib/node_as_page_test.go341
1 files changed, 184 insertions, 157 deletions
diff --git a/hugolib/node_as_page_test.go b/hugolib/node_as_page_test.go
index d661fe885..35588da4d 100644
--- a/hugolib/node_as_page_test.go
+++ b/hugolib/node_as_page_test.go
@@ -18,8 +18,11 @@ import (
"path/filepath"
"strings"
"testing"
+
"time"
+ "github.com/spf13/hugo/deps"
+ "github.com/spf13/hugo/hugofs"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
@@ -56,24 +59,28 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
viper.Set("uglyURLs", ugly)
viper.Set("preserveTaxonomyNames", preserveTaxonomyNames)
- writeLayoutsForNodeAsPageTests(t)
- writeNodePagesForNodeAsPageTests("", t)
-
- writeRegularPagesForNodeAsPageTests(t)
-
viper.Set("paginate", 1)
viper.Set("title", "Hugo Rocks")
viper.Set("rssURI", "customrss.xml")
- s := NewSiteDefaultLang()
+ depsCfg := newTestDepsConfig()
- if err := buildAndRenderSite(s); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ viper.SetFs(depsCfg.Fs.Source)
+
+ writeLayoutsForNodeAsPageTests(t, depsCfg.Fs)
+ writeNodePagesForNodeAsPageTests(t, depsCfg.Fs, "")
+
+ writeRegularPagesForNodeAsPageTests(t, depsCfg.Fs)
+
+ sites, err := NewHugoSitesFromConfiguration(depsCfg)
+
+ require.NoError(t, err)
+
+ require.NoError(t, sites.Build(BuildCfg{}))
// date order: home, sect1, sect2, cat/hugo, cat/web, categories
- assertFileContent(t, filepath.Join("public", "index.html"), false,
+ assertFileContent(t, depsCfg.Fs, filepath.Join("public", "index.html"), false,
"Index Title: Home Sweet Home!",
"Home <strong>Content!</strong>",
"# Pages: 4",
@@ -82,10 +89,9 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
"GetPage: Section1 ",
)
- assertFileContent(t, expectedFilePath(ugly, "public", "sect1", "regular1"), false, "Single Title: Page 01", "Content Page 01")
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "sect1", "regular1"), false, "Single Title: Page 01", "Content Page 01")
- h := s.owner
- nodes := h.findAllPagesByKindNotIn(KindPage)
+ nodes := sites.findAllPagesByKindNotIn(KindPage)
require.Len(t, nodes, 7)
@@ -99,7 +105,7 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
section2 := nodes[4]
require.Equal(t, "Section2", section2.Title)
- pages := h.findAllPagesByKind(KindPage)
+ pages := sites.findAllPagesByKind(KindPage)
require.Len(t, pages, 4)
first := pages[0]
@@ -109,46 +115,48 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
require.True(t, first.IsPage())
// Check Home paginator
- assertFileContent(t, expectedFilePath(ugly, "public", "page", "2"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "page", "2"), false,
"Pag: Page 02")
// Check Sections
- assertFileContent(t, expectedFilePath(ugly, "public", "sect1"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "sect1"), false,
"Section Title: Section", "Section1 <strong>Content!</strong>",
"Date: 2009-01-04",
"Lastmod: 2009-01-05",
)
- assertFileContent(t, expectedFilePath(ugly, "public", "sect2"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "sect2"), false,
"Section Title: Section", "Section2 <strong>Content!</strong>",
"Date: 2009-01-06",
"Lastmod: 2009-01-07",
)
// Check Sections paginator
- assertFileContent(t, expectedFilePath(ugly, "public", "sect1", "page", "2"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "sect1", "page", "2"), false,
"Pag: Page 02")
- sections := h.findAllPagesByKind(KindSection)
+ sections := sites.findAllPagesByKind(KindSection)
require.Len(t, sections, 2)
// Check taxonomy lists
- assertFileContent(t, expectedFilePath(ugly, "public", "categories", "hugo"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "categories", "hugo"), false,
"Taxonomy Title: Taxonomy Hugo", "Taxonomy Hugo <strong>Content!</strong>",
"Date: 2009-01-08",
"Lastmod: 2009-01-09",
)
- assertFileContent(t, expectedFilePath(ugly, "public", "categories", "hugo-rocks"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "categories", "hugo-rocks"), false,
"Taxonomy Title: Taxonomy Hugo Rocks",
)
+ s := sites.Sites[0]
+
web := s.getPage(KindTaxonomy, "categories", "web")
require.NotNil(t, web)
require.Len(t, web.Data["Pages"].(Pages), 4)
- assertFileContent(t, expectedFilePath(ugly, "public", "categories", "web"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "categories", "web"), false,
"Taxonomy Title: Taxonomy Web",
"Taxonomy Web <strong>Content!</strong>",
"Date: 2009-01-10",
@@ -156,12 +164,12 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
)
// Check taxonomy list paginator
- assertFileContent(t, expectedFilePath(ugly, "public", "categories", "hugo", "page", "2"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "categories", "hugo", "page", "2"), false,
"Taxonomy Title: Taxonomy Hugo",
"Pag: Page 02")
// Check taxonomy terms
- assertFileContent(t, expectedFilePath(ugly, "public", "categories"), false,
+ assertFileContent(t, depsCfg.Fs, expectedFilePath(ugly, "public", "categories"), false,
"Taxonomy Terms Title: Taxonomy Term Categories", "Taxonomy Term Categories <strong>Content!</strong>", "k/v: hugo",
"Date: 2009-01-14",
"Lastmod: 2009-01-15",
@@ -170,11 +178,11 @@ func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
// There are no pages to paginate over in the taxonomy terms.
// RSS
- assertFileContent(t, filepath.Join("public", "customrss.xml"), false, "Recent content in Home Sweet Home! on Hugo Rocks", "<rss")
- assertFileContent(t, filepath.Join("public", "sect1", "customrss.xml"), false, "Recent content in Section1 on Hugo Rocks", "<rss")
- assertFileContent(t, filepath.Join("public", "sect2", "customrss.xml"), false, "Recent content in Section2 on Hugo Rocks", "<rss")
- assertFileContent(t, filepath.Join("public", "categories", "hugo", "customrss.xml"), false, "Recent content in Taxonomy Hugo on Hugo Rocks", "<rss")
- assertFileContent(t, filepath.Join("public", "categories", "web", "customrss.xml"), false, "Recent content in Taxonomy Web on Hugo Rocks", "<rss")
+ assertFileContent(t, depsCfg.Fs, filepath.Join("public", "customrss.xml"), false, "Recent content in Home Sweet Home! on Hugo Rocks", "<rss")
+ assertFileContent(t, depsCfg.Fs, filepath.Join("public", "sect1", "customrss.xml"), false, "Recent content in Section1 on Hugo Rocks", "<rss")
+ assertFileContent(t, depsCfg.Fs, filepath.Join("public", "sect2", "customrss.xml"), false, "Recent content in Section2 on Hugo Rocks", "<rss")
+ assertFileContent(t, depsCfg.Fs, filepath.Join("public", "categories", "hugo", "customrss.xml"), false, "Recent content in Taxonomy Hugo on Hugo Rocks", "<rss")
+ assertFileContent(t, depsCfg.Fs, filepath.Join("public", "categories", "web", "customrss.xml"), false, "Recent content in Taxonomy Web on Hugo Rocks", "<rss")
}
@@ -187,19 +195,23 @@ func TestNodesWithNoContentFile(t *testing.T) {
func doTestNodesWithNoContentFile(t *testing.T, ugly bool) {
testCommonResetState()
- writeLayoutsForNodeAsPageTests(t)
- writeRegularPagesForNodeAsPageTests(t)
-
viper.Set("uglyURLs", ugly)
viper.Set("paginate", 1)
viper.Set("title", "Hugo Rocks!")
viper.Set("rssURI", "customrss.xml")
- s := NewSiteDefaultLang()
+ fs := hugofs.NewMem()
- if err := buildAndRenderSite(s); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ writeLayoutsForNodeAsPageTests(t, fs)
+ writeRegularPagesForNodeAsPageTests(t, fs)
+
+ sites, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
+
+ require.NoError(t, err)
+
+ require.NoError(t, sites.Build(BuildCfg{}))
+
+ s := sites.Sites[0]
// Home page
homePages := s.findPagesByKind(KindHome)
@@ -210,21 +222,21 @@ func doTestNodesWithNoContentFile(t *testing.T, ugly bool) {
require.Len(t, homePage.Pages, 4)
require.True(t, homePage.Path() == "")
- assertFileContent(t, filepath.Join("public", "index.html"), false,
+ assertFileContent(t, fs, filepath.Join("public", "index.html"), false,
"Index Title: Hugo Rocks!",
"Date: 2010-06-12",
"Lastmod: 2010-06-13",
)
// Taxonomy list
- assertFileContent(t, expectedFilePath(ugly, "public", "categories", "hugo"), false,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories", "hugo"), false,
"Taxonomy Title: Hugo",
"Date: 2010-06-12",
"Lastmod: 2010-06-13",
)
// Taxonomy terms
- assertFileContent(t, expectedFilePath(ugly, "public", "categories"), false,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "categories"), false,
"Taxonomy Terms Title: Categories",
)
@@ -232,9 +244,9 @@ func doTestNodesWithNoContentFile(t *testing.T, ugly bool) {
for _, p := range pages {
var want string
if ugly {
- want = "/" + p.Site.pathSpec.URLize(p.Title) + ".html"
+ want = "/" + p.s.PathSpec.URLize(p.Title) + ".html"
} else {
- want = "/" + p.Site.pathSpec.URLize(p.Title) + "/"
+ want = "/" + p.s.PathSpec.URLize(p.Title) + "/"
}
if p.URL() != want {
t.Errorf("Taxonomy term URL mismatch: want %q, got %q", want, p.URL())
@@ -242,29 +254,29 @@ func doTestNodesWithNoContentFile(t *testing.T, ugly bool) {
}
// Sections
- assertFileContent(t, expectedFilePath(ugly, "public", "sect1"), false,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "sect1"), false,
"Section Title: Sect1s",
"Date: 2010-06-12",
"Lastmod: 2010-06-13",
)
- assertFileContent(t, expectedFilePath(ugly, "public", "sect2"), false,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "sect2"), false,
"Section Title: Sect2s",
"Date: 2008-07-06",
"Lastmod: 2008-07-09",
)
// RSS
- assertFileContent(t, filepath.Join("public", "customrss.xml"), false, "Hugo Rocks!", "<rss")
- assertFileContent(t, filepath.Join("public", "sect1", "customrss.xml"), false, "Recent content in Sect1s on Hugo Rocks!", "<rss")
- assertFileContent(t, filepath.Join("public", "sect2", "customrss.xml"), false, "Recent content in Sect2s on Hugo Rocks!", "<rss")
- assertFileContent(t, filepath.Join("public", "categories", "hugo", "customrss.xml"), false, "Recent content in Hugo on Hugo Rocks!", "<rss")
- assertFileContent(t, filepath.Join("public", "categories", "web", "customrss.xml"), false, "Recent content in Web on Hugo Rocks!", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "customrss.xml"), false, "Hugo Rocks!", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "sect1", "customrss.xml"), false, "Recent content in Sect1s on Hugo Rocks!", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "sect2", "customrss.xml"), false, "Recent content in Sect2s on Hugo Rocks!", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", "customrss.xml"), false, "Recent content in Hugo on Hugo Rocks!", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "categories", "web", "customrss.xml"), false, "Recent content in Web on Hugo Rocks!", "<rss")
}
func TestNodesAsPageMultilingual(t *testing.T) {
- for _, ugly := range []bool{true, false} {
+ for _, ugly := range []bool{false, true} {
doTestNodesAsPageMultilingual(t, ugly)
}
}
@@ -273,11 +285,13 @@ func doTestNodesAsPageMultilingual(t *testing.T, ugly bool) {
testCommonResetState()
+ fs := hugofs.NewMem()
+
viper.Set("uglyURLs", ugly)
- writeLayoutsForNodeAsPageTests(t)
+ viper.SetFs(fs.Source)
- writeSource(t, "config.toml",
+ writeSource(t, fs, "config.toml",
`
paginage = 1
title = "Hugo Multilingual Rocks!"
@@ -303,19 +317,17 @@ weight = 3
title = "Deutsche Hugo"
`)
+ writeLayoutsForNodeAsPageTests(t, fs)
+
for _, lang := range []string{"nn", "en"} {
- writeRegularPagesForNodeAsPageTestsWithLang(t, lang)
+ writeRegularPagesForNodeAsPageTestsWithLang(t, fs, lang)
}
- // Only write node pages for the English and Deutsch
- writeNodePagesForNodeAsPageTests("en", t)
- writeNodePagesForNodeAsPageTests("de", t)
-
if err := LoadGlobalConfig("", "config.toml"); err != nil {
t.Fatalf("Failed to load config: %s", err)
}
- sites, err := NewHugoSitesFromConfiguration(DepsCfg{})
+ sites, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
if err != nil {
t.Fatalf("Failed to create sites: %s", err)
@@ -325,6 +337,10 @@ title = "Deutsche Hugo"
t.Fatalf("Got %d sites", len(sites.Sites))
}
+ // Only write node pages for the English and Deutsch
+ writeNodePagesForNodeAsPageTests(t, fs, "en")
+ writeNodePagesForNodeAsPageTests(t, fs, "de")
+
err = sites.Build(BuildCfg{})
if err != nil {
@@ -356,92 +372,99 @@ title = "Deutsche Hugo"
require.Equal(t, expetedPermalink(ugly, "/en/sect1/"), enSect.Permalink())
- assertFileContent(t, filepath.Join("public", "nn", "index.html"), true,
+ assertFileContent(t, fs, filepath.Join("public", "nn", "index.html"), true,
"Index Title: Hugo på norsk")
- assertFileContent(t, filepath.Join("public", "en", "index.html"), true,
+ assertFileContent(t, fs, filepath.Join("public", "en", "index.html"), true,
"Index Title: Home Sweet Home!", "<strong>Content!</strong>")
- assertFileContent(t, filepath.Join("public", "de", "index.html"), true,
+ assertFileContent(t, fs, filepath.Join("public", "de", "index.html"), true,
"Index Title: Home Sweet Home!", "<strong>Content!</strong>")
// Taxonomy list
- assertFileContent(t, expectedFilePath(ugly, "public", "nn", "categories", "hugo"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "categories", "hugo"), true,
"Taxonomy Title: Hugo")
- assertFileContent(t, expectedFilePath(ugly, "public", "en", "categories", "hugo"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "categories", "hugo"), true,
"Taxonomy Title: Taxonomy Hugo")
// Taxonomy terms
- assertFileContent(t, expectedFilePath(ugly, "public", "nn", "categories"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "categories"), true,
"Taxonomy Terms Title: Categories")
- assertFileContent(t, expectedFilePath(ugly, "public", "en", "categories"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "categories"), true,
"Taxonomy Terms Title: Taxonomy Term Categories")
// Sections
- assertFileContent(t, expectedFilePath(ugly, "public", "nn", "sect1"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "sect1"), true,
"Section Title: Sect1s")
- assertFileContent(t, expectedFilePath(ugly, "public", "nn", "sect2"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "sect2"), true,
"Section Title: Sect2s")
- assertFileContent(t, expectedFilePath(ugly, "public", "en", "sect1"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "sect1"), true,
"Section Title: Section1")
- assertFileContent(t, expectedFilePath(ugly, "public", "en", "sect2"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "sect2"), true,
"Section Title: Section2")
// Regular pages
- assertFileContent(t, expectedFilePath(ugly, "public", "en", "sect1", "regular1"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "en", "sect1", "regular1"), true,
"Single Title: Page 01")
- assertFileContent(t, expectedFilePath(ugly, "public", "nn", "sect1", "regular2"), true,
+ assertFileContent(t, fs, expectedFilePath(ugly, "public", "nn", "sect1", "regular2"), true,
"Single Title: Page 02")
// RSS
- assertFileContent(t, filepath.Join("public", "nn", "customrss.xml"), true, "Hugo på norsk", "<rss")
- assertFileContent(t, filepath.Join("public", "nn", "sect1", "customrss.xml"), true, "Recent content in Sect1s on Hugo på norsk", "<rss")
- assertFileContent(t, filepath.Join("public", "nn", "sect2", "customrss.xml"), true, "Recent content in Sect2s on Hugo på norsk", "<rss")
- assertFileContent(t, filepath.Join("public", "nn", "categories", "hugo", "customrss.xml"), true, "Recent content in Hugo on Hugo på norsk", "<rss")
- assertFileContent(t, filepath.Join("public", "nn", "categories", "web", "customrss.xml"), true, "Recent content in Web on Hugo på norsk", "<rss")
-
- assertFileContent(t, filepath.Join("public", "en", "customrss.xml"), true, "Recent content in Home Sweet Home! on Hugo in English", "<rss")
- assertFileContent(t, filepath.Join("public", "en", "sect1", "customrss.xml"), true, "Recent content in Section1 on Hugo in English", "<rss")
- assertFileContent(t, filepath.Join("public", "en", "sect2", "customrss.xml"), true, "Recent content in Section2 on Hugo in English", "<rss")
- assertFileContent(t, filepath.Join("public", "en", "categories", "hugo", "customrss.xml"), true, "Recent content in Taxonomy Hugo on Hugo in English", "<rss")
- assertFileContent(t, filepath.Join("public", "en", "categories", "web", "customrss.xml"), true, "Recent content in Taxonomy Web on Hugo in English", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "nn", "customrss.xml"), true, "Hugo på norsk", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "nn", "sect1", "customrss.xml"), true, "Recent content in Sect1s on Hugo på norsk", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "nn", "sect2", "customrss.xml"), true, "Recent content in Sect2s on Hugo på norsk", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "nn", "categories", "hugo", "customrss.xml"), true, "Recent content in Hugo on Hugo på norsk", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "nn", "categories", "web", "customrss.xml"), true, "Recent content in Web on Hugo på norsk", "<rss")
+
+ assertFileContent(t, fs, filepath.Join("public", "en", "customrss.xml"), true, "Recent content in Home Sweet Home! on Hugo in English", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "en", "sect1", "customrss.xml"), true, "Recent content in Section1 on Hugo in English", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "en", "sect2", "customrss.xml"), true, "Recent content in Section2 on Hugo in English", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "en", "categories", "hugo", "customrss.xml"), true, "Recent content in Taxonomy Hugo on Hugo in English", "<rss")
+ assertFileContent(t, fs, filepath.Join("public", "en", "categories", "web", "customrss.xml"), true, "Recent content in Taxonomy Web on Hugo in English", "<rss")
}
func TestNodesWithTaxonomies(t *testing.T) {
testCommonResetState()
- writeLayoutsForNodeAsPageTests(t)
- writeRegularPagesForNodeAsPageTests(t)
+ fs := hugofs.NewMem()
+
+ viper.Set("paginate", 1)
+ viper.Set("title", "Hugo Rocks!")
- writeSource(t, filepath.Join("content", "_index.md"), `---
+ writeLayoutsForNodeAsPageTests(t, fs)
+ writeRegularPagesForNodeAsPageTests(t, fs)
+
+ writeSource(t, fs, filepath.Join("content", "_index.md"), `---
title: Home With Taxonomies
categories: [
- "Hugo",
+ "Hugo",
"Home"
]
---
`)
- viper.Set("paginate", 1)
- viper.Set("title", "Hugo Rocks!")
+ h, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
- s := NewSiteDefaultLang()
+ require.NoError(t, err)
- if err := buildAndRenderSite(s); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ require.NoError(t, h.Build(BuildCfg{}))
- assertFileContent(t, filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy Title: Hugo", "# Pages: 5")
- assertFileContent(t, filepath.Join("public", "categories", "home", "index.html"), true, "Taxonomy Title: Home", "# Pages: 1")
+ assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy Title: Hugo", "# Pages: 5")
+ assertFileContent(t, fs, filepath.Join("public", "categories", "home", "index.html"), true, "Taxonomy Title: Home", "# Pages: 1")
}
func TestNodesWithMenu(t *testing.T) {
testCommonResetState()
- writeLayoutsForNodeAsPageTests(t)
- writeRegularPagesForNodeAsPageTests(t)
+ viper.Set("paginate", 1)
+ viper.Set("title", "Hugo Rocks!")
+
+ fs := hugofs.NewMem()
- writeSource(t, filepath.Join("content", "_index.md"), `---
+ writeLayoutsForNodeAsPageTests(t, fs)
+ writeRegularPagesForNodeAsPageTests(t, fs)
+
+ writeSource(t, fs, filepath.Join("content", "_index.md"), `---
title: Home With Menu
menu:
mymenu:
@@ -449,7 +472,7 @@ menu:
---
`)
- writeSource(t, filepath.Join("content", "sect1", "_index.md"), `---
+ writeSource(t, fs, filepath.Join("content", "sect1", "_index.md"), `---
title: Sect1 With Menu
menu:
mymenu:
@@ -457,7 +480,7 @@ menu:
---
`)
- writeSource(t, filepath.Join("content", "categories", "hugo", "_index.md"), `---
+ writeSource(t, fs, filepath.Join("content", "categories", "hugo", "_index.md"), `---
title: Taxonomy With Menu
menu:
mymenu:
@@ -465,98 +488,102 @@ menu:
---
`)
- viper.Set("paginate", 1)
- viper.Set("title", "Hugo Rocks!")
+ h, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
- s := NewSiteDefaultLang()
+ require.NoError(t, err)
- if err := buildAndRenderSite(s); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ require.NoError(t, h.Build(BuildCfg{}))
- assertFileContent(t, filepath.Join("public", "index.html"), true, "Home With Menu", "Home Menu Item: Go Home!: /")
- assertFileContent(t, filepath.Join("public", "sect1", "index.html"), true, "Sect1 With Menu", "Section Menu Item: Go Sect1!: /sect1/")
- assertFileContent(t, filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy With Menu", "Taxonomy Menu Item: Go Tax Hugo!: /categories/hugo/")
+ assertFileContent(t, fs, filepath.Join("public", "index.html"), true, "Home With Menu", "Home Menu Item: Go Home!: /")
+ assertFileContent(t, fs, filepath.Join("public", "sect1", "index.html"), true, "Sect1 With Menu", "Section Menu Item: Go Sect1!: /sect1/")
+ assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", "index.html"), true, "Taxonomy With Menu", "Taxonomy Menu Item: Go Tax Hugo!: /categories/hugo/")
}
func TestNodesWithAlias(t *testing.T) {
testCommonResetState()
- writeLayoutsForNodeAsPageTests(t)
- writeRegularPagesForNodeAsPageTests(t)
+ fs := hugofs.NewMem()
+
+ viper.Set("paginate", 1)
+ viper.Set("baseURL", "http://base/")
+ viper.Set("title", "Hugo Rocks!")
+
+ writeLayoutsForNodeAsPageTests(t, fs)
+ writeRegularPagesForNodeAsPageTests(t, fs)
- writeSource(t, filepath.Join("content", "_index.md"), `---
+ writeSource(t, fs, filepath.Join("content", "_index.md"), `---
title: Home With Alias
aliases:
- /my/new/home.html
---
`)
- viper.Set("paginate", 1)
- viper.Set("baseURL", "http://base/")
- viper.Set("title", "Hugo Rocks!")
+ h, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
- s := NewSiteDefaultLang()
+ require.NoError(t, err)
- if err := buildAndRenderSite(s); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ require.NoError(t, h.Build(BuildCfg{}))
- assertFileContent(t, filepath.Join("public", "index.html"), true, "Home With Alias")
- assertFileContent(t, filepath.Join("public", "my", "new", "home.html"), true, "content=\"0; url=http://base/")
+ assertFileContent(t, fs, filepath.Join("public", "index.html"), true, "Home With Alias")
+ assertFileContent(t, fs, filepath.Join("public", "my", "new", "home.html"), true, "content=\"0; url=http://base/")
}
func TestNodesWithSectionWithIndexPageOnly(t *testing.T) {
testCommonResetState()
- writeLayoutsForNodeAsPageTests(t)
+ fs := hugofs.NewMem()
- writeSource(t, filepath.Join("content", "sect", "_index.md"), `---
+ viper.Set("paginate", 1)
+ viper.Set("title", "Hugo Rocks!")
+
+ writeLayoutsForNodeAsPageTests(t, fs)
+
+ writeSource(t, fs, filepath.Join("content", "sect", "_index.md"), `---
title: MySection
---
My Section Content
`)
- viper.Set("paginate", 1)
- viper.Set("title", "Hugo Rocks!")
+ h, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
- s := NewSiteDefaultLang()
+ require.NoError(t, err)
- if err := buildAndRenderSite(s); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ require.NoError(t, h.Build(BuildCfg{}))
- assertFileContent(t, filepath.Join("public", "sect", "index.html"), true, "My Section")
+ assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), true, "My Section")
}
func TestNodesWithURLs(t *testing.T) {
testCommonResetState()
- writeLayoutsForNodeAsPageTests(t)
+ fs := hugofs.NewMem()
- writeRegularPagesForNodeAsPageTests(t)
+ viper.Set("paginate", 1)
+ viper.Set("title", "Hugo Rocks!")
+ viper.Set("baseURL", "http://bep.is/base/")
+
+ writeLayoutsForNodeAsPageTests(t, fs)
+ writeRegularPagesForNodeAsPageTests(t, fs)
- writeSource(t, filepath.Join("content", "sect", "_index.md"), `---
+ writeSource(t, fs, filepath.Join("content", "sect", "_index.md"), `---
title: MySection
url: foo.html
---
My Section Content
`)
- viper.Set("paginate", 1)
- viper.Set("title", "Hugo Rocks!")
- viper.Set("baseURL", "http://bep.is/base/")
+ h, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
- s := NewSiteDefaultLang()
+ require.NoError(t, err)
- if err := buildAndRenderSite(s); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ require.NoError(t, h.Build(BuildCfg{}))
+
+ assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), true, "My Section")
- assertFileContent(t, filepath.Join("public", "sect", "index.html"), true, "My Section")
+ s := h.Sites[0]
p := s.RegularPages[0]
@@ -573,11 +600,11 @@ My Section Content
}
-func writeRegularPagesForNodeAsPageTests(t *testing.T) {
- writeRegularPagesForNodeAsPageTestsWithLang(t, "")
+func writeRegularPagesForNodeAsPageTests(t *testing.T, fs *hugofs.Fs) {
+ writeRegularPagesForNodeAsPageTestsWithLang(t, fs, "")
}
-func writeRegularPagesForNodeAsPageTestsWithLang(t *testing.T, lang string) {
+func writeRegularPagesForNodeAsPageTestsWithLang(t *testing.T, fs *hugofs.Fs, lang string) {
var langStr string
if lang != "" {
@@ -597,7 +624,7 @@ func writeRegularPagesForNodeAsPageTestsWithLang(t *testing.T, lang string) {
}
date = date.Add(-24 * time.Duration(i) * time.Hour)
- writeSource(t, filepath.Join("content", sect, fmt.Sprintf("regular%d.%smd", i, langStr)), fmt.Sprintf(`---
+ writeSource(t, fs, filepath.Join("content", sect, fmt.Sprintf("regular%d.%smd", i, langStr)), fmt.Sprintf(`---
title: Page %02d
lastMod : %q
date : %q
@@ -612,7 +639,7 @@ Content Page %02d
}
}
-func writeNodePagesForNodeAsPageTests(lang string, t *testing.T) {
+func writeNodePagesForNodeAsPageTests(t *testing.T, fs *hugofs.Fs, lang string) {
filename := "_index.md"
@@ -624,7 +651,7 @@ func writeNodePagesForNodeAsPageTests(lang string, t *testing.T) {
date, _ := time.Parse(format, "2009-01-01")
- writeSource(t, filepath.Join("content", filename), fmt.Sprintf(`---
+ writeSource(t, fs, filepath.Join("content", filename), fmt.Sprintf(`---
title: Home Sweet Home!
date : %q
lastMod : %q
@@ -632,14 +659,14 @@ lastMod : %q
l-%s Home **Content!**
`, date.Add(1*24*time.Hour).Format(time.RFC822), date.Add(2*24*time.Hour).Format(time.RFC822), lang))
- writeSource(t, filepath.Join("content", "sect1", filename), fmt.Sprintf(`---
+ writeSource(t, fs, filepath.Join("content", "sect1", filename), fmt.Sprintf(`---
title: Section1
date : %q
lastMod : %q
---
Section1 **Content!**
`, date.Add(3*24*time.Hour).Format(time.RFC822), date.Add(4*24*time.Hour).Format(time.RFC822)))
- writeSource(t, filepath.Join("content", "sect2", filename), fmt.Sprintf(`---
+ writeSource(t, fs, filepath.Join("content", "sect2", filename), fmt.Sprintf(`---
title: Section2
date : %q
lastMod : %q
@@ -647,7 +674,7 @@ lastMod : %q
Section2 **Content!**
`, date.Add(5*24*time.Hour).Format(time.RFC822), date.Add(6*24*time.Hour).Format(time.RFC822)))
- writeSource(t, filepath.Join("content", "categories", "hugo", filename), fmt.Sprintf(`---
+ writeSource(t, fs, filepath.Join("content", "categories", "hugo", filename), fmt.Sprintf(`---
title: Taxonomy Hugo
date : %q
lastMod : %q
@@ -655,7 +682,7 @@ lastMod : %q
Taxonomy Hugo **Content!**
`, date.Add(7*24*time.Hour).Format(time.RFC822), date.Add(8*24*time.Hour).Format(time.RFC822)))
- writeSource(t, filepath.Join("content", "categories", "web", filename), fmt.Sprintf(`---
+ writeSource(t, fs, filepath.Join("content", "categories", "web", filename), fmt.Sprintf(`---
title: Taxonomy Web
date : %q
lastMod : %q
@@ -663,7 +690,7 @@ lastMod : %q
Taxonomy Web **Content!**
`, date.Add(9*24*time.Hour).Format(time.RFC822), date.Add(10*24*time.Hour).Format(time.RFC822)))
- writeSource(t, filepath.Join("content", "categories", "hugo-rocks", filename), fmt.Sprintf(`---
+ writeSource(t, fs, filepath.Join("content", "categories", "hugo-rocks", filename), fmt.Sprintf(`---
title: Taxonomy Hugo Rocks
date : %q
lastMod : %q
@@ -671,7 +698,7 @@ lastMod : %q
Taxonomy Hugo Rocks **Content!**
`, date.Add(11*24*time.Hour).Format(time.RFC822), date.Add(12*24*time.Hour).Format(time.RFC822)))
- writeSource(t, filepath.Join("content", "categories", filename), fmt.Sprintf(`---
+ writeSource(t, fs, filepath.Join("content", "categories", filename), fmt.Sprintf(`---
title: Taxonomy Term Categories
date : %q
lastMod : %q
@@ -681,8 +708,8 @@ Taxonomy Term Categories **Content!**
}
-func writeLayoutsForNodeAsPageTests(t *testing.T) {
- writeSource(t, filepath.Join("layouts", "index.html"), `
+func writeLayoutsForNodeAsPageTests(t *testing.T, fs *hugofs.Fs) {
+ writeSource(t, fs, filepath.Join("layouts", "index.html"), `
Index Title: {{ .Title }}
Index Content: {{ .Content }}
# Pages: {{ len .Data.Pages }}
@@ -699,14 +726,14 @@ Lastmod: {{ .Lastmod.Format "2006-01-02" }}
GetPage: {{ with .Site.GetPage "section" "sect1" }}{{ .Title }}{{ end }}
`)
- writeSource(t, filepath.Join("layouts", "_default", "single.html"), `
+ writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), `
Single Title: {{ .Title }}
Single Content: {{ .Content }}
Date: {{ .Date.Format "2006-01-02" }}
Lastmod: {{ .Lastmod.Format "2006-01-02" }}
`)
- writeSource(t, filepath.Join("layouts", "_default", "section.html"), `
+ writeSource(t, fs, filepath.Join("layouts", "_default", "section.html"), `
Section Title: {{ .Title }}
Section Content: {{ .Content }}
# Pages: {{ len .Data.Pages }}
@@ -723,7 +750,7 @@ Lastmod: {{ .Lastmod.Format "2006-01-02" }}
`)
// Taxonomy lists
- writeSource(t, filepath.Join("layouts", "_default", "taxonomy.html"), `
+ writeSource(t, fs, filepath.Join("layouts", "_default", "taxonomy.html"), `
Taxonomy Title: {{ .Title }}
Taxonomy Content: {{ .Content }}
# Pages: {{ len .Data.Pages }}
@@ -740,7 +767,7 @@ Lastmod: {{ .Lastmod.Format "2006-01-02" }}
`)
// Taxonomy terms
- writeSource(t, filepath.Join("layouts", "_default", "terms.html"), `
+ writeSource(t, fs, filepath.Join("layouts", "_default", "terms.html"), `
Taxonomy Terms Title: {{ .Title }}
Taxonomy Terms Content: {{ .Content }}
{{ range $key, $value := .Data.Terms }}