summaryrefslogtreecommitdiffstats
path: root/helpers/path_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-10-24 13:45:30 +0200
committerGitHub <noreply@github.com>2016-10-24 13:45:30 +0200
commita10b2cd372798c4e4b862f0ec03010d2aea2ff1e (patch)
treef768c420aac0008e4d118709e13fda278a7588c5 /helpers/path_test.go
parentdffd7da07c3fb198acfa6c4664b53132c4cabe55 (diff)
Avoid reading from Viper for path and URL funcs
The gain, given the "real sites benchmark" below, is obvious: ``` benchmark old ns/op new ns/op delta BenchmarkHugo-4 14497594101 13084156335 -9.75% benchmark old allocs new allocs delta BenchmarkHugo-4 57404335 48282002 -15.89% benchmark old bytes new bytes delta BenchmarkHugo-4 9933505624 9721984424 -2.13% ``` Fixes #2495
Diffstat (limited to 'helpers/path_test.go')
-rw-r--r--helpers/path_test.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/helpers/path_test.go b/helpers/path_test.go
index cbdcd8da2..ef0c16505 100644
--- a/helpers/path_test.go
+++ b/helpers/path_test.go
@@ -33,9 +33,14 @@ import (
"github.com/spf13/viper"
)
+func initCommonTestConfig() {
+ viper.Set("CurrentContentLanguage", NewLanguage("en"))
+}
+
func TestMakePath(t *testing.T) {
viper.Reset()
defer viper.Reset()
+ initCommonTestConfig()
tests := []struct {
input string
@@ -57,7 +62,8 @@ func TestMakePath(t *testing.T) {
for _, test := range tests {
viper.Set("RemovePathAccents", test.removeAccents)
- output := MakePath(test.input)
+ p := NewPathSpecFromConfig(viper.GetViper())
+ output := p.MakePath(test.input)
if output != test.expected {
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
}
@@ -67,6 +73,9 @@ func TestMakePath(t *testing.T) {
func TestMakePathSanitized(t *testing.T) {
viper.Reset()
defer viper.Reset()
+ initCommonTestConfig()
+
+ p := NewPathSpecFromConfig(viper.GetViper())
tests := []struct {
input string
@@ -81,7 +90,7 @@ func TestMakePathSanitized(t *testing.T) {
}
for _, test := range tests {
- output := MakePathSanitized(test.input)
+ output := p.MakePathSanitized(test.input)
if output != test.expected {
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
}
@@ -91,7 +100,10 @@ func TestMakePathSanitized(t *testing.T) {
func TestMakePathSanitizedDisablePathToLower(t *testing.T) {
viper.Reset()
defer viper.Reset()
+
+ initCommonTestConfig()
viper.Set("DisablePathToLower", true)
+ p := NewPathSpecFromConfig(viper.GetViper())
tests := []struct {
input string
@@ -106,7 +118,7 @@ func TestMakePathSanitizedDisablePathToLower(t *testing.T) {
}
for _, test := range tests {
- output := MakePathSanitized(test.input)
+ output := p.MakePathSanitized(test.input)
if output != test.expected {
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
}