From 82c2ddf4930cdc9bf0451a0da937d8f3239e1222 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 30 Sep 2020 14:20:00 +0200 Subject: [PATCH] Fix tests broken by mapstructure update Mapstructure so far returned nil for empty string slices. In a recent version this bug has been fixed: https://github.com/mitchellh/mapstructure/pull/155 Incidentally, this was a bug in Viper too: GetStringSlice and Unmarshal returned with different values. Signed-off-by: Mark Sagi-Kazar --- viper_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/viper_test.go b/viper_test.go index 29a4bfb..cfcff5a 100644 --- a/viper_test.go +++ b/viper_test.go @@ -869,12 +869,13 @@ func TestBindPFlags(t *testing.T) { } } +// nolint: dupl func TestBindPFlagsStringSlice(t *testing.T) { tests := []struct { Expected []string Value string }{ - {nil, ""}, + {[]string{}, ""}, {[]string{"jeden"}, "jeden"}, {[]string{"dwa", "trzy"}, "dwa,trzy"}, {[]string{"cztery", "piec , szesc"}, "cztery,\"piec , szesc\""}, @@ -908,6 +909,7 @@ func TestBindPFlagsStringSlice(t *testing.T) { } if changed { assert.Equal(t, testValue.Expected, val.StringSlice) + assert.Equal(t, testValue.Expected, v.Get("stringslice")) } else { assert.Equal(t, defaultVal, val.StringSlice) } @@ -915,12 +917,13 @@ func TestBindPFlagsStringSlice(t *testing.T) { } } +// nolint: dupl func TestBindPFlagsIntSlice(t *testing.T) { tests := []struct { Expected []int Value string }{ - {nil, ""}, + {[]int{}, ""}, {[]int{1}, "1"}, {[]int{2, 3}, "2,3"}, } @@ -953,6 +956,7 @@ func TestBindPFlagsIntSlice(t *testing.T) { } if changed { assert.Equal(t, testValue.Expected, val.IntSlice) + assert.Equal(t, testValue.Expected, v.Get("intslice")) } else { assert.Equal(t, defaultVal, val.IntSlice) }