diff options
author | Bjørn Erik Pedersen <[email protected]> | 2017-02-05 10:20:06 +0700 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-02-17 17:15:26 +0100 |
commit | 93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch) | |
tree | 5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /helpers/path_test.go | |
parent | e34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff) | |
download | hugo-93ca7c9e958e34469a337e4efcc7c75774ec50fd.tar.gz hugo-93ca7c9e958e34469a337e4efcc7c75774ec50fd.zip |
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
Diffstat (limited to 'helpers/path_test.go')
-rw-r--r-- | helpers/path_test.go | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/helpers/path_test.go b/helpers/path_test.go index 46141befc..90dd95288 100644 --- a/helpers/path_test.go +++ b/helpers/path_test.go @@ -34,15 +34,7 @@ import ( "github.com/spf13/viper" ) -func initCommonTestConfig() { - viper.Set("currentContentLanguage", NewLanguage("en")) -} - func TestMakePath(t *testing.T) { - viper.Reset() - defer viper.Reset() - initCommonTestConfig() - tests := []struct { input string expected string @@ -64,8 +56,10 @@ func TestMakePath(t *testing.T) { } for _, test := range tests { - viper.Set("removePathAccents", test.removeAccents) - p := NewPathSpec(hugofs.NewMem(), viper.GetViper()) + v := viper.New() + l := NewDefaultLanguage(v) + v.Set("removePathAccents", test.removeAccents) + p := NewPathSpec(hugofs.NewMem(v), l) output := p.MakePath(test.input) if output != test.expected { @@ -75,11 +69,9 @@ func TestMakePath(t *testing.T) { } func TestMakePathSanitized(t *testing.T) { - viper.Reset() - defer viper.Reset() - initCommonTestConfig() - - p := NewPathSpec(hugofs.NewMem(), viper.GetViper()) + v := viper.New() + l := NewDefaultLanguage(v) + p := NewPathSpec(hugofs.NewMem(v), l) tests := []struct { input string @@ -102,12 +94,12 @@ func TestMakePathSanitized(t *testing.T) { } func TestMakePathSanitizedDisablePathToLower(t *testing.T) { - viper.Reset() - defer viper.Reset() + v := viper.New() + + v.Set("disablePathToLower", true) - initCommonTestConfig() - viper.Set("disablePathToLower", true) - p := NewPathSpec(hugofs.NewMem(), viper.GetViper()) + l := NewDefaultLanguage(v) + p := NewPathSpec(hugofs.NewMem(v), l) tests := []struct { input string @@ -553,9 +545,9 @@ func TestAbsPathify(t *testing.T) { for i, d := range data { viper.Reset() // todo see comment in AbsPathify - viper.Set("workingDir", d.workingDir) + ps := newTestDefaultPathSpec("workingDir", d.workingDir) - expected := AbsPathify(d.inPath) + expected := ps.AbsPathify(d.inPath) if d.expected != expected { t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected) } @@ -563,18 +555,18 @@ func TestAbsPathify(t *testing.T) { t.Logf("Running platform specific path tests for %s", runtime.GOOS) if runtime.GOOS == "windows" { for i, d := range windowsData { - viper.Set("workingDir", d.workingDir) + ps := newTestDefaultPathSpec("workingDir", d.workingDir) - expected := AbsPathify(d.inPath) + expected := ps.AbsPathify(d.inPath) if d.expected != expected { t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected) } } } else { for i, d := range unixData { - viper.Set("workingDir", d.workingDir) + ps := newTestDefaultPathSpec("workingDir", d.workingDir) - expected := AbsPathify(d.inPath) + expected := ps.AbsPathify(d.inPath) if d.expected != expected { t.Errorf("Test %d failed. Expected %q but got %q", i, d.expected, expected) } |