mirror of
https://github.com/spf13/viper
synced 2025-05-07 20:57:18 +00:00
add an unit test for flag shadow
This commit is contained in:
parent
ebcc662f66
commit
f76910fe8d
1 changed files with 19 additions and 0 deletions
|
@ -2704,6 +2704,25 @@ func TestIsPathShadowedInFlatMap(t *testing.T) {
|
||||||
assert.Equal(t, expected2, v.isPathShadowedInFlatMap(path2, flagMap))
|
assert.Equal(t, expected2, v.isPathShadowedInFlatMap(path2, flagMap))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFlagShadow(t *testing.T) {
|
||||||
|
v := New()
|
||||||
|
|
||||||
|
v.SetDefault("foo.bar1.bar2", "default")
|
||||||
|
|
||||||
|
flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||||
|
flags.String("foo.bar1", "shadowed", "")
|
||||||
|
flags.VisitAll(func(flag *pflag.Flag) {
|
||||||
|
flag.Changed = true
|
||||||
|
})
|
||||||
|
|
||||||
|
v.BindPFlags(flags)
|
||||||
|
|
||||||
|
assert.Equal(t, "shadowed", v.GetString("foo.bar1"))
|
||||||
|
// the default "foo.bar1.bar2" value should shadowed by flag "foo.bar1" value
|
||||||
|
// and should return an empty string
|
||||||
|
assert.Equal(t, "", v.GetString("foo.bar1.bar2"))
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkGetBool(b *testing.B) {
|
func BenchmarkGetBool(b *testing.B) {
|
||||||
key := "BenchmarkGetBool"
|
key := "BenchmarkGetBool"
|
||||||
v = New()
|
v = New()
|
||||||
|
|
Loading…
Add table
Reference in a new issue