summaryrefslogtreecommitdiffstats
path: root/hugolib/config_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-15 15:31:50 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-15 16:15:32 +0200
commitae6cf93c84c3584b111f4b9fa3fb4e3f63d37915 (patch)
tree3dc0411801105a70d20ab426cbf7df62b9979815 /hugolib/config_test.go
parenta70da2b74a6af0834cce9668cdb6acdb1c86a4c0 (diff)
Fix default values when loading from config dir
By waiting until we've loaded the config dir config before applying the default values. Fixes #8763
Diffstat (limited to 'hugolib/config_test.go')
-rw-r--r--hugolib/config_test.go53
1 files changed, 40 insertions, 13 deletions
diff --git a/hugolib/config_test.go b/hugolib/config_test.go
index 6de274717..575931975 100644
--- a/hugolib/config_test.go
+++ b/hugolib/config_test.go
@@ -20,6 +20,8 @@ import (
"strings"
"testing"
+ "github.com/gohugoio/hugo/config"
+
"github.com/gohugoio/hugo/media"
"github.com/google/go-cmp/cmp"
@@ -29,24 +31,49 @@ import (
)
func TestLoadConfig(t *testing.T) {
- t.Parallel()
c := qt.New(t)
- // Add a random config variable for testing.
- // side = page in Norwegian.
- configContent := `
- PaginatePath = "side"
- `
-
- mm := afero.NewMemMapFs()
-
- writeToFs(t, mm, "hugo.toml", configContent)
+ loadConfig := func(c *qt.C, configContent string, fromDir bool) config.Provider {
+ mm := afero.NewMemMapFs()
+ filename := "config.toml"
+ descriptor := ConfigSourceDescriptor{Fs: mm}
+ if fromDir {
+ filename = filepath.Join("config", "_default", filename)
+ descriptor.AbsConfigDir = "config"
+ }
+ writeToFs(t, mm, filename, configContent)
+ cfg, _, err := LoadConfig(descriptor)
+ c.Assert(err, qt.IsNil)
+ return cfg
+ }
- cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Filename: "hugo.toml"})
- c.Assert(err, qt.IsNil)
+ c.Run("Basic", func(c *qt.C) {
+ c.Parallel()
+ // Add a random config variable for testing.
+ // side = page in Norwegian.
+ cfg := loadConfig(c, `PaginatePath = "side"`, false)
+ c.Assert(cfg.GetString("paginatePath"), qt.Equals, "side")
+ })
- c.Assert(cfg.GetString("paginatePath"), qt.Equals, "side")
+ // Issue #8763
+ for _, fromDir := range []bool{false, true} {
+ testName := "Taxonomy overrides"
+ if fromDir {
+ testName += " from dir"
+ }
+ c.Run(testName, func(c *qt.C) {
+ c.Parallel()
+ cfg := loadConfig(c, `[taxonomies]
+appellation = "appellations"
+vigneron = "vignerons"`, fromDir)
+
+ c.Assert(cfg.Get("taxonomies"), qt.DeepEquals, maps.Params{
+ "appellation": "appellations",
+ "vigneron": "vignerons",
+ })
+ })
+ }
}
func TestLoadMultiConfig(t *testing.T) {