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 --- hugolib/site_url_test.go | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'hugolib/site_url_test.go') diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go index 5706b9fb5..6f75846e7 100644 --- a/hugolib/site_url_test.go +++ b/hugolib/site_url_test.go @@ -20,9 +20,7 @@ import ( "html/template" "github.com/spf13/hugo/deps" - "github.com/spf13/hugo/hugofs" "github.com/spf13/hugo/source" - "github.com/spf13/viper" "github.com/stretchr/testify/require" ) @@ -35,14 +33,6 @@ slug: slug-doc-2 slug doc 2 content ` -const indexTemplate = "{{ range .Data.Pages }}.{{ end }}" - -func must(err error) { - if err != nil { - panic(err) - } -} - var urlFakeSource = []source.ByteSource{ {Name: filepath.FromSlash("content/blue/doc1.md"), Content: []byte(slugDoc1)}, {Name: filepath.FromSlash("content/blue/doc2.md"), Content: []byte(slugDoc2)}, @@ -50,8 +40,7 @@ var urlFakeSource = []source.ByteSource{ // Issue #1105 func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) { - testCommonResetState() - + t.Parallel() for i, this := range []struct { in string expected string @@ -61,8 +50,10 @@ func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) { {"http://base.com/sub", "http://base.com/sub"}, {"http://base.com", "http://base.com"}} { - viper.Set("baseURL", this.in) - s, err := NewSiteDefaultLang() + cfg, fs := newTestCfg() + cfg.Set("baseURL", this.in) + d := deps.DepsCfg{Cfg: cfg, Fs: fs} + s, err := NewSiteForCfg(d) require.NoError(t, err) s.initializeSiteInfo() @@ -70,18 +61,16 @@ func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) { t.Errorf("[%d] got %s expected %s", i, s.Info.BaseURL, this.expected) } } - } func TestPageCount(t *testing.T) { - testCommonResetState() - - viper.Set("uglyURLs", false) - viper.Set("paginate", 10) + t.Parallel() + cfg, fs := newTestCfg() + cfg.Set("uglyURLs", false) + cfg.Set("paginate", 10) - fs := hugofs.NewMem() writeSourcesToSource(t, "content", fs, urlFakeSource...) - s := buildSingleSite(t, deps.DepsCfg{Fs: fs}, BuildCfg{}) + s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{}) _, err := s.Fs.Destination.Open("public/blue") if err != nil { -- cgit v1.2.3