From bca56c4e66f94a04243852db3195a7c9c7aa98dc Mon Sep 17 00:00:00 2001 From: Yang Song Date: Mon, 26 Aug 2024 19:22:03 -0400 Subject: [PATCH] [confmaptest] Add a test on empty slice to nil (#10966) #### Description Add a test on empty slices being sanitized to `nil` in `ToStringMap` --- confmap/confmaptest/configtest_test.go | 7 +++++++ confmap/confmaptest/testdata/empty-slice.yaml | 1 + 2 files changed, 8 insertions(+) create mode 100644 confmap/confmaptest/testdata/empty-slice.yaml diff --git a/confmap/confmaptest/configtest_test.go b/confmap/confmaptest/configtest_test.go index 151a1c9275a..34d97d6b009 100644 --- a/confmap/confmaptest/configtest_test.go +++ b/confmap/confmaptest/configtest_test.go @@ -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"})) diff --git a/confmap/confmaptest/testdata/empty-slice.yaml b/confmap/confmaptest/testdata/empty-slice.yaml new file mode 100644 index 00000000000..ec9c7c062ae --- /dev/null +++ b/confmap/confmaptest/testdata/empty-slice.yaml @@ -0,0 +1 @@ +slice: [] # empty slices are sanitized to nil in ToStringMap