summaryrefslogtreecommitdiffstats
path: root/hugolib/page_permalink_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-05 10:20:06 +0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-02-17 17:15:26 +0100
commit93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch)
tree5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /hugolib/page_permalink_test.go
parente34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff)
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
Diffstat (limited to 'hugolib/page_permalink_test.go')
-rw-r--r--hugolib/page_permalink_test.go68
1 files changed, 35 insertions, 33 deletions
diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go
index 5ed8a8b47..0d7e983da 100644
--- a/hugolib/page_permalink_test.go
+++ b/hugolib/page_permalink_test.go
@@ -14,18 +14,18 @@
package hugolib
import (
+ "fmt"
"html/template"
"path/filepath"
"testing"
- "github.com/spf13/hugo/helpers"
- "github.com/spf13/hugo/source"
- "github.com/spf13/viper"
+ "github.com/stretchr/testify/require"
+
+ "github.com/spf13/hugo/deps"
)
-// TODO(bep) globals test siteinfo
-func _TestPermalink(t *testing.T) {
- testCommonResetState()
+func TestPermalink(t *testing.T) {
+ t.Parallel()
tests := []struct {
file string
@@ -50,51 +50,53 @@ func _TestPermalink(t *testing.T) {
{"x/y/z/boofar.md", "", "boofar", "", true, false, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
{"x/y/z/boofar.md", "http://barnew/", "", "", true, false, "http://barnew/x/y/z/boofar.html", "/x/y/z/boofar.html"},
{"x/y/z/boofar.md", "http://barnew/", "boofar", "", true, false, "http://barnew/x/y/z/boofar.html", "/x/y/z/boofar.html"},
- {"x/y/z/boofar.md", "http://barnew/boo/", "boofar", "", true, false, "http://barnew/boo/x/y/z/boofar.html", "/boo/x/y/z/boofar.html"},
- {"x/y/z/boofar.md", "http://barnew/boo/", "boofar", "", false, true, "http://barnew/boo/x/y/z/boofar/", "/x/y/z/boofar/"},
- {"x/y/z/boofar.md", "http://barnew/boo/", "boofar", "", false, false, "http://barnew/boo/x/y/z/boofar/", "/boo/x/y/z/boofar/"},
- {"x/y/z/boofar.md", "http://barnew/boo/", "boofar", "", true, true, "http://barnew/boo/x/y/z/boofar.html", "/x/y/z/boofar.html"},
- {"x/y/z/boofar.md", "http://barnew/boo", "boofar", "", true, true, "http://barnew/boo/x/y/z/boofar.html", "/x/y/z/boofar.html"},
+ {"x/y/z/boofar.md", "http://barnew/boo/", "booslug", "", true, false, "http://barnew/boo/x/y/z/booslug.html", "/boo/x/y/z/booslug.html"},
+ {"x/y/z/boofar.md", "http://barnew/boo/", "booslug", "", false, true, "http://barnew/boo/x/y/z/booslug/", "/x/y/z/booslug/"},
+ {"x/y/z/boofar.md", "http://barnew/boo/", "booslug", "", false, false, "http://barnew/boo/x/y/z/booslug/", "/boo/x/y/z/booslug/"},
+ {"x/y/z/boofar.md", "http://barnew/boo/", "booslug", "", true, true, "http://barnew/boo/x/y/z/booslug.html", "/x/y/z/booslug.html"},
+ {"x/y/z/boofar.md", "http://barnew/boo", "booslug", "", true, true, "http://barnew/boo/x/y/z/booslug.html", "/x/y/z/booslug.html"},
// test URL overrides
{"x/y/z/boofar.md", "", "", "/z/y/q/", false, false, "/z/y/q/", "/z/y/q/"},
}
- viper.Set("defaultExtension", "html")
for i, test := range tests {
- viper.Set("uglyURLs", test.uglyURLs)
- viper.Set("canonifyURLs", test.canonifyURLs)
- info := newSiteInfo(siteBuilderCfg{baseURL: string(test.base), language: helpers.NewDefaultLanguage()})
-
- p := &Page{
- pageInit: &pageInit{},
- Kind: KindPage,
- URLPath: URLPath{
- Section: "z",
- URL: test.url,
- },
- Site: &info,
- Source: Source{File: *source.NewFile(filepath.FromSlash(test.file))},
- }
- if test.slug != "" {
- p.update(map[string]interface{}{
- "slug": test.slug,
- })
- }
+ cfg, fs := newTestCfg()
+
+ cfg.Set("defaultExtension", "html")
+
+ cfg.Set("uglyURLs", test.uglyURLs)
+ cfg.Set("canonifyURLs", test.canonifyURLs)
+ cfg.Set("baseURL", test.base)
+
+ pageContent := fmt.Sprintf(`---
+title: Page
+slug: %q
+url: %q
+---
+Content
+`, test.slug, test.url)
+
+ writeSource(t, fs, filepath.Join("content", filepath.FromSlash(test.file)), pageContent)
+
+ s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
+ require.Len(t, s.RegularPages, 1)
+
+ p := s.RegularPages[0]
u := p.Permalink()
expected := test.expectedAbs
if u != expected {
- t.Errorf("Test %d: Expected abs url: %s, got: %s", i, expected, u)
+ t.Fatalf("[%d] Expected abs url: %s, got: %s", i, expected, u)
}
u = p.RelPermalink()
expected = test.expectedRel
if u != expected {
- t.Errorf("Test %d: Expected rel url: %s, got: %s", i, expected, u)
+ t.Errorf("[%d] Expected rel url: %s, got: %s", i, expected, u)
}
}
}