mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Stop Viper from leaking across many of the tests (now tests pass regardless of order tested)
This commit is contained in:
parent
599d1b9786
commit
a584ff207b
15 changed files with 223 additions and 101 deletions
|
@ -7,6 +7,8 @@ import (
|
|||
)
|
||||
|
||||
func TestFixURL(t *testing.T) {
|
||||
defer viper.Reset()
|
||||
|
||||
type data struct {
|
||||
TestName string
|
||||
CLIBaseURL string
|
||||
|
@ -28,6 +30,7 @@ func TestFixURL(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, test := range tests {
|
||||
viper.Reset()
|
||||
BaseURL = test.CLIBaseURL
|
||||
viper.Set("BaseURL", test.CfgBaseURL)
|
||||
serverAppend = test.AppendPort
|
||||
|
|
|
@ -431,6 +431,8 @@ func TestExists(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAbsPathify(t *testing.T) {
|
||||
defer viper.Reset()
|
||||
|
||||
type test struct {
|
||||
inPath, workingDir, expected string
|
||||
}
|
||||
|
@ -450,6 +452,7 @@ func TestAbsPathify(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, d := range data {
|
||||
viper.Reset()
|
||||
// todo see comment in AbsPathify
|
||||
viper.Set("WorkingDir", d.workingDir)
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func TestParsePygmentsArgs(t *testing.T) {
|
||||
|
@ -20,6 +21,7 @@ func TestParsePygmentsArgs(t *testing.T) {
|
|||
{"boo=invalid", "foo", false, false},
|
||||
{"style", "foo", false, false},
|
||||
} {
|
||||
viper.Reset()
|
||||
viper.Set("PygmentsStyle", this.pygmentsStyle)
|
||||
viper.Set("PygmentsUseClasses", this.pygmentsUseClasses)
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestURLize(t *testing.T) {
|
||||
|
@ -28,6 +29,7 @@ func TestURLize(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAbsURL(t *testing.T) {
|
||||
defer viper.Reset()
|
||||
tests := []struct {
|
||||
input string
|
||||
baseURL string
|
||||
|
@ -41,6 +43,7 @@ func TestAbsURL(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
viper.Reset()
|
||||
viper.Set("BaseURL", test.baseURL)
|
||||
output := AbsURL(test.input)
|
||||
if output != test.expected {
|
||||
|
@ -50,7 +53,8 @@ func TestAbsURL(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRelURL(t *testing.T) {
|
||||
defer viper.Set("canonifyURLs", viper.GetBool("canonifyURLs"))
|
||||
defer viper.Reset()
|
||||
//defer viper.Set("canonifyURLs", viper.GetBool("canonifyURLs"))
|
||||
tests := []struct {
|
||||
input string
|
||||
baseURL string
|
||||
|
@ -70,6 +74,7 @@ func TestRelURL(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, test := range tests {
|
||||
viper.Reset()
|
||||
viper.Set("BaseURL", test.baseURL)
|
||||
viper.Set("canonifyURLs", test.canonify)
|
||||
|
||||
|
|
|
@ -5,13 +5,15 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/kr/pretty"
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/hugo/hugofs"
|
||||
"github.com/spf13/hugo/source"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -156,6 +158,8 @@ type testMenuState struct {
|
|||
|
||||
// Issue 817 - identifier should trump everything
|
||||
func TestPageMenuWithIdentifier(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
toml := []source.ByteSource{
|
||||
{"sect/doc1.md", tstCreateMenuPageWithIdentifierTOML("t1", "m1", "i1")},
|
||||
|
@ -176,13 +180,12 @@ func TestPageMenuWithIdentifier(t *testing.T) {
|
|||
|
||||
func doTestPageMenuWithIdentifier(t *testing.T, menuPageSources []source.ByteSource) {
|
||||
|
||||
ts := setupMenuTests(t, menuPageSources)
|
||||
defer resetMenuTestState(ts)
|
||||
s := setupMenuTests(t, menuPageSources)
|
||||
|
||||
assert.Equal(t, 3, len(ts.site.Pages), "Not enough pages")
|
||||
assert.Equal(t, 3, len(s.Pages), "Not enough pages")
|
||||
|
||||
me1 := ts.findTestMenuEntryByID("m1", "i1")
|
||||
me2 := ts.findTestMenuEntryByID("m1", "i2")
|
||||
me1 := findTestMenuEntryByID(s, "m1", "i1")
|
||||
me2 := findTestMenuEntryByID(s, "m1", "i2")
|
||||
|
||||
assert.NotNil(t, me1)
|
||||
assert.NotNil(t, me2)
|
||||
|
@ -194,6 +197,9 @@ func doTestPageMenuWithIdentifier(t *testing.T, menuPageSources []source.ByteSou
|
|||
|
||||
// Issue 817 contd - name should be second identifier in
|
||||
func TestPageMenuWithDuplicateName(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
toml := []source.ByteSource{
|
||||
{"sect/doc1.md", tstCreateMenuPageWithNameTOML("t1", "m1", "n1")},
|
||||
{"sect/doc2.md", tstCreateMenuPageWithNameTOML("t1", "m1", "n2")},
|
||||
|
@ -212,13 +218,12 @@ func TestPageMenuWithDuplicateName(t *testing.T) {
|
|||
}
|
||||
|
||||
func doTestPageMenuWithDuplicateName(t *testing.T, menuPageSources []source.ByteSource) {
|
||||
ts := setupMenuTests(t, menuPageSources)
|
||||
defer resetMenuTestState(ts)
|
||||
s := setupMenuTests(t, menuPageSources)
|
||||
|
||||
assert.Equal(t, 3, len(ts.site.Pages), "Not enough pages")
|
||||
assert.Equal(t, 3, len(s.Pages), "Not enough pages")
|
||||
|
||||
me1 := ts.findTestMenuEntryByName("m1", "n1")
|
||||
me2 := ts.findTestMenuEntryByName("m1", "n2")
|
||||
me1 := findTestMenuEntryByName(s, "m1", "n1")
|
||||
me2 := findTestMenuEntryByName(s, "m1", "n2")
|
||||
|
||||
assert.NotNil(t, me1)
|
||||
assert.NotNil(t, me2)
|
||||
|
@ -229,19 +234,21 @@ func doTestPageMenuWithDuplicateName(t *testing.T, menuPageSources []source.Byte
|
|||
}
|
||||
|
||||
func TestPageMenu(t *testing.T) {
|
||||
ts := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
defer resetMenuTestState(ts)
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
if len(ts.site.Pages) != 3 {
|
||||
t.Fatalf("Posts not created, expected 3 got %d", len(ts.site.Pages))
|
||||
s := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
|
||||
if len(s.Pages) != 3 {
|
||||
t.Fatalf("Posts not created, expected 3 got %d", len(s.Pages))
|
||||
}
|
||||
|
||||
first := ts.site.Pages[0]
|
||||
second := ts.site.Pages[1]
|
||||
third := ts.site.Pages[2]
|
||||
first := s.Pages[0]
|
||||
second := s.Pages[1]
|
||||
third := s.Pages[2]
|
||||
|
||||
pOne := ts.findTestMenuEntryByName("p_one", "One")
|
||||
pTwo := ts.findTestMenuEntryByID("p_two", "Two")
|
||||
pOne := findTestMenuEntryByName(s, "p_one", "One")
|
||||
pTwo := findTestMenuEntryByID(s, "p_two", "Two")
|
||||
|
||||
for i, this := range []struct {
|
||||
menu string
|
||||
|
@ -275,10 +282,12 @@ func TestPageMenu(t *testing.T) {
|
|||
|
||||
// issue #888
|
||||
func TestMenuWithHashInURL(t *testing.T) {
|
||||
ts := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
defer resetMenuTestState(ts)
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
me := ts.findTestMenuEntryByID("hash", "hash")
|
||||
s := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
|
||||
me := findTestMenuEntryByID(s, "hash", "hash")
|
||||
|
||||
assert.NotNil(t, me)
|
||||
|
||||
|
@ -287,6 +296,9 @@ func TestMenuWithHashInURL(t *testing.T) {
|
|||
|
||||
// issue #719
|
||||
func TestMenuWithUnicodeURLs(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
for _, uglyURLs := range []bool{true, false} {
|
||||
for _, canonifyURLs := range []bool{true, false} {
|
||||
doTestMenuWithUnicodeURLs(t, canonifyURLs, uglyURLs)
|
||||
|
@ -298,10 +310,9 @@ func doTestMenuWithUnicodeURLs(t *testing.T, canonifyURLs, uglyURLs bool) {
|
|||
viper.Set("CanonifyURLs", canonifyURLs)
|
||||
viper.Set("UglyURLs", uglyURLs)
|
||||
|
||||
ts := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
defer resetMenuTestState(ts)
|
||||
s := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
|
||||
unicodeRussian := ts.findTestMenuEntryByID("unicode", "unicode-russian")
|
||||
unicodeRussian := findTestMenuEntryByID(s, "unicode", "unicode-russian")
|
||||
|
||||
expectedBase := "/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0"
|
||||
|
||||
|
@ -321,31 +332,31 @@ func doTestMenuWithUnicodeURLs(t *testing.T, canonifyURLs, uglyURLs bool) {
|
|||
|
||||
// Issue #1114
|
||||
func TestSectionPagesMenu(t *testing.T) {
|
||||
viper.Set("SectionPagesMenu", "spm")
|
||||
defer viper.Set("SectionPagesMenu", "")
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
for _, canonify := range []bool{true, false} {
|
||||
doTestSectionPagesMenu(canonify, t)
|
||||
}
|
||||
viper.Set("SectionPagesMenu", "spm")
|
||||
|
||||
doTestSectionPagesMenu(true, t)
|
||||
doTestSectionPagesMenu(false, t)
|
||||
}
|
||||
|
||||
func doTestSectionPagesMenu(canonifyUrls bool, t *testing.T) {
|
||||
viper.Set("CanonifyURLs", canonifyUrls)
|
||||
ts := setupMenuTests(t, MENU_PAGE_SECTIONS_SOURCES)
|
||||
defer resetMenuTestState(ts)
|
||||
s := setupMenuTests(t, MENU_PAGE_SECTIONS_SOURCES)
|
||||
|
||||
assert.Equal(t, 2, len(ts.site.Sections))
|
||||
assert.Equal(t, 2, len(s.Sections))
|
||||
|
||||
firstSectionPages := ts.site.Sections["first"]
|
||||
firstSectionPages := s.Sections["first"]
|
||||
assert.Equal(t, 2, len(firstSectionPages))
|
||||
secondSectionPages := ts.site.Sections["second-section"]
|
||||
secondSectionPages := s.Sections["second-section"]
|
||||
assert.Equal(t, 1, len(secondSectionPages))
|
||||
|
||||
nodeFirst := ts.site.newSectionListNode("first", firstSectionPages)
|
||||
nodeSecond := ts.site.newSectionListNode("second-section", secondSectionPages)
|
||||
nodeFirst := s.newSectionListNode("first", firstSectionPages)
|
||||
nodeSecond := s.newSectionListNode("second-section", secondSectionPages)
|
||||
|
||||
firstSectionMenuEntry := ts.findTestMenuEntryByID("spm", "first")
|
||||
secondSectionMenuEntry := ts.findTestMenuEntryByID("spm", "second-section")
|
||||
firstSectionMenuEntry := findTestMenuEntryByID(s, "spm", "first")
|
||||
secondSectionMenuEntry := findTestMenuEntryByID(s, "spm", "second-section")
|
||||
|
||||
assert.NotNil(t, firstSectionMenuEntry)
|
||||
assert.NotNil(t, secondSectionMenuEntry)
|
||||
|
@ -366,9 +377,11 @@ func doTestSectionPagesMenu(canonifyUrls bool, t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTaxonomyNodeMenu(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("CanonifyURLs", true)
|
||||
ts := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
defer resetMenuTestState(ts)
|
||||
s := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
|
||||
for i, this := range []struct {
|
||||
menu string
|
||||
|
@ -378,14 +391,14 @@ func TestTaxonomyNodeMenu(t *testing.T) {
|
|||
hasMenuCurrent bool
|
||||
}{
|
||||
{"tax", taxRenderInfo{key: "key", singular: "one", plural: "two"},
|
||||
ts.findTestMenuEntryByID("tax", "1"), true, false},
|
||||
findTestMenuEntryByID(s, "tax", "1"), true, false},
|
||||
{"tax", taxRenderInfo{key: "key", singular: "one", plural: "two"},
|
||||
ts.findTestMenuEntryByID("tax", "2"), true, false},
|
||||
findTestMenuEntryByID(s, "tax", "2"), true, false},
|
||||
{"tax", taxRenderInfo{key: "key", singular: "one", plural: "two"},
|
||||
&MenuEntry{Name: "Somewhere else", URL: "/somewhereelse"}, false, false},
|
||||
} {
|
||||
|
||||
n, _ := ts.site.newTaxonomyNode(this.taxInfo)
|
||||
n, _ := s.newTaxonomyNode(this.taxInfo)
|
||||
|
||||
isMenuCurrent := n.IsMenuCurrent(this.menu, this.menuItem)
|
||||
hasMenuCurrent := n.HasMenuCurrent(this.menu, this.menuItem)
|
||||
|
@ -400,7 +413,7 @@ func TestTaxonomyNodeMenu(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
menuEntryXML := ts.findTestMenuEntryByID("tax", "xml")
|
||||
menuEntryXML := findTestMenuEntryByID(s, "tax", "xml")
|
||||
|
||||
if strings.HasSuffix(menuEntryXML.URL, "/") {
|
||||
t.Error("RSS menu item should not be padded with trailing slash")
|
||||
|
@ -408,10 +421,15 @@ func TestTaxonomyNodeMenu(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHomeNodeMenu(t *testing.T) {
|
||||
ts := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
defer resetMenuTestState(ts)
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
home := ts.site.newHomeNode()
|
||||
viper.Set("CanonifyURLs", true)
|
||||
viper.Set("UglyURLs", true)
|
||||
|
||||
s := setupMenuTests(t, MENU_PAGE_SOURCES)
|
||||
|
||||
home := s.newHomeNode()
|
||||
homeMenuEntry := &MenuEntry{Name: home.Title, URL: home.URL}
|
||||
|
||||
for i, this := range []struct {
|
||||
|
@ -423,20 +441,24 @@ func TestHomeNodeMenu(t *testing.T) {
|
|||
{"main", homeMenuEntry, true, false},
|
||||
{"doesnotexist", homeMenuEntry, false, false},
|
||||
{"main", &MenuEntry{Name: "Somewhere else", URL: "/somewhereelse"}, false, false},
|
||||
{"grandparent", ts.findTestMenuEntryByID("grandparent", "grandparentId"), false, false},
|
||||
{"grandparent", ts.findTestMenuEntryByID("grandparent", "parentId"), false, true},
|
||||
{"grandparent", ts.findTestMenuEntryByID("grandparent", "grandchildId"), true, false},
|
||||
{"grandparent", findTestMenuEntryByID(s, "grandparent", "grandparentId"), false, false},
|
||||
{"grandparent", findTestMenuEntryByID(s, "grandparent", "parentId"), false, true},
|
||||
{"grandparent", findTestMenuEntryByID(s, "grandparent", "grandchildId"), true, false},
|
||||
} {
|
||||
|
||||
isMenuCurrent := home.IsMenuCurrent(this.menu, this.menuItem)
|
||||
hasMenuCurrent := home.HasMenuCurrent(this.menu, this.menuItem)
|
||||
|
||||
if isMenuCurrent != this.isMenuCurrent {
|
||||
t.Errorf("[%d] Wrong result from IsMenuCurrent: %v", i, isMenuCurrent)
|
||||
fmt.Println("isMenuCurrent", isMenuCurrent)
|
||||
pretty.Println("this:", this)
|
||||
t.Errorf("[%d] Wrong result from IsMenuCurrent: %v for %q", i, isMenuCurrent, this.menu)
|
||||
}
|
||||
|
||||
if hasMenuCurrent != this.hasMenuCurrent {
|
||||
t.Errorf("[%d] Wrong result for menuItem %v for HasMenuCurrent: %v", i, this.menuItem, hasMenuCurrent)
|
||||
fmt.Println("hasMenuCurrent", hasMenuCurrent)
|
||||
pretty.Println("this:", this)
|
||||
t.Errorf("[%d] Wrong result for menu %q menuItem %v for HasMenuCurrent: %v", i, this.menu, this.menuItem, hasMenuCurrent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -444,16 +466,16 @@ func TestHomeNodeMenu(t *testing.T) {
|
|||
var testMenuIdentityMatcher = func(me *MenuEntry, id string) bool { return me.Identifier == id }
|
||||
var testMenuNameMatcher = func(me *MenuEntry, id string) bool { return me.Name == id }
|
||||
|
||||
func (ts testMenuState) findTestMenuEntryByID(mn string, id string) *MenuEntry {
|
||||
return ts.findTestMenuEntry(mn, id, testMenuIdentityMatcher)
|
||||
func findTestMenuEntryByID(s *Site, mn string, id string) *MenuEntry {
|
||||
return findTestMenuEntry(s, mn, id, testMenuIdentityMatcher)
|
||||
}
|
||||
func (ts testMenuState) findTestMenuEntryByName(mn string, id string) *MenuEntry {
|
||||
return ts.findTestMenuEntry(mn, id, testMenuNameMatcher)
|
||||
func findTestMenuEntryByName(s *Site, mn string, id string) *MenuEntry {
|
||||
return findTestMenuEntry(s, mn, id, testMenuNameMatcher)
|
||||
}
|
||||
|
||||
func (ts testMenuState) findTestMenuEntry(mn string, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
|
||||
func findTestMenuEntry(s *Site, mn string, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
|
||||
var found *MenuEntry
|
||||
if menu, ok := ts.site.Menus[mn]; ok {
|
||||
if menu, ok := s.Menus[mn]; ok {
|
||||
for _, me := range *menu {
|
||||
|
||||
if matcher(me, id) {
|
||||
|
@ -463,7 +485,7 @@ func (ts testMenuState) findTestMenuEntry(mn string, id string, matcher func(me
|
|||
found = me
|
||||
}
|
||||
|
||||
descendant := ts.findDescendantTestMenuEntry(me, id, matcher)
|
||||
descendant := findDescendantTestMenuEntry(me, id, matcher)
|
||||
if descendant != nil {
|
||||
if found != nil {
|
||||
panic(fmt.Sprintf("Duplicate menu entry in menu %s with id/name %s", mn, id))
|
||||
|
@ -475,7 +497,7 @@ func (ts testMenuState) findTestMenuEntry(mn string, id string, matcher func(me
|
|||
return found
|
||||
}
|
||||
|
||||
func (ts testMenuState) findDescendantTestMenuEntry(parent *MenuEntry, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
|
||||
func findDescendantTestMenuEntry(parent *MenuEntry, id string, matcher func(me *MenuEntry, id string) bool) *MenuEntry {
|
||||
var found *MenuEntry
|
||||
if parent.HasChildren() {
|
||||
for _, child := range parent.Children {
|
||||
|
@ -487,7 +509,7 @@ func (ts testMenuState) findDescendantTestMenuEntry(parent *MenuEntry, id string
|
|||
found = child
|
||||
}
|
||||
|
||||
descendant := ts.findDescendantTestMenuEntry(child, id, matcher)
|
||||
descendant := findDescendantTestMenuEntry(child, id, matcher)
|
||||
if descendant != nil {
|
||||
if found != nil {
|
||||
panic(fmt.Sprintf("Duplicate menu entry in menuitem %s with id/name %s", parent.KeyName(), id))
|
||||
|
@ -499,9 +521,7 @@ func (ts testMenuState) findDescendantTestMenuEntry(parent *MenuEntry, id string
|
|||
return found
|
||||
}
|
||||
|
||||
func getTestMenuState(s *Site, t *testing.T) *testMenuState {
|
||||
menuState := &testMenuState{site: s, oldBaseURL: viper.Get("baseurl"), oldMenu: viper.Get("menu")}
|
||||
|
||||
func setupTestMenuState(s *Site, t *testing.T) {
|
||||
menus, err := tomlToMap(CONF_MENU1)
|
||||
|
||||
if err != nil {
|
||||
|
@ -510,21 +530,14 @@ func getTestMenuState(s *Site, t *testing.T) *testMenuState {
|
|||
|
||||
viper.Set("menu", menus["menu"])
|
||||
viper.Set("baseurl", "http://foo.local/Zoo/")
|
||||
|
||||
return menuState
|
||||
}
|
||||
|
||||
func setupMenuTests(t *testing.T, pageSources []source.ByteSource) *testMenuState {
|
||||
func setupMenuTests(t *testing.T, pageSources []source.ByteSource) *Site {
|
||||
s := createTestSite(pageSources)
|
||||
testState := getTestMenuState(s, t)
|
||||
setupTestMenuState(s, t)
|
||||
testSiteSetup(s, t)
|
||||
|
||||
return testState
|
||||
}
|
||||
|
||||
func resetMenuTestState(state *testMenuState) {
|
||||
viper.Set("menu", state.oldMenu)
|
||||
viper.Set("baseurl", state.oldBaseURL)
|
||||
return s
|
||||
}
|
||||
|
||||
func createTestSite(pageSources []source.ByteSource) *Site {
|
||||
|
@ -537,7 +550,6 @@ func createTestSite(pageSources []source.ByteSource) *Site {
|
|||
}
|
||||
|
||||
func testSiteSetup(s *Site, t *testing.T) {
|
||||
|
||||
s.Menus = Menus{}
|
||||
s.initializeSiteInfo()
|
||||
|
||||
|
@ -548,7 +560,6 @@ func testSiteSetup(s *Site, t *testing.T) {
|
|||
if err := s.BuildSiteMeta(); err != nil {
|
||||
t.Fatalf("Unable to build site metadata: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func tomlToMap(s string) (map[string]interface{}, error) {
|
||||
|
|
|
@ -10,6 +10,9 @@ import (
|
|||
)
|
||||
|
||||
func TestPermalink(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
tests := []struct {
|
||||
file string
|
||||
dir string
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var EMPTY_PAGE = ""
|
||||
|
@ -664,15 +665,19 @@ func TestSliceToLower(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTargetPath(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("DefaultExtension", "html")
|
||||
site_permalinks_setting := PermalinkOverrides{
|
||||
"post": ":year/:month/:day/:title/",
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
content string
|
||||
path string
|
||||
hasPermalink bool
|
||||
expected string
|
||||
content string
|
||||
path string
|
||||
hasPermalink bool
|
||||
expected string
|
||||
}{
|
||||
{SIMPLE_PAGE, "content/post/x.md", false, "content/post/x.html"},
|
||||
{SIMPLE_PAGE_WITH_URL, "content/post/x.md", false, "simple/url/index.html"},
|
||||
|
|
|
@ -2,12 +2,13 @@ package hugolib
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/hugo/source"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"html/template"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/hugo/source"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSplitPages(t *testing.T) {
|
||||
|
@ -100,6 +101,9 @@ func TestPagerNoPages(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPaginationURLFactory(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("PaginatePath", "zoo")
|
||||
unicode := newPaginationURLFactory("новости проекта")
|
||||
fooBar := newPaginationURLFactory("foo", "bar")
|
||||
|
@ -112,12 +116,18 @@ func TestPaginationURLFactory(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPaginator(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
for _, useViper := range []bool{false, true} {
|
||||
doTestPaginator(t, useViper)
|
||||
}
|
||||
}
|
||||
|
||||
func doTestPaginator(t *testing.T, useViper bool) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
pagerSize := 5
|
||||
if useViper {
|
||||
viper.Set("paginate", pagerSize)
|
||||
|
@ -159,6 +169,9 @@ func doTestPaginator(t *testing.T, useViper bool) {
|
|||
}
|
||||
|
||||
func TestPaginatorWithNegativePaginate(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("paginate", -1)
|
||||
s := &Site{}
|
||||
_, err := s.newHomeNode().Paginator()
|
||||
|
@ -166,6 +179,9 @@ func TestPaginatorWithNegativePaginate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPaginate(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
for _, useViper := range []bool{false, true} {
|
||||
doTestPaginate(t, useViper)
|
||||
}
|
||||
|
@ -224,6 +240,9 @@ func TestInvalidOptions(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPaginateWithNegativePaginate(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("paginate", -1)
|
||||
s := &Site{}
|
||||
_, err := s.newHomeNode().Paginate(createTestPages(2))
|
||||
|
@ -243,6 +262,9 @@ func TestPaginatePages(t *testing.T) {
|
|||
|
||||
// Issue #993
|
||||
func TestPaginatorFollowedByPaginateShouldFail(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("paginate", 10)
|
||||
s := &Site{}
|
||||
n1 := s.newHomeNode()
|
||||
|
@ -259,6 +281,8 @@ func TestPaginatorFollowedByPaginateShouldFail(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPaginateFollowedByDifferentPaginateShouldFail(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("paginate", 10)
|
||||
s := &Site{}
|
||||
|
|
|
@ -33,10 +33,12 @@ const RSS_TEMPLATE = `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom
|
|||
</rss>`
|
||||
|
||||
func TestRSSOutput(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
rssUri := "customrss.xml"
|
||||
viper.Set("baseurl", "http://auth/bub/")
|
||||
viper.Set("RSSUri", rssUri)
|
||||
defer viper.Set("RSSUri", "index.xml")
|
||||
|
||||
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||
s := &Site{
|
||||
|
@ -44,6 +46,7 @@ func TestRSSOutput(t *testing.T) {
|
|||
}
|
||||
s.initializeSiteInfo()
|
||||
s.prepTemplates()
|
||||
|
||||
// Add an rss.xml template to invoke the rss build.
|
||||
s.addTemplate("rss.xml", RSS_TEMPLATE)
|
||||
|
||||
|
|
|
@ -177,10 +177,12 @@ func TestFigureImgWidth(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHighlight(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
if !helpers.HasPygments() {
|
||||
t.Skip("Skip test as Pygments is not installed")
|
||||
}
|
||||
defer viper.Set("PygmentsStyle", viper.Get("PygmentsStyle"))
|
||||
viper.Set("PygmentsStyle", "bw")
|
||||
|
||||
tem := tpl.New()
|
||||
|
|
|
@ -2,12 +2,14 @@ package hugolib
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/source"
|
||||
"github.com/spf13/hugo/target"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/source"
|
||||
"github.com/spf13/hugo/target"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const ALIAS_DOC_1 = "---\ntitle: alias doc\naliases:\n - \"alias1/\"\n - \"alias-2/\"\n---\naliases\n"
|
||||
|
@ -74,6 +76,11 @@ func TestDegenerateNoTarget(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileTarget(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("DefaultExtension", "html")
|
||||
|
||||
s := &Site{
|
||||
Source: &source.InMemorySource{ByteSource: fakeSource},
|
||||
}
|
||||
|
@ -91,6 +98,11 @@ func TestFileTarget(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPageTargetUgly(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
viper.Set("DefaultExtension", "html")
|
||||
viper.Set("UglyURLs", true)
|
||||
|
||||
s := &Site{
|
||||
Targets: targetList{Page: &target.PagePub{UglyURLs: true}},
|
||||
Source: &source.InMemorySource{ByteSource: fakeSource},
|
||||
|
@ -108,6 +120,10 @@ func TestPageTargetUgly(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileTargetPublishDir(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
viper.Set("DefaultExtension", "html")
|
||||
|
||||
s := &Site{
|
||||
|
||||
Targets: targetList{
|
||||
|
|
|
@ -3,6 +3,12 @@ package hugolib
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/hugo/helpers"
|
||||
"github.com/spf13/hugo/hugofs"
|
||||
|
@ -10,11 +16,6 @@ import (
|
|||
"github.com/spf13/hugo/target"
|
||||
"github.com/spf13/hugo/tpl"
|
||||
"github.com/spf13/viper"
|
||||
"html/template"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -212,8 +213,10 @@ func TestRenderThingOrDefault(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func TestDraftAndFutureRender(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||
sources := []source.ByteSource{
|
||||
{filepath.FromSlash("sect/doc1.md"), []byte("---\ntitle: doc1\ndraft: true\npublishdate: \"2414-05-29\"\n---\n# doc1\n*some content*")},
|
||||
|
@ -281,7 +284,11 @@ func TestCrossrefs(t *testing.T) {
|
|||
}
|
||||
|
||||
func doTestCrossrefs(t *testing.T, relative, uglyUrls bool) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
baseUrl := "http://foo/bar"
|
||||
viper.Set("DefaultExtension", "html")
|
||||
viper.Set("baseurl", baseUrl)
|
||||
viper.Set("UglyURLs", uglyUrls)
|
||||
viper.Set("verbose", true)
|
||||
|
@ -358,10 +365,15 @@ func Test404ShouldAlwaysHaveUglyUrls(t *testing.T) {
|
|||
}
|
||||
|
||||
func doTest404ShouldAlwaysHaveUglyUrls(t *testing.T, uglyURLs bool) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("DefaultExtension", "html")
|
||||
viper.Set("verbose", true)
|
||||
viper.Set("baseurl", "http://auth/bub")
|
||||
viper.Set("DisableSitemap", false)
|
||||
viper.Set("DisableRSS", false)
|
||||
viper.Set("RSSUri", "index.xml")
|
||||
|
||||
viper.Set("UglyURLs", uglyURLs)
|
||||
|
||||
|
@ -423,6 +435,9 @@ func doTest404ShouldAlwaysHaveUglyUrls(t *testing.T, uglyURLs bool) {
|
|||
}
|
||||
|
||||
func TestSkipRender(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||
sources := []source.ByteSource{
|
||||
{filepath.FromSlash("sect/doc1.html"), []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")},
|
||||
|
@ -435,6 +450,7 @@ func TestSkipRender(t *testing.T) {
|
|||
{filepath.FromSlash("sect/doc8.html"), []byte("---\nmarkup: md\n---\n# title\nsome *content*")},
|
||||
}
|
||||
|
||||
viper.Set("DefaultExtension", "html")
|
||||
viper.Set("verbose", true)
|
||||
viper.Set("CanonifyURLs", true)
|
||||
viper.Set("baseurl", "http://auth/bub")
|
||||
|
@ -481,6 +497,11 @@ func TestSkipRender(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAbsUrlify(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("DefaultExtension", "html")
|
||||
|
||||
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||
sources := []source.ByteSource{
|
||||
{filepath.FromSlash("sect/doc1.html"), []byte("<!doctype html><html><head></head><body><a href=\"#frag1\">link</a></body></html>")},
|
||||
|
@ -584,6 +605,9 @@ var WEIGHTED_SOURCES = []source.ByteSource{
|
|||
}
|
||||
|
||||
func TestOrderedPages(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||
|
||||
viper.Set("baseurl", "http://auth/bub")
|
||||
|
@ -649,6 +673,9 @@ var GROUPED_SOURCES = []source.ByteSource{
|
|||
}
|
||||
|
||||
func TestGroupedPages(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println("Recovered in f", r)
|
||||
|
@ -832,6 +859,9 @@ date = 2010-05-27T07:32:00Z
|
|||
Front Matter with weighted tags and categories`)
|
||||
|
||||
func TestWeightedTaxonomies(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||
sources := []source.ByteSource{
|
||||
{filepath.FromSlash("sect/doc1.md"), PAGE_WITH_WEIGHTED_TAXONOMIES_1},
|
||||
|
|
|
@ -4,12 +4,13 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"html/template"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"github.com/spf13/hugo/hugofs"
|
||||
"github.com/spf13/hugo/source"
|
||||
"github.com/spf13/hugo/target"
|
||||
"github.com/spf13/viper"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
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"
|
||||
|
@ -54,6 +55,8 @@ var urlFakeSource = []source.ByteSource{
|
|||
|
||||
// Issue #1105
|
||||
func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
for i, this := range []struct {
|
||||
in string
|
||||
|
@ -76,6 +79,9 @@ func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPageCount(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||
|
||||
viper.Set("uglyurls", false)
|
||||
|
|
|
@ -10,6 +10,9 @@ import (
|
|||
const SITE_INFO_PARAM_TEMPLATE = `{{ .Site.Params.MyGlobalParam }}`
|
||||
|
||||
func TestSiteInfoParams(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("Params", map[string]interface{}{"MyGlobalParam": "FOOBAR_PARAM"})
|
||||
s := &Site{}
|
||||
|
||||
|
@ -32,6 +35,9 @@ func TestSiteInfoParams(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSiteInfoPermalinks(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
viper.Set("Permalinks", map[string]interface{}{"section": "/:title"})
|
||||
s := &Site{}
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ const SITEMAP_TEMPLATE = `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap
|
|||
</urlset>`
|
||||
|
||||
func TestSitemapOutput(t *testing.T) {
|
||||
viper.Reset()
|
||||
defer viper.Reset()
|
||||
|
||||
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||
|
||||
viper.Set("baseurl", "http://auth/bub/")
|
||||
|
|
Loading…
Reference in a new issue