aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/testhelpers_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2021-06-09 10:58:18 +0200
committerBjørn Erik Pedersen <[email protected]>2021-06-14 17:00:32 +0200
commitd392893cd73dc00c927f342778f6dca9628d328e (patch)
treee2ea3eec09f36b7122ecdbc498c3c130e240e85c /hugolib/testhelpers_test.go
parenta886dd53b80322e1edf924f2ede4d4ea037c5baf (diff)
downloadhugo-d392893cd73dc00c927f342778f6dca9628d328e.tar.gz
hugo-d392893cd73dc00c927f342778f6dca9628d328e.zip
Misc config loading fixes
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
Diffstat (limited to 'hugolib/testhelpers_test.go')
-rw-r--r--hugolib/testhelpers_test.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go
index 09988f972..451022e5c 100644
--- a/hugolib/testhelpers_test.go
+++ b/hugolib/testhelpers_test.go
@@ -30,6 +30,7 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/gohugoio/hugo/common/herrors"
+ "github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/resources/page"
@@ -39,7 +40,6 @@ import (
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/tpl"
- "github.com/spf13/viper"
"github.com/gohugoio/hugo/resources/resource"
@@ -83,7 +83,7 @@ type sitesBuilder struct {
// Default toml
configFormat string
configFileSet bool
- viperSet bool
+ configSet bool
// Default is empty.
// TODO(bep) revisit this and consider always setting it to something.
@@ -111,7 +111,7 @@ type filenameContent struct {
}
func newTestSitesBuilder(t testing.TB) *sitesBuilder {
- v := viper.New()
+ v := config.New()
fs := hugofs.NewMem(v)
litterOptions := litter.Options{
@@ -140,7 +140,7 @@ func newTestSitesBuilderFromDepsCfg(t testing.TB, d deps.DepsCfg) *sitesBuilder
b.WithWorkingDir(workingDir)
- return b.WithViper(d.Cfg.(*viper.Viper))
+ return b.WithViper(d.Cfg.(config.Provider))
}
func (s *sitesBuilder) Running() *sitesBuilder {
@@ -186,26 +186,26 @@ func (s *sitesBuilder) WithConfigTemplate(data interface{}, format, configTempla
return s.WithConfigFile(format, b.String())
}
-func (s *sitesBuilder) WithViper(v *viper.Viper) *sitesBuilder {
+func (s *sitesBuilder) WithViper(v config.Provider) *sitesBuilder {
s.T.Helper()
if s.configFileSet {
s.T.Fatal("WithViper: use Viper or config.toml, not both")
}
defer func() {
- s.viperSet = true
+ s.configSet = true
}()
// Write to a config file to make sure the tests follow the same code path.
var buff bytes.Buffer
- m := v.AllSettings()
+ m := v.Get("").(maps.Params)
s.Assert(parser.InterfaceToConfig(m, metadecoders.TOML, &buff), qt.IsNil)
return s.WithConfigFile("toml", buff.String())
}
func (s *sitesBuilder) WithConfigFile(format, conf string) *sitesBuilder {
s.T.Helper()
- if s.viperSet {
- s.T.Fatal("WithConfigFile: use Viper or config.toml, not both")
+ if s.configSet {
+ s.T.Fatal("WithConfigFile: use config.Config or config.toml, not both")
}
s.configFileSet = true
filename := s.absFilename("config." + format)
@@ -845,14 +845,14 @@ func (th testHelper) replaceDefaultContentLanguageValue(value string) string {
return value
}
-func loadTestConfig(fs afero.Fs, withConfig ...func(cfg config.Provider) error) (*viper.Viper, error) {
+func loadTestConfig(fs afero.Fs, withConfig ...func(cfg config.Provider) error) (config.Provider, error) {
v, _, err := LoadConfig(ConfigSourceDescriptor{Fs: fs}, withConfig...)
return v, err
}
-func newTestCfgBasic() (*viper.Viper, *hugofs.Fs) {
+func newTestCfgBasic() (config.Provider, *hugofs.Fs) {
mm := afero.NewMemMapFs()
- v := viper.New()
+ v := config.New()
v.Set("defaultContentLanguageInSubdir", true)
fs := hugofs.NewFrom(hugofs.NewBaseFileDecorator(mm), v)
@@ -860,7 +860,7 @@ func newTestCfgBasic() (*viper.Viper, *hugofs.Fs) {
return v, fs
}
-func newTestCfg(withConfig ...func(cfg config.Provider) error) (*viper.Viper, *hugofs.Fs) {
+func newTestCfg(withConfig ...func(cfg config.Provider) error) (config.Provider, *hugofs.Fs) {
mm := afero.NewMemMapFs()
v, err := loadTestConfig(mm, func(cfg config.Provider) error {