From 93ca7c9e958e34469a337e4efcc7c75774ec50fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 5 Feb 2017 10:20:06 +0700 Subject: all: Refactor to nonglobal Viper, i18n etc. This is a final rewrite that removes all the global state in Hugo, which also enables the use if `t.Parallel` in tests. Updates #2701 Fixes #3016 --- helpers/testhelpers_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 helpers/testhelpers_test.go (limited to 'helpers/testhelpers_test.go') diff --git a/helpers/testhelpers_test.go b/helpers/testhelpers_test.go new file mode 100644 index 000000000..303f9feb6 --- /dev/null +++ b/helpers/testhelpers_test.go @@ -0,0 +1,37 @@ +package helpers + +import ( + "github.com/spf13/viper" + + "github.com/spf13/hugo/hugofs" +) + +func newTestPathSpec(fs *hugofs.Fs, v *viper.Viper) *PathSpec { + l := NewDefaultLanguage(v) + return NewPathSpec(fs, l) +} + +func newTestDefaultPathSpec(configKeyValues ...interface{}) *PathSpec { + v := viper.New() + fs := hugofs.NewMem(v) + cfg := newTestCfg(fs) + + for i := 0; i < len(configKeyValues); i += 2 { + cfg.Set(configKeyValues[i].(string), configKeyValues[i+1]) + } + return newTestPathSpec(fs, cfg) +} + +func newTestCfg(fs *hugofs.Fs) *viper.Viper { + v := viper.New() + + v.SetFs(fs.Source) + + return v + +} + +func newTestContentSpec() *ContentSpec { + v := viper.New() + return NewContentSpec(v) +} -- cgit v1.2.3