Fixing all tests to pass with new Viper Config

This commit is contained in:
spf13 2014-04-07 11:44:13 -04:00
parent 62dd1d45c1
commit 9a83f7a01b
6 changed files with 37 additions and 31 deletions

View file

@ -80,7 +80,7 @@ func init() {
} }
func InitializeConfig() { func InitializeConfig() {
viper.SetConfigName(CfgFile) // config viper.SetConfigName(CfgFile)
viper.AddConfigPath(Source) viper.AddConfigPath(Source)
viper.ReadInConfig() viper.ReadInConfig()

View file

@ -3,6 +3,8 @@ package hugolib
import ( import (
"html/template" "html/template"
"testing" "testing"
"github.com/spf13/viper"
) )
func TestPermalink(t *testing.T) { func TestPermalink(t *testing.T) {
@ -32,6 +34,7 @@ func TestPermalink(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
viper.Set("uglyurls", test.uglyurls)
p := &Page{ p := &Page{
Node: Node{ Node: Node{
UrlPath: UrlPath{ UrlPath: UrlPath{
@ -40,9 +43,6 @@ func TestPermalink(t *testing.T) {
}, },
Site: SiteInfo{ Site: SiteInfo{
BaseUrl: test.base, BaseUrl: test.base,
Config: &Config{
UglyUrls: test.uglyurls,
},
}, },
}, },
File: File{FileName: test.file, Dir: test.dir, Extension: "html"}, File: File{FileName: test.file, Dir: test.dir, Extension: "html"},

View file

@ -2,9 +2,11 @@ package hugolib
import ( import (
"bytes" "bytes"
"testing"
"github.com/spf13/hugo/source" "github.com/spf13/hugo/source"
"github.com/spf13/hugo/target" "github.com/spf13/hugo/target"
"testing" "github.com/spf13/viper"
) )
const RSS_TEMPLATE = `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> const RSS_TEMPLATE = `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
@ -31,9 +33,9 @@ const RSS_TEMPLATE = `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom
func TestRSSOutput(t *testing.T) { func TestRSSOutput(t *testing.T) {
files := make(map[string][]byte) files := make(map[string][]byte)
target := &target.InMemoryTarget{Files: files} target := &target.InMemoryTarget{Files: files}
viper.Set("baseurl", "http://auth/bub/")
s := &Site{ s := &Site{
Target: target, Target: target,
Config: Config{BaseUrl: "http://auth/bub/"},
Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES}, Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
} }
s.initializeSiteInfo() s.initializeSiteInfo()

View file

@ -3,12 +3,15 @@ package hugolib
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/target"
"html/template" "html/template"
"io" "io"
"strings" "strings"
"testing" "testing"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/target"
"github.com/spf13/viper"
) )
const ( const (
@ -200,11 +203,9 @@ func TestTargetPath(t *testing.T) {
if true { if true {
return return
} }
for _, test := range tests { for _, test := range tests {
s := &Site{ p := pageMust(ReadFrom(strings.NewReader(test.content), helpers.AbsPathify(test.doc)))
Config: Config{ContentDir: "content"},
}
p := pageMust(ReadFrom(strings.NewReader(test.content), s.Config.GetAbsPath(test.doc)))
expected := test.expectedOutFile expected := test.expectedOutFile
@ -232,13 +233,11 @@ func TestSkipRender(t *testing.T) {
{"sect/doc8.html", []byte("---\nmarkup: md\n---\n# title\nsome *content*"), "sect"}, {"sect/doc8.html", []byte("---\nmarkup: md\n---\n# title\nsome *content*"), "sect"},
} }
viper.Set("verbose", true)
viper.Set("CanonifyUrls", true)
viper.Set("baseurl", "http://auth/bub")
s := &Site{ s := &Site{
Target: target, Target: target,
Config: Config{
Verbose: true,
BaseUrl: "http://auth/bub",
CanonifyUrls: true,
},
Source: &source.InMemorySource{ByteSource: sources}, Source: &source.InMemorySource{ByteSource: sources},
} }
@ -295,15 +294,13 @@ func TestAbsUrlify(t *testing.T) {
{"content/blue/doc2.html", []byte("---\nf: t\n---\n<!doctype html><html><body>more content</body></html>"), "blue"}, {"content/blue/doc2.html", []byte("---\nf: t\n---\n<!doctype html><html><body>more content</body></html>"), "blue"},
} }
for _, canonify := range []bool{true, false} { for _, canonify := range []bool{true, false} {
viper.Set("CanonifyUrls", canonify)
viper.Set("BaseUrl", "http://auth/bub")
s := &Site{ s := &Site{
Target: target, Target: target,
Config: Config{
BaseUrl: "http://auth/bub",
CanonifyUrls: canonify,
},
Source: &source.InMemorySource{ByteSource: sources}, 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.initializeSiteInfo()
s.prepTemplates() s.prepTemplates()
must(s.addTemplate("blue/single.html", TEMPLATE_WITH_URL_ABS)) must(s.addTemplate("blue/single.html", TEMPLATE_WITH_URL_ABS))
@ -335,7 +332,7 @@ func TestAbsUrlify(t *testing.T) {
expected := test.expected expected := test.expected
if !canonify { if !canonify {
expected = strings.Replace(expected, s.Config.BaseUrl, "", -1) expected = strings.Replace(expected, viper.GetString("baseurl"), "", -1)
} }
if string(content) != expected { if string(content) != expected {
t.Errorf("AbsUrlify content expected:\n%q\ngot\n%q", expected, string(content)) 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) { func TestOrderedPages(t *testing.T) {
files := make(map[string][]byte) files := make(map[string][]byte)
target := &target.InMemoryTarget{Files: files} target := &target.InMemoryTarget{Files: files}
viper.Set("baseurl", "http://auth/bub")
s := &Site{ s := &Site{
Target: target, Target: target,
Config: Config{BaseUrl: "http://auth/bub/"},
Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES}, Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
} }
s.initializeSiteInfo() s.initializeSiteInfo()
@ -466,9 +464,11 @@ func TestWeightedIndexes(t *testing.T) {
indexes["tag"] = "tags" indexes["tag"] = "tags"
indexes["category"] = "categories" indexes["category"] = "categories"
viper.Set("baseurl", "http://auth/bub")
viper.Set("indexes", indexes)
s := &Site{ s := &Site{
Target: target, Target: target,
Config: Config{BaseUrl: "http://auth/bub/", Indexes: indexes},
Source: &source.InMemorySource{ByteSource: sources}, Source: &source.InMemorySource{ByteSource: sources},
} }
s.initializeSiteInfo() s.initializeSiteInfo()

View file

@ -1,10 +1,12 @@
package hugolib package hugolib
import ( import (
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/target"
"html/template" "html/template"
"testing" "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" 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) files := make(map[string][]byte)
target := &target.InMemoryTarget{Files: files} target := &target.InMemoryTarget{Files: files}
alias := &InMemoryAliasTarget{files: files} alias := &InMemoryAliasTarget{files: files}
viper.Set("uglyurls", false)
s := &Site{ s := &Site{
Target: target, Target: target,
Alias: alias, Alias: alias,
Config: Config{UglyUrls: false},
Source: &source.InMemorySource{ByteSource: urlFakeSource}, Source: &source.InMemorySource{ByteSource: urlFakeSource},
} }
s.initializeSiteInfo() s.initializeSiteInfo()

View file

@ -3,14 +3,15 @@ package hugolib
import ( import (
"bytes" "bytes"
"testing" "testing"
"github.com/spf13/viper"
) )
const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}` const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}`
func TestSiteInfoParams(t *testing.T) { func TestSiteInfoParams(t *testing.T) {
s := &Site{ viper.Set("Params", map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"})
Config: Config{Params: map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"}}, s := &Site{}
}
s.initialize() s.initialize()
if s.Info.Params["MyGlobalParam"] != "FOOBAR_PARAM" { if s.Info.Params["MyGlobalParam"] != "FOOBAR_PARAM" {