mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-03 19:30:54 -04:00
config: Increase test coverage
This commit is contained in:
parent
e77b2ad8fd
commit
266d46dccc
@ -14,6 +14,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -32,3 +33,13 @@ func TestIsValidConfigFileName(t *testing.T) {
|
|||||||
c.Assert(IsValidConfigFilename(""), qt.Equals, false)
|
c.Assert(IsValidConfigFilename(""), qt.Equals, false)
|
||||||
c.Assert(IsValidConfigFilename("config.toml.swp"), qt.Equals, false)
|
c.Assert(IsValidConfigFilename("config.toml.swp"), qt.Equals, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFromTOMLConfigString(t *testing.T) {
|
||||||
|
c := qt.New(t)
|
||||||
|
|
||||||
|
c.Assert(
|
||||||
|
func() { FromTOMLConfigString("cfg") },
|
||||||
|
qt.PanicMatches,
|
||||||
|
regexp.MustCompile("_stream.toml:.*"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -353,6 +354,90 @@ func TestDefaultConfigProvider(t *testing.T) {
|
|||||||
|
|
||||||
c.Assert(r.Wait(), qt.IsNil)
|
c.Assert(r.Wait(), qt.IsNil)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
c.Run("GetBool", func(c *qt.C) {
|
||||||
|
cfg := New()
|
||||||
|
|
||||||
|
var k string
|
||||||
|
var v bool
|
||||||
|
|
||||||
|
k, v = "foo", true
|
||||||
|
|
||||||
|
cfg.Set(k, v)
|
||||||
|
c.Assert(cfg.Get(k), qt.Equals, v)
|
||||||
|
c.Assert(cfg.GetBool(k), qt.Equals, v)
|
||||||
|
})
|
||||||
|
|
||||||
|
c.Run("GetParams", func(c *qt.C) {
|
||||||
|
cfg := New()
|
||||||
|
k := "foo"
|
||||||
|
|
||||||
|
cfg.Set(k, maps.Params{k: true})
|
||||||
|
c.Assert(cfg.GetParams(k), qt.DeepEquals, maps.Params{
|
||||||
|
k: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
c.Assert(cfg.GetParams("bar"), qt.IsNil)
|
||||||
|
})
|
||||||
|
|
||||||
|
c.Run("Keys", func(c *qt.C) {
|
||||||
|
cfg := New()
|
||||||
|
k := "foo"
|
||||||
|
k2 := "bar"
|
||||||
|
|
||||||
|
cfg.Set(k, maps.Params{k: struct{}{}})
|
||||||
|
cfg.Set(k2, maps.Params{k2: struct{}{}})
|
||||||
|
|
||||||
|
c.Assert(len(cfg.Keys()), qt.Equals, 2)
|
||||||
|
|
||||||
|
got := cfg.Keys()
|
||||||
|
slices.Sort(got)
|
||||||
|
|
||||||
|
want := []string{k, k2}
|
||||||
|
slices.Sort(want)
|
||||||
|
|
||||||
|
c.Assert(got, qt.DeepEquals, want)
|
||||||
|
})
|
||||||
|
|
||||||
|
c.Run("WalkParams", func(c *qt.C) {
|
||||||
|
cfg := New()
|
||||||
|
|
||||||
|
cfg.Set("x", maps.Params{})
|
||||||
|
cfg.Set("y", maps.Params{})
|
||||||
|
|
||||||
|
var got []string
|
||||||
|
cfg.WalkParams(func(params ...maps.KeyParams) bool {
|
||||||
|
got = append(got, params[len(params)-1].Key)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
want := []string{"", "x", "y"}
|
||||||
|
slices.Sort(got)
|
||||||
|
slices.Sort(want)
|
||||||
|
|
||||||
|
c.Assert(got, qt.DeepEquals, want)
|
||||||
|
|
||||||
|
cfg = New()
|
||||||
|
cfg.WalkParams(func(params ...maps.KeyParams) bool {
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
got = []string{""}
|
||||||
|
want = []string{""}
|
||||||
|
c.Assert(got, qt.DeepEquals, want)
|
||||||
|
})
|
||||||
|
|
||||||
|
c.Run("SetDefaults", func(c *qt.C) {
|
||||||
|
cfg := New()
|
||||||
|
|
||||||
|
cfg.SetDefaults(maps.Params{
|
||||||
|
"foo": "bar",
|
||||||
|
"bar": "baz",
|
||||||
|
})
|
||||||
|
|
||||||
|
c.Assert(cfg.Get("foo"), qt.Equals, "bar")
|
||||||
|
c.Assert(cfg.Get("bar"), qt.Equals, "baz")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkDefaultConfigProvider(b *testing.B) {
|
func BenchmarkDefaultConfigProvider(b *testing.B) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user