summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-15 10:00:34 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-15 10:00:34 +0100
commit691156c5baf81dc16a41856c4eaa814b3262a02e (patch)
treec6eab276ba3ee3f1aaa60ad855a2d776556ac8e8 /tpl
parenta988d3cf3631e07c7d2bf5bb9eb9be21ee21fd04 (diff)
Use OS fs by default
Fixes #3032
Diffstat (limited to 'tpl')
-rw-r--r--tpl/template_funcs_test.go36
-rw-r--r--tpl/template_test.go19
2 files changed, 32 insertions, 23 deletions
diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go
index bbe31216b..e4af75b30 100644
--- a/tpl/template_funcs_test.go
+++ b/tpl/template_funcs_test.go
@@ -50,13 +50,17 @@ import (
)
var (
- logger = jww.NewNotepad(jww.LevelFatal, jww.LevelFatal, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime)
- defaultDepsConfig = deps.DepsCfg{
+ logger = jww.NewNotepad(jww.LevelFatal, jww.LevelFatal, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime)
+)
+
+func newDefaultDepsCfg() deps.DepsCfg {
+ return deps.DepsCfg{
Language: helpers.NewLanguage("en"),
+ Fs: hugofs.NewMem(),
Logger: logger,
TemplateProvider: DefaultTemplateProvider,
}
-)
+}
type tstNoStringer struct {
}
@@ -268,7 +272,7 @@ urlize: bat-man
tstInitTemplates()
- config := defaultDepsConfig
+ config := newDefaultDepsCfg()
config.WithTemplate = func(templ tplapi.Template) error {
if _, err := templ.New("test").Parse(in); err != nil {
t.Fatal("Got error on parse", err)
@@ -2798,7 +2802,9 @@ func TestPartialCached(t *testing.T) {
tmp = tc.tmpl
}
- defaultDepsConfig.WithTemplate = func(templ tplapi.Template) error {
+ cfg := newDefaultDepsCfg()
+
+ cfg.WithTemplate = func(templ tplapi.Template) error {
err := templ.AddTemplate("testroot", tmp)
if err != nil {
return err
@@ -2811,7 +2817,7 @@ func TestPartialCached(t *testing.T) {
return nil
}
- de := deps.New(defaultDepsConfig)
+ de := deps.New(cfg)
require.NoError(t, de.LoadTemplates())
buf := new(bytes.Buffer)
@@ -2836,7 +2842,8 @@ func TestPartialCached(t *testing.T) {
}
func BenchmarkPartial(b *testing.B) {
- defaultDepsConfig.WithTemplate = func(templ tplapi.Template) error {
+ cfg := newDefaultDepsCfg()
+ cfg.WithTemplate = func(templ tplapi.Template) error {
err := templ.AddTemplate("testroot", `{{ partial "bench1" . }}`)
if err != nil {
return err
@@ -2849,7 +2856,7 @@ func BenchmarkPartial(b *testing.B) {
return nil
}
- de := deps.New(defaultDepsConfig)
+ de := deps.New(cfg)
require.NoError(b, de.LoadTemplates())
buf := new(bytes.Buffer)
@@ -2866,7 +2873,8 @@ func BenchmarkPartial(b *testing.B) {
}
func BenchmarkPartialCached(b *testing.B) {
- defaultDepsConfig.WithTemplate = func(templ tplapi.Template) error {
+ cfg := newDefaultDepsCfg()
+ cfg.WithTemplate = func(templ tplapi.Template) error {
err := templ.AddTemplate("testroot", `{{ partialCached "bench1" . }}`)
if err != nil {
return err
@@ -2879,7 +2887,7 @@ func BenchmarkPartialCached(b *testing.B) {
return nil
}
- de := deps.New(defaultDepsConfig)
+ de := deps.New(cfg)
require.NoError(b, de.LoadTemplates())
buf := new(bytes.Buffer)
@@ -2896,7 +2904,8 @@ func BenchmarkPartialCached(b *testing.B) {
}
func newTestFuncster() *templateFuncster {
- d := deps.New(defaultDepsConfig)
+ cfg := newDefaultDepsCfg()
+ d := deps.New(cfg)
if err := d.LoadTemplates(); err != nil {
panic(err)
}
@@ -2905,7 +2914,8 @@ func newTestFuncster() *templateFuncster {
}
func newTestTemplate(t *testing.T, name, template string) *template.Template {
- defaultDepsConfig.WithTemplate = func(templ tplapi.Template) error {
+ cfg := newDefaultDepsCfg()
+ cfg.WithTemplate = func(templ tplapi.Template) error {
err := templ.AddTemplate(name, template)
if err != nil {
return err
@@ -2913,7 +2923,7 @@ func newTestTemplate(t *testing.T, name, template string) *template.Template {
return nil
}
- de := deps.New(defaultDepsConfig)
+ de := deps.New(cfg)
require.NoError(t, de.LoadTemplates())
return de.Tmpl.Lookup(name)
diff --git a/tpl/template_test.go b/tpl/template_test.go
index f22eb78ee..60950bb3b 100644
--- a/tpl/template_test.go
+++ b/tpl/template_test.go
@@ -27,7 +27,6 @@ import (
"github.com/spf13/afero"
"github.com/spf13/hugo/deps"
"github.com/spf13/hugo/helpers"
- "github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/tplapi"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
@@ -80,7 +79,7 @@ html lang=en
d := "DATA"
- config := defaultDepsConfig
+ config := newDefaultDepsCfg()
config.WithTemplate = func(templ tplapi.Template) error {
return templ.AddAceTemplate("mytemplate.ace", basePath, innerPath,
[]byte(this.baseContent), []byte(this.innerContent))
@@ -149,7 +148,8 @@ func TestAddTemplateFileWithMaster(t *testing.T) {
masterTplName := "mt"
finalTplName := "tp"
- defaultDepsConfig.WithTemplate = func(templ tplapi.Template) error {
+ cfg := newDefaultDepsCfg()
+ cfg.WithTemplate = func(templ tplapi.Template) error {
err := templ.AddTemplateFileWithMaster(finalTplName, overlayTplName, masterTplName)
@@ -188,16 +188,14 @@ func TestAddTemplateFileWithMaster(t *testing.T) {
return nil
}
- defaultDepsConfig.Fs = hugofs.NewMem()
-
if this.writeSkipper != 1 {
- afero.WriteFile(defaultDepsConfig.Fs.Source, masterTplName, []byte(this.masterTplContent), 0644)
+ afero.WriteFile(cfg.Fs.Source, masterTplName, []byte(this.masterTplContent), 0644)
}
if this.writeSkipper != 2 {
- afero.WriteFile(defaultDepsConfig.Fs.Source, overlayTplName, []byte(this.overlayTplContent), 0644)
+ afero.WriteFile(cfg.Fs.Source, overlayTplName, []byte(this.overlayTplContent), 0644)
}
- deps.New(defaultDepsConfig)
+ deps.New(cfg)
}
@@ -286,11 +284,12 @@ func TestTplGoFuzzReports(t *testing.T) {
H: "a,b,c,d,e,f",
}
- defaultDepsConfig.WithTemplate = func(templ tplapi.Template) error {
+ cfg := newDefaultDepsCfg()
+ cfg.WithTemplate = func(templ tplapi.Template) error {
return templ.AddTemplate("fuzz", this.data)
}
- de := deps.New(defaultDepsConfig)
+ de := deps.New(cfg)
require.NoError(t, de.LoadTemplates())
templ := de.Tmpl.(*GoHTMLTemplate)