Skip to content

Commit

Permalink
add unit tests to cover edge cases
Browse files Browse the repository at this point in the history
JSON treats int array as float64 array, this tests checks that there is
no issue between type conversions in Load Merge.
  • Loading branch information
grount authored and Daniel Gront committed Feb 22, 2021
1 parent 77c5ac0 commit 008754c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions koanf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,56 @@ func TestLoadFileAllKeys(t *testing.T) {
}
}

func TestLoadMergeYamlJson(t *testing.T) {
var (
assert = assert.New(t)
k = koanf.New(delim)
)

assert.NoError(k.Load(file.Provider(mockYAML), yaml.Parser()),
"error loading file")
// loading json after yaml causes the intbools to be loaded as []float64
assert.NoError(k.Load(file.Provider(mockJSON), yaml.Parser()),
"error loading file")

// checking that there is no issues with expecting it to be an []int64
v := k.Int64s("intbools")
assert.Len(v, 3)

defer func() {
if err := recover(); err != nil {
assert.Failf("panic", "received panic: %v", err)
}
}()

v2 := k.MustInt64s("intbools")
assert.Len(v2, 3)
}

func TestLoadMergeJsonYaml(t *testing.T) {
var (
assert = assert.New(t)
k = koanf.New(delim)
)

assert.NoError(k.Load(file.Provider(mockJSON), yaml.Parser()),
"error loading file")
assert.NoError(k.Load(file.Provider(mockYAML), yaml.Parser()),
"error loading file")

v := k.Float64s("intbools")
assert.Len(v, 3)

defer func() {
if err := recover(); err != nil {
assert.Failf("panic", "received panic: %v", err)
}
}()

v2 := k.MustFloat64s("intbools")
assert.Len(v2, 3)
}

func TestWatchFile(t *testing.T) {
var (
assert = assert.New(t)
Expand Down

0 comments on commit 008754c

Please sign in to comment.