diff --git a/commands/hugo.go b/commands/hugo.go index 0e84093c1..2a6bd8e6e 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -80,7 +80,7 @@ func init() { } func InitializeConfig() { - viper.SetConfigName(CfgFile) // config + viper.SetConfigName(CfgFile) viper.AddConfigPath(Source) viper.ReadInConfig() diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go index a4fed5b19..5bbf07da8 100644 --- a/hugolib/page_permalink_test.go +++ b/hugolib/page_permalink_test.go @@ -3,6 +3,8 @@ package hugolib import ( "html/template" "testing" + + "github.com/spf13/viper" ) func TestPermalink(t *testing.T) { @@ -32,6 +34,7 @@ func TestPermalink(t *testing.T) { } for _, test := range tests { + viper.Set("uglyurls", test.uglyurls) p := &Page{ Node: Node{ UrlPath: UrlPath{ @@ -40,9 +43,6 @@ func TestPermalink(t *testing.T) { }, Site: SiteInfo{ BaseUrl: test.base, - Config: &Config{ - UglyUrls: test.uglyurls, - }, }, }, File: File{FileName: test.file, Dir: test.dir, Extension: "html"}, diff --git a/hugolib/rss_test.go b/hugolib/rss_test.go index 5f21db887..8bcb155bd 100644 --- a/hugolib/rss_test.go +++ b/hugolib/rss_test.go @@ -2,9 +2,11 @@ package hugolib import ( "bytes" + "testing" + "github.com/spf13/hugo/source" "github.com/spf13/hugo/target" - "testing" + "github.com/spf13/viper" ) const RSS_TEMPLATE = ` @@ -31,9 +33,9 @@ const RSS_TEMPLATE = `more content"), "blue"}, } for _, canonify := range []bool{true, false} { + viper.Set("CanonifyUrls", canonify) + viper.Set("BaseUrl", "http://auth/bub") s := &Site{ Target: target, - Config: Config{ - BaseUrl: "http://auth/bub", - CanonifyUrls: canonify, - }, Source: &source.InMemorySource{ByteSource: sources}, } - t.Logf("Rendering with BaseUrl %q and CanonifyUrls set %v", s.Config.BaseUrl, canonify) + t.Logf("Rendering with BaseUrl %q and CanonifyUrls set %v", viper.GetString("baseUrl"), canonify) s.initializeSiteInfo() s.prepTemplates() must(s.addTemplate("blue/single.html", TEMPLATE_WITH_URL_ABS)) @@ -335,7 +332,7 @@ func TestAbsUrlify(t *testing.T) { expected := test.expected if !canonify { - expected = strings.Replace(expected, s.Config.BaseUrl, "", -1) + expected = strings.Replace(expected, viper.GetString("baseurl"), "", -1) } if string(content) != expected { t.Errorf("AbsUrlify content expected:\n%q\ngot\n%q", expected, string(content)) @@ -380,9 +377,10 @@ var WEIGHTED_SOURCES = []source.ByteSource{ func TestOrderedPages(t *testing.T) { files := make(map[string][]byte) target := &target.InMemoryTarget{Files: files} + + viper.Set("baseurl", "http://auth/bub") s := &Site{ Target: target, - Config: Config{BaseUrl: "http://auth/bub/"}, Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES}, } s.initializeSiteInfo() @@ -466,9 +464,11 @@ func TestWeightedIndexes(t *testing.T) { indexes["tag"] = "tags" indexes["category"] = "categories" + + viper.Set("baseurl", "http://auth/bub") + viper.Set("indexes", indexes) s := &Site{ Target: target, - Config: Config{BaseUrl: "http://auth/bub/", Indexes: indexes}, Source: &source.InMemorySource{ByteSource: sources}, } s.initializeSiteInfo() diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go index ef661961b..f248d6df1 100644 --- a/hugolib/site_url_test.go +++ b/hugolib/site_url_test.go @@ -1,10 +1,12 @@ package hugolib import ( - "github.com/spf13/hugo/source" - "github.com/spf13/hugo/target" "html/template" "testing" + + "github.com/spf13/hugo/source" + "github.com/spf13/hugo/target" + "github.com/spf13/viper" ) const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - sd1/foo/\n - sd2\n - sd3/\n - sd4.html\n---\nslug doc 1 content\n" @@ -51,10 +53,11 @@ func TestPageCount(t *testing.T) { files := make(map[string][]byte) target := &target.InMemoryTarget{Files: files} alias := &InMemoryAliasTarget{files: files} + + viper.Set("uglyurls", false) s := &Site{ Target: target, Alias: alias, - Config: Config{UglyUrls: false}, Source: &source.InMemorySource{ByteSource: urlFakeSource}, } s.initializeSiteInfo() diff --git a/hugolib/siteinfo_test.go b/hugolib/siteinfo_test.go index c0ae56575..7d765e580 100644 --- a/hugolib/siteinfo_test.go +++ b/hugolib/siteinfo_test.go @@ -3,14 +3,15 @@ package hugolib import ( "bytes" "testing" + + "github.com/spf13/viper" ) const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}` func TestSiteInfoParams(t *testing.T) { - s := &Site{ - Config: Config{Params: map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"}}, - } + viper.Set("Params", map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"}) + s := &Site{} s.initialize() if s.Info.Params["MyGlobalParam"] != "FOOBAR_PARAM" {