diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-01-10 10:55:03 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-04 11:37:25 +0700 |
commit | c71e1b106e6011d148cac899f83c4685dee33a22 (patch) | |
tree | c5c7090f0c2398c7771e4908ebcc97aa7714ffd2 /hugolib/testhelpers_test.go | |
parent | 0ada40591216572b0e4c6a8ab986b0aa4fb13c13 (diff) |
all: Refactor to nonglobal file systems
Updates #2701
Fixes #2951
Diffstat (limited to 'hugolib/testhelpers_test.go')
-rw-r--r-- | hugolib/testhelpers_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go new file mode 100644 index 000000000..1d775aca8 --- /dev/null +++ b/hugolib/testhelpers_test.go @@ -0,0 +1,53 @@ +package hugolib + +import ( + "path/filepath" + "testing" + + "github.com/spf13/hugo/deps" + "github.com/spf13/hugo/helpers" + "github.com/spf13/hugo/hugofs" + "github.com/spf13/hugo/source" + "github.com/spf13/hugo/tplapi" + "github.com/spf13/viper" + + "github.com/stretchr/testify/require" +) + +func newTestDepsConfig() deps.DepsCfg { + return deps.DepsCfg{Fs: hugofs.NewMem()} +} + +func newTestPathSpec() *helpers.PathSpec { + return helpers.NewPathSpec(hugofs.NewMem(), viper.GetViper()) +} + +func createWithTemplateFromNameValues(additionalTemplates ...string) func(templ tplapi.Template) error { + + return func(templ tplapi.Template) error { + for i := 0; i < len(additionalTemplates); i += 2 { + err := templ.AddTemplate(additionalTemplates[i], additionalTemplates[i+1]) + if err != nil { + return err + } + } + return nil + } +} + +func buildSingleSite(t *testing.T, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site { + h, err := NewHugoSitesFromConfiguration(depsCfg) + + require.NoError(t, err) + require.Len(t, h.Sites, 1) + + require.NoError(t, h.Build(buildCfg)) + + return h.Sites[0] +} + +func writeSourcesToSource(t *testing.T, base string, fs *hugofs.Fs, sources ...source.ByteSource) { + for _, src := range sources { + writeSource(t, fs, filepath.Join(base, src.Name), string(src.Content)) + } +} |