mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
Updated TestBindPFlagsStringSlice() to highlight a failure
When pflag marked as changed, the value is not detected (and lower priority value used)
This commit is contained in:
parent
aafc9e6bc7
commit
148386d3bb
1 changed files with 9 additions and 1 deletions
|
@ -540,6 +540,8 @@ func TestBindPFlags(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBindPFlagsStringSlice(t *testing.T) {
|
||||
defaultVal := []string{"default"}
|
||||
|
||||
for _, testValue := range []struct {
|
||||
Expected []string
|
||||
Value string
|
||||
|
@ -551,6 +553,8 @@ func TestBindPFlagsStringSlice(t *testing.T) {
|
|||
|
||||
for _, changed := range []bool{true, false} {
|
||||
v := New() // create independent Viper object
|
||||
v.SetDefault("stringslice", defaultVal)
|
||||
|
||||
flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||
flagSet.StringSlice("stringslice", testValue.Expected, "test")
|
||||
flagSet.Visit(func(f *pflag.Flag) {
|
||||
|
@ -572,7 +576,11 @@ func TestBindPFlagsStringSlice(t *testing.T) {
|
|||
if err := v.Unmarshal(val); err != nil {
|
||||
t.Fatalf("%+#v cannot unmarshal: %s", testValue.Value, err)
|
||||
}
|
||||
assert.Equal(t, testValue.Expected, val.StringSlice)
|
||||
if changed {
|
||||
assert.Equal(t, testValue.Expected, val.StringSlice)
|
||||
} else {
|
||||
assert.Equal(t, defaultVal, val.StringSlice)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue