summaryrefslogtreecommitdiffstats
path: root/hugolib/alias_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/alias_test.go
parent0ada40591216572b0e4c6a8ab986b0aa4fb13c13 (diff)
all: Refactor to nonglobal file systems
Updates #2701 Fixes #2951
Diffstat (limited to 'hugolib/alias_test.go')
-rw-r--r--hugolib/alias_test.go40
1 files changed, 25 insertions, 15 deletions
diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go
index 87bc9b130..22803d22e 100644
--- a/hugolib/alias_test.go
+++ b/hugolib/alias_test.go
@@ -16,6 +16,10 @@ package hugolib
import (
"path/filepath"
"testing"
+
+ "github.com/spf13/hugo/deps"
+ "github.com/spf13/hugo/hugofs"
+ "github.com/stretchr/testify/require"
)
const pageWithAlias = `---
@@ -30,31 +34,37 @@ const aliasTemplate = "<html><body>ALIASTEMPLATE</body></html>"
func TestAlias(t *testing.T) {
testCommonResetState()
- writeSource(t, filepath.Join("content", "page.md"), pageWithAlias)
- writeSource(t, filepath.Join("layouts", "_default", "single.html"), basicTemplate)
- if err := buildAndRenderSite(NewSiteDefaultLang()); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ fs := hugofs.NewMem()
+
+ writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias)
+ writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), basicTemplate)
+
+ buildSingleSite(t, deps.DepsCfg{Fs: fs}, BuildCfg{})
// the real page
- assertFileContent(t, filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
+ assertFileContent(t, fs, filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
// the alias redirector
- assertFileContent(t, filepath.Join("public", "foo", "bar", "index.html"), false, "<meta http-equiv=\"refresh\" content=\"0; ")
+ assertFileContent(t, fs, filepath.Join("public", "foo", "bar", "index.html"), false, "<meta http-equiv=\"refresh\" content=\"0; ")
}
func TestAliasTemplate(t *testing.T) {
testCommonResetState()
- writeSource(t, filepath.Join("content", "page.md"), pageWithAlias)
- writeSource(t, filepath.Join("layouts", "_default", "single.html"), basicTemplate)
- writeSource(t, filepath.Join("layouts", "alias.html"), aliasTemplate)
- if err := buildAndRenderSite(NewSiteDefaultLang()); err != nil {
- t.Fatalf("Failed to build site: %s", err)
- }
+ fs := hugofs.NewMem()
+
+ writeSource(t, fs, filepath.Join("content", "page.md"), pageWithAlias)
+ writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), basicTemplate)
+ writeSource(t, fs, filepath.Join("layouts", "alias.html"), aliasTemplate)
+
+ sites, err := NewHugoSitesFromConfiguration(deps.DepsCfg{Fs: fs})
+
+ require.NoError(t, err)
+
+ require.NoError(t, sites.Build(BuildCfg{}))
// the real page
- assertFileContent(t, filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
+ assertFileContent(t, fs, filepath.Join("public", "page", "index.html"), false, "For some moments the old man")
// the alias redirector
- assertFileContent(t, filepath.Join("public", "foo", "bar", "index.html"), false, "ALIASTEMPLATE")
+ assertFileContent(t, fs, filepath.Join("public", "foo", "bar", "index.html"), false, "ALIASTEMPLATE")
}