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