From d392893cd73dc00c927f342778f6dca9628d328e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 9 Jun 2021 10:58:18 +0200 Subject: 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 --- markup/asciidocext/convert_test.go | 18 +++++++++--------- markup/blackfriday/convert_test.go | 6 +++--- markup/highlight/config_test.go | 5 ++--- markup/markup_config/config.go | 3 +-- markup/markup_config/config_test.go | 6 +++--- markup/markup_test.go | 8 +++----- markup/mmark/convert_test.go | 4 ++-- markup/org/convert_test.go | 5 +++-- 8 files changed, 26 insertions(+), 29 deletions(-) (limited to 'markup') diff --git a/markup/asciidocext/convert_test.go b/markup/asciidocext/convert_test.go index 4c183f7bb..14110bb04 100644 --- a/markup/asciidocext/convert_test.go +++ b/markup/asciidocext/convert_test.go @@ -22,17 +22,17 @@ import ( "testing" "github.com/gohugoio/hugo/common/loggers" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/markup/converter" "github.com/gohugoio/hugo/markup/markup_config" "github.com/gohugoio/hugo/markup/tableofcontents" - "github.com/spf13/viper" qt "github.com/frankban/quicktest" ) func TestAsciidoctorDefaultArgs(t *testing.T) { c := qt.New(t) - cfg := viper.New() + cfg := config.New() mconf := markup_config.Default p, err := Provider.New( @@ -57,7 +57,7 @@ func TestAsciidoctorDefaultArgs(t *testing.T) { func TestAsciidoctorNonDefaultArgs(t *testing.T) { c := qt.New(t) - cfg := viper.New() + cfg := config.New() mconf := markup_config.Default mconf.AsciidocExt.Backend = "manpage" mconf.AsciidocExt.NoHeaderOrFooter = false @@ -88,7 +88,7 @@ func TestAsciidoctorNonDefaultArgs(t *testing.T) { func TestAsciidoctorDisallowedArgs(t *testing.T) { c := qt.New(t) - cfg := viper.New() + cfg := config.New() mconf := markup_config.Default mconf.AsciidocExt.Backend = "disallowed-backend" mconf.AsciidocExt.Extensions = []string{"./disallowed-extension"} @@ -117,7 +117,7 @@ func TestAsciidoctorDisallowedArgs(t *testing.T) { func TestAsciidoctorArbitraryExtension(t *testing.T) { c := qt.New(t) - cfg := viper.New() + cfg := config.New() mconf := markup_config.Default mconf.AsciidocExt.Extensions = []string{"arbitrary-extension"} p, err := Provider.New( @@ -142,7 +142,7 @@ func TestAsciidoctorArbitraryExtension(t *testing.T) { func TestAsciidoctorDisallowedExtension(t *testing.T) { c := qt.New(t) - cfg := viper.New() + cfg := config.New() for _, disallowedExtension := range []string{ `foo-bar//`, `foo-bar\\ `, @@ -177,7 +177,7 @@ func TestAsciidoctorDisallowedExtension(t *testing.T) { func TestAsciidoctorWorkingFolderCurrent(t *testing.T) { c := qt.New(t) - cfg := viper.New() + cfg := config.New() mconf := markup_config.Default mconf.AsciidocExt.WorkingFolderCurrent = true mconf.AsciidocExt.Trace = false @@ -208,7 +208,7 @@ func TestAsciidoctorWorkingFolderCurrent(t *testing.T) { func TestAsciidoctorWorkingFolderCurrentAndExtensions(t *testing.T) { c := qt.New(t) - cfg := viper.New() + cfg := config.New() mconf := markup_config.Default mconf.AsciidocExt.NoHeaderOrFooter = true mconf.AsciidocExt.Extensions = []string{"asciidoctor-html5s", "asciidoctor-diagram"} @@ -247,7 +247,7 @@ func TestAsciidoctorWorkingFolderCurrentAndExtensions(t *testing.T) { func TestAsciidoctorAttributes(t *testing.T) { c := qt.New(t) - cfg := viper.New() + cfg := config.New() mconf := markup_config.Default mconf.AsciidocExt.Attributes = map[string]string{"my-base-url": "https://gohugo.io/", "my-attribute-name": "my value"} mconf.AsciidocExt.Trace = false diff --git a/markup/blackfriday/convert_test.go b/markup/blackfriday/convert_test.go index 414905a76..5b1c1a71f 100644 --- a/markup/blackfriday/convert_test.go +++ b/markup/blackfriday/convert_test.go @@ -16,7 +16,7 @@ package blackfriday import ( "testing" - "github.com/spf13/viper" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/markup/converter" @@ -140,7 +140,7 @@ func TestGetAllFlags(t *testing.T) { func TestConvert(t *testing.T) { c := qt.New(t) p, err := Provider.New(converter.ProviderConfig{ - Cfg: viper.New(), + Cfg: config.New(), }) c.Assert(err, qt.IsNil) conv, err := p.New(converter.DocumentContext{}) @@ -153,7 +153,7 @@ func TestConvert(t *testing.T) { func TestGetHTMLRendererAnchors(t *testing.T) { c := qt.New(t) p, err := Provider.New(converter.ProviderConfig{ - Cfg: viper.New(), + Cfg: config.New(), }) c.Assert(err, qt.IsNil) conv, err := p.New(converter.DocumentContext{ diff --git a/markup/highlight/config_test.go b/markup/highlight/config_test.go index 3c3747622..ab92ecf36 100644 --- a/markup/highlight/config_test.go +++ b/markup/highlight/config_test.go @@ -17,16 +17,15 @@ package highlight import ( "testing" - "github.com/spf13/viper" - qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/config" ) func TestConfig(t *testing.T) { c := qt.New(t) c.Run("applyLegacyConfig", func(c *qt.C) { - v := viper.New() + v := config.New() v.Set("pygmentsStyle", "hugo") v.Set("pygmentsUseClasses", false) v.Set("pygmentsCodeFences", false) diff --git a/markup/markup_config/config.go b/markup/markup_config/config.go index a3562cd24..d4a101709 100644 --- a/markup/markup_config/config.go +++ b/markup/markup_config/config.go @@ -24,7 +24,6 @@ import ( "github.com/gohugoio/hugo/markup/tableofcontents" "github.com/gohugoio/hugo/parser" "github.com/mitchellh/mapstructure" - "github.com/spf13/cast" ) type Config struct { @@ -73,7 +72,7 @@ func normalizeConfig(m map[string]interface{}) { if err != nil { return } - vm := cast.ToStringMap(v) + vm := maps.ToStringMap(v) // Changed from a bool in 0.81.0 if vv, found := vm["attribute"]; found { if vvb, ok := vv.(bool); ok { diff --git a/markup/markup_config/config_test.go b/markup/markup_config/config_test.go index 4a1f1232b..08d7b5995 100644 --- a/markup/markup_config/config_test.go +++ b/markup/markup_config/config_test.go @@ -16,7 +16,7 @@ package markup_config import ( "testing" - "github.com/spf13/viper" + "github.com/gohugoio/hugo/config" qt "github.com/frankban/quicktest" ) @@ -26,7 +26,7 @@ func TestConfig(t *testing.T) { c.Run("Decode", func(c *qt.C) { c.Parallel() - v := viper.New() + v := config.New() v.Set("markup", map[string]interface{}{ "goldmark": map[string]interface{}{ @@ -55,7 +55,7 @@ func TestConfig(t *testing.T) { c.Run("legacy", func(c *qt.C) { c.Parallel() - v := viper.New() + v := config.New() v.Set("blackfriday", map[string]interface{}{ "angledQuotes": true, diff --git a/markup/markup_test.go b/markup/markup_test.go index 6e7fe2059..71d39075d 100644 --- a/markup/markup_test.go +++ b/markup/markup_test.go @@ -16,17 +16,15 @@ package markup import ( "testing" - "github.com/spf13/viper" - - "github.com/gohugoio/hugo/markup/converter" - qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/config" + "github.com/gohugoio/hugo/markup/converter" ) func TestConverterRegistry(t *testing.T) { c := qt.New(t) - r, err := NewConverterProvider(converter.ProviderConfig{Cfg: viper.New()}) + r, err := NewConverterProvider(converter.ProviderConfig{Cfg: config.New()}) c.Assert(err, qt.IsNil) c.Assert("goldmark", qt.Equals, r.GetMarkupConfig().DefaultMarkdownHandler) diff --git a/markup/mmark/convert_test.go b/markup/mmark/convert_test.go index 01d3e8cbb..414e023ab 100644 --- a/markup/mmark/convert_test.go +++ b/markup/mmark/convert_test.go @@ -16,7 +16,7 @@ package mmark import ( "testing" - "github.com/spf13/viper" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/common/loggers" @@ -62,7 +62,7 @@ func TestGetMmarkExtensions(t *testing.T) { func TestConvert(t *testing.T) { c := qt.New(t) - p, err := Provider.New(converter.ProviderConfig{Cfg: viper.New(), Logger: loggers.NewErrorLogger()}) + p, err := Provider.New(converter.ProviderConfig{Cfg: config.New(), Logger: loggers.NewErrorLogger()}) c.Assert(err, qt.IsNil) conv, err := p.New(converter.DocumentContext{}) c.Assert(err, qt.IsNil) diff --git a/markup/org/convert_test.go b/markup/org/convert_test.go index 96c388457..e3676fc34 100644 --- a/markup/org/convert_test.go +++ b/markup/org/convert_test.go @@ -16,8 +16,9 @@ package org import ( "testing" + "github.com/gohugoio/hugo/config" + "github.com/gohugoio/hugo/common/loggers" - "github.com/spf13/viper" "github.com/gohugoio/hugo/markup/converter" @@ -28,7 +29,7 @@ func TestConvert(t *testing.T) { c := qt.New(t) p, err := Provider.New(converter.ProviderConfig{ Logger: loggers.NewErrorLogger(), - Cfg: viper.New(), + Cfg: config.New(), }) c.Assert(err, qt.IsNil) conv, err := p.New(converter.DocumentContext{}) -- cgit v1.2.3