Skip to content

Commit

Permalink
[confmaptest] Add a test on empty slice to nil (#10966)
Browse files Browse the repository at this point in the history
#### Description

Add a test on empty slices being sanitized to `nil` in `ToStringMap`
  • Loading branch information
songy23 committed Aug 26, 2024
1 parent a80ce1a commit bca56c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions confmap/confmaptest/configtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func TestLoadConf(t *testing.T) {
assert.Equal(t, map[string]any{"floating": 3.14}, cfg.ToStringMap())
}

func TestToStringMapSanitizeEmptySlice(t *testing.T) {
cfg, err := LoadConf(filepath.Join("testdata", "empty-slice.yaml"))
require.NoError(t, err)
var nilSlice []interface{}
assert.Equal(t, map[string]any{"slice": nilSlice}, cfg.ToStringMap())
}

func TestValidateProviderScheme(t *testing.T) {
assert.NoError(t, ValidateProviderScheme(&schemeProvider{scheme: "file"}))
assert.NoError(t, ValidateProviderScheme(&schemeProvider{scheme: "s3"}))
Expand Down
1 change: 1 addition & 0 deletions confmap/confmaptest/testdata/empty-slice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
slice: [] # empty slices are sanitized to nil in ToStringMap

0 comments on commit bca56c4

Please sign in to comment.