MCPcopy
hub / github.com/spf13/viper / TestFlagShadow

Function TestFlagShadow

viper_test.go:2625–2642  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2623}
2624
2625func TestFlagShadow(t *testing.T) {
2626 v := New()
2627
2628 v.SetDefault("foo.bar1.bar2", "default")
2629
2630 flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
2631 flags.String("foo.bar1", "shadowed", "")
2632 flags.VisitAll(func(flag *pflag.Flag) {
2633 flag.Changed = true
2634 })
2635
2636 v.BindPFlags(flags)
2637
2638 assert.Equal(t, "shadowed", v.GetString("foo.bar1"))
2639 // the default "foo.bar1.bar2" value should shadowed by flag "foo.bar1" value
2640 // and should return an empty string
2641 assert.Equal(t, "", v.GetString("foo.bar1.bar2"))
2642}
2643
2644func BenchmarkGetBool(b *testing.B) {
2645 key := "BenchmarkGetBool"

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
SetDefaultMethod · 0.80
StringMethod · 0.80
BindPFlagsMethod · 0.80
GetStringMethod · 0.80
VisitAllMethod · 0.65

Tested by

no test coverage detected