mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-12 20:13:59 +02:00
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
This commit is contained in:
committed by
GitHub
parent
dffd7da07c
commit
a10b2cd372
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user