mirror of
https://github.com/spf13/viper
synced 2024-12-23 03:57:01 +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
b7a3b95476
commit
cc7e906d88
1 changed files with 9 additions and 1 deletions
|
@ -613,6 +613,8 @@ func TestBindPFlags(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBindPFlagsStringSlice(t *testing.T) {
|
func TestBindPFlagsStringSlice(t *testing.T) {
|
||||||
|
defaultVal := []string{"default"}
|
||||||
|
|
||||||
for _, testValue := range []struct {
|
for _, testValue := range []struct {
|
||||||
Expected []string
|
Expected []string
|
||||||
Value string
|
Value string
|
||||||
|
@ -624,6 +626,8 @@ func TestBindPFlagsStringSlice(t *testing.T) {
|
||||||
|
|
||||||
for _, changed := range []bool{true, false} {
|
for _, changed := range []bool{true, false} {
|
||||||
v := New() // create independent Viper object
|
v := New() // create independent Viper object
|
||||||
|
v.SetDefault("stringslice", defaultVal)
|
||||||
|
|
||||||
flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||||
flagSet.StringSlice("stringslice", testValue.Expected, "test")
|
flagSet.StringSlice("stringslice", testValue.Expected, "test")
|
||||||
flagSet.Visit(func(f *pflag.Flag) {
|
flagSet.Visit(func(f *pflag.Flag) {
|
||||||
|
@ -645,7 +649,11 @@ func TestBindPFlagsStringSlice(t *testing.T) {
|
||||||
if err := v.Unmarshal(val); err != nil {
|
if err := v.Unmarshal(val); err != nil {
|
||||||
t.Fatalf("%+#v cannot unmarshal: %s", testValue.Value, err)
|
t.Fatalf("%+#v cannot unmarshal: %s", testValue.Value, err)
|
||||||
}
|
}
|
||||||
|
if changed {
|
||||||
assert.Equal(t, testValue.Expected, val.StringSlice)
|
assert.Equal(t, testValue.Expected, val.StringSlice)
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, defaultVal, val.StringSlice)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue