diff options
author | Bjørn Erik Pedersen <[email protected]> | 2016-10-24 13:45:30 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2016-10-24 13:45:30 +0200 |
commit | a10b2cd372798c4e4b862f0ec03010d2aea2ff1e (patch) | |
tree | f768c420aac0008e4d118709e13fda278a7588c5 /helpers/url_test.go | |
parent | dffd7da07c3fb198acfa6c4664b53132c4cabe55 (diff) | |
download | hugo-a10b2cd372798c4e4b862f0ec03010d2aea2ff1e.tar.gz hugo-a10b2cd372798c4e4b862f0ec03010d2aea2ff1e.zip |
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/url_test.go')
-rw-r--r-- | helpers/url_test.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/helpers/url_test.go b/helpers/url_test.go index 2cf93b859..5394e9573 100644 --- a/helpers/url_test.go +++ b/helpers/url_test.go @@ -24,6 +24,10 @@ import ( ) func TestURLize(t *testing.T) { + initCommonTestConfig() + + p := NewPathSpecFromConfig(viper.GetViper()) + tests := []struct { input string expected string @@ -37,7 +41,7 @@ func TestURLize(t *testing.T) { } for _, test := range tests { - output := URLize(test.input) + output := p.URLize(test.input) if output != test.expected { t.Errorf("Expected %#v, got %#v\n", test.expected, output) } @@ -83,7 +87,8 @@ func doTestAbsURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool, for _, test := range tests { viper.Set("BaseURL", test.baseURL) - output := AbsURL(test.input, addLanguage) + p := NewPathSpecFromConfig(viper.GetViper()) + output := p.AbsURL(test.input, addLanguage) expected := test.expected if multilingual && addLanguage { if !defaultInSubDir && lang == "en" { @@ -159,8 +164,9 @@ func doTestRelURL(t *testing.T, defaultInSubDir, addLanguage, multilingual bool, for i, test := range tests { viper.Set("BaseURL", test.baseURL) viper.Set("canonifyURLs", test.canonify) + p := NewPathSpecFromConfig(viper.GetViper()) - output := RelURL(test.input, addLanguage) + output := p.RelURL(test.input, addLanguage) expected := test.expected if multilingual && addLanguage { |