diff options
Diffstat (limited to 'config/configProvider.go')
-rw-r--r-- | config/configProvider.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/config/configProvider.go b/config/configProvider.go index 471ce9a1d..335294d73 100644 --- a/config/configProvider.go +++ b/config/configProvider.go @@ -13,6 +13,12 @@ package config +import ( + "strings" + + "github.com/spf13/viper" +) + // Provider provides the configuration settings for Hugo. type Provider interface { GetString(key string) string @@ -25,3 +31,14 @@ type Provider interface { Set(key string, value interface{}) IsSet(key string) bool } + +// FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests. +func FromConfigString(config, configType string) (Provider, error) { + v := viper.New() + v.SetConfigType(configType) + if err := v.ReadConfig(strings.NewReader(config)); err != nil { + return nil, err + } + return v, nil + +} |