Skip to content

Commit 266d46d

Browse files
pixel365bep
authored andcommitted
config: Increase test coverage
1 parent e77b2ad commit 266d46d

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

config/configLoader_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package config
1515

1616
import (
17+
"regexp"
1718
"strings"
1819
"testing"
1920

@@ -32,3 +33,13 @@ func TestIsValidConfigFileName(t *testing.T) {
3233
c.Assert(IsValidConfigFilename(""), qt.Equals, false)
3334
c.Assert(IsValidConfigFilename("config.toml.swp"), qt.Equals, false)
3435
}
36+
37+
func TestFromTOMLConfigString(t *testing.T) {
38+
c := qt.New(t)
39+
40+
c.Assert(
41+
func() { FromTOMLConfigString("cfg") },
42+
qt.PanicMatches,
43+
regexp.MustCompile("_stream.toml:.*"),
44+
)
45+
}

config/defaultConfigProvider_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"context"
1818
"errors"
1919
"fmt"
20+
"slices"
2021
"strconv"
2122
"strings"
2223
"testing"
@@ -353,6 +354,90 @@ func TestDefaultConfigProvider(t *testing.T) {
353354

354355
c.Assert(r.Wait(), qt.IsNil)
355356
})
357+
358+
c.Run("GetBool", func(c *qt.C) {
359+
cfg := New()
360+
361+
var k string
362+
var v bool
363+
364+
k, v = "foo", true
365+
366+
cfg.Set(k, v)
367+
c.Assert(cfg.Get(k), qt.Equals, v)
368+
c.Assert(cfg.GetBool(k), qt.Equals, v)
369+
})
370+
371+
c.Run("GetParams", func(c *qt.C) {
372+
cfg := New()
373+
k := "foo"
374+
375+
cfg.Set(k, maps.Params{k: true})
376+
c.Assert(cfg.GetParams(k), qt.DeepEquals, maps.Params{
377+
k: true,
378+
})
379+
380+
c.Assert(cfg.GetParams("bar"), qt.IsNil)
381+
})
382+
383+
c.Run("Keys", func(c *qt.C) {
384+
cfg := New()
385+
k := "foo"
386+
k2 := "bar"
387+
388+
cfg.Set(k, maps.Params{k: struct{}{}})
389+
cfg.Set(k2, maps.Params{k2: struct{}{}})
390+
391+
c.Assert(len(cfg.Keys()), qt.Equals, 2)
392+
393+
got := cfg.Keys()
394+
slices.Sort(got)
395+
396+
want := []string{k, k2}
397+
slices.Sort(want)
398+
399+
c.Assert(got, qt.DeepEquals, want)
400+
})
401+
402+
c.Run("WalkParams", func(c *qt.C) {
403+
cfg := New()
404+
405+
cfg.Set("x", maps.Params{})
406+
cfg.Set("y", maps.Params{})
407+
408+
var got []string
409+
cfg.WalkParams(func(params ...maps.KeyParams) bool {
410+
got = append(got, params[len(params)-1].Key)
411+
return false
412+
})
413+
414+
want := []string{"", "x", "y"}
415+
slices.Sort(got)
416+
slices.Sort(want)
417+
418+
c.Assert(got, qt.DeepEquals, want)
419+
420+
cfg = New()
421+
cfg.WalkParams(func(params ...maps.KeyParams) bool {
422+
return true
423+
})
424+
425+
got = []string{""}
426+
want = []string{""}
427+
c.Assert(got, qt.DeepEquals, want)
428+
})
429+
430+
c.Run("SetDefaults", func(c *qt.C) {
431+
cfg := New()
432+
433+
cfg.SetDefaults(maps.Params{
434+
"foo": "bar",
435+
"bar": "baz",
436+
})
437+
438+
c.Assert(cfg.Get("foo"), qt.Equals, "bar")
439+
c.Assert(cfg.Get("bar"), qt.Equals, "baz")
440+
})
356441
}
357442

358443
func BenchmarkDefaultConfigProvider(b *testing.B) {

0 commit comments

Comments
 (0)