mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-27 02:01:31 +00:00
d392893cd7
The main motivation behind this is simplicity and correctnes, but the new small config library is also faster: ``` BenchmarkDefaultConfigProvider/Viper-16 252418 4546 ns/op 2720 B/op 30 allocs/op BenchmarkDefaultConfigProvider/Custom-16 450756 2651 ns/op 1008 B/op 6 allocs/op ``` Fixes #8633 Fixes #8618 Fixes #8630 Updates #8591 Closes #6680 Closes #5192
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/gohugoio/hugo/common/loggers"
|
|
"github.com/gohugoio/hugo/config"
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/gohugoio/hugo/hugofs"
|
|
"github.com/gohugoio/hugo/langs"
|
|
"github.com/gohugoio/hugo/modules"
|
|
)
|
|
|
|
func newTestPathSpec(fs *hugofs.Fs, v config.Provider) *PathSpec {
|
|
l := langs.NewDefaultLanguage(v)
|
|
ps, _ := NewPathSpec(fs, l, nil)
|
|
return ps
|
|
}
|
|
|
|
func newTestDefaultPathSpec(configKeyValues ...interface{}) *PathSpec {
|
|
v := config.New()
|
|
fs := hugofs.NewMem(v)
|
|
cfg := newTestCfg()
|
|
|
|
for i := 0; i < len(configKeyValues); i += 2 {
|
|
cfg.Set(configKeyValues[i].(string), configKeyValues[i+1])
|
|
}
|
|
return newTestPathSpec(fs, cfg)
|
|
}
|
|
|
|
func newTestCfg() config.Provider {
|
|
v := config.New()
|
|
v.Set("contentDir", "content")
|
|
v.Set("dataDir", "data")
|
|
v.Set("i18nDir", "i18n")
|
|
v.Set("layoutDir", "layouts")
|
|
v.Set("assetDir", "assets")
|
|
v.Set("resourceDir", "resources")
|
|
v.Set("publishDir", "public")
|
|
v.Set("archetypeDir", "archetypes")
|
|
langs.LoadLanguageSettings(v, nil)
|
|
langs.LoadLanguageSettings(v, nil)
|
|
mod, err := modules.CreateProjectModule(v)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
v.Set("allModules", modules.Modules{mod})
|
|
|
|
return v
|
|
}
|
|
|
|
func newTestContentSpec() *ContentSpec {
|
|
v := config.New()
|
|
spec, err := NewContentSpec(v, loggers.NewErrorLogger(), afero.NewMemMapFs())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return spec
|
|
}
|