diff options
author | Bjørn Erik Pedersen <[email protected]> | 2017-01-10 10:55:03 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-02-04 11:37:25 +0700 |
commit | c71e1b106e6011d148cac899f83c4685dee33a22 (patch) | |
tree | c5c7090f0c2398c7771e4908ebcc97aa7714ffd2 /hugolib/template_test.go | |
parent | 0ada40591216572b0e4c6a8ab986b0aa4fb13c13 (diff) | |
download | hugo-c71e1b106e6011d148cac899f83c4685dee33a22.tar.gz hugo-c71e1b106e6011d148cac899f83c4685dee33a22.zip |
all: Refactor to nonglobal file systems
Updates #2701
Fixes #2951
Diffstat (limited to 'hugolib/template_test.go')
-rw-r--r-- | hugolib/template_test.go | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/hugolib/template_test.go b/hugolib/template_test.go index 20db56f8a..2690b172a 100644 --- a/hugolib/template_test.go +++ b/hugolib/template_test.go @@ -17,127 +17,133 @@ import ( "path/filepath" "testing" + "github.com/spf13/hugo/deps" + "github.com/spf13/hugo/hugofs" + "github.com/spf13/viper" ) func TestBaseGoTemplate(t *testing.T) { + + var fs *hugofs.Fs + // Variants: // 1. <current-path>/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>. // 2. <current-path>/baseof.<suffix> // 3. _default/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>. // 4. _default/baseof.<suffix> - for i, this := range []struct { + for _, this := range []struct { setup func(t *testing.T) assert func(t *testing.T) }{ { // Variant 1 func(t *testing.T) { - writeSource(t, filepath.Join("layouts", "section", "sect-baseof.html"), `Base: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("layouts", "section", "sect.html"), `{{define "main"}}sect{{ end }}`) + writeSource(t, fs, filepath.Join("layouts", "section", "sect-baseof.html"), `Base: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("layouts", "section", "sect.html"), `{{define "main"}}sect{{ end }}`) }, func(t *testing.T) { - assertFileContent(t, filepath.Join("public", "sect", "index.html"), false, "Base: sect") + assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: sect") }, }, { // Variant 2 func(t *testing.T) { - writeSource(t, filepath.Join("layouts", "baseof.html"), `Base: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("layouts", "index.html"), `{{define "main"}}index{{ end }}`) + writeSource(t, fs, filepath.Join("layouts", "baseof.html"), `Base: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("layouts", "index.html"), `{{define "main"}}index{{ end }}`) }, func(t *testing.T) { - assertFileContent(t, filepath.Join("public", "index.html"), false, "Base: index") + assertFileContent(t, fs, filepath.Join("public", "index.html"), false, "Base: index") }, }, { // Variant 3 func(t *testing.T) { - writeSource(t, filepath.Join("layouts", "_default", "list-baseof.html"), `Base: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) + writeSource(t, fs, filepath.Join("layouts", "_default", "list-baseof.html"), `Base: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) }, func(t *testing.T) { - assertFileContent(t, filepath.Join("public", "sect", "index.html"), false, "Base: list") + assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: list") }, }, { // Variant 4 func(t *testing.T) { - writeSource(t, filepath.Join("layouts", "_default", "baseof.html"), `Base: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) + writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `Base: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) }, func(t *testing.T) { - assertFileContent(t, filepath.Join("public", "sect", "index.html"), false, "Base: list") + assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: list") }, }, { // Variant 1, theme, use project's base func(t *testing.T) { viper.Set("theme", "mytheme") - writeSource(t, filepath.Join("layouts", "section", "sect-baseof.html"), `Base: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("themes", "mytheme", "layouts", "section", "sect-baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("layouts", "section", "sect.html"), `{{define "main"}}sect{{ end }}`) + writeSource(t, fs, filepath.Join("layouts", "section", "sect-baseof.html"), `Base: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "section", "sect-baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("layouts", "section", "sect.html"), `{{define "main"}}sect{{ end }}`) }, func(t *testing.T) { - assertFileContent(t, filepath.Join("public", "sect", "index.html"), false, "Base: sect") + assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: sect") }, }, { // Variant 1, theme, use theme's base func(t *testing.T) { viper.Set("theme", "mytheme") - writeSource(t, filepath.Join("themes", "mytheme", "layouts", "section", "sect-baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("layouts", "section", "sect.html"), `{{define "main"}}sect{{ end }}`) + writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "section", "sect-baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("layouts", "section", "sect.html"), `{{define "main"}}sect{{ end }}`) }, func(t *testing.T) { - assertFileContent(t, filepath.Join("public", "sect", "index.html"), false, "Base Theme: sect") + assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base Theme: sect") }, }, { // Variant 4, theme, use project's base func(t *testing.T) { viper.Set("theme", "mytheme") - writeSource(t, filepath.Join("layouts", "_default", "baseof.html"), `Base: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("themes", "mytheme", "layouts", "_default", "baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("themes", "mytheme", "layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) + writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `Base: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) }, func(t *testing.T) { - assertFileContent(t, filepath.Join("public", "sect", "index.html"), false, "Base: list") + assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base: list") }, }, { // Variant 4, theme, use themes's base func(t *testing.T) { viper.Set("theme", "mytheme") - writeSource(t, filepath.Join("themes", "mytheme", "layouts", "_default", "baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) - writeSource(t, filepath.Join("themes", "mytheme", "layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) + writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "baseof.html"), `Base Theme: {{block "main" .}}block{{end}}`) + writeSource(t, fs, filepath.Join("themes", "mytheme", "layouts", "_default", "list.html"), `{{define "main"}}list{{ end }}`) }, func(t *testing.T) { - assertFileContent(t, filepath.Join("public", "sect", "index.html"), false, "Base Theme: list") + assertFileContent(t, fs, filepath.Join("public", "sect", "index.html"), false, "Base Theme: list") }, }, } { testCommonResetState() - writeSource(t, filepath.Join("content", "sect", "page.md"), `--- + fs = hugofs.NewMem() + + writeSource(t, fs, filepath.Join("content", "sect", "page.md"), `--- title: Template test --- Some content `) this.setup(t) - if err := buildAndRenderSite(NewSiteDefaultLang()); err != nil { - t.Fatalf("[%d] Failed to build site: %s", i, err) - } + buildSingleSite(t, deps.DepsCfg{Fs: fs}, BuildCfg{}) this.assert(t) |