Skip to content

Commit

Permalink
Add test for slice with nil as default.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaholaz committed May 13, 2024
1 parent 79e1254 commit 5ed8fd1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,28 @@ func TestMultipleDefinitions(t *testing.T) {
t.Fatalf("Should not be allowed to redefine a key.")
}
}

func TestSliceWithNilAsDefault(t *testing.T) {
type Config struct {
Foo []string
}

config := Config{
Foo: nil,
}
err := LoadConfig("test_configs/multipledefinitions.cfg", &config)
if err != nil {
t.Fatalf("Could not parse config with string slice with nil default correctly: %s", err.Error())
}

want := Config{
Foo: []string{"bar", "baz"},
}
if !reflect.DeepEqual(want, config) {
t.Fatalf(`
Could not parse config with string slice with nil default.
expected: %#v
got: %#v`, want, config)
}

}

0 comments on commit 5ed8fd1

Please sign in to comment.