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

Function TestBindPFlags

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

Source from the content-addressed store, hash-verified

1090}
1091
1092func TestBindPFlags(t *testing.T) {
1093 v := New() // create independent Viper object
1094 flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
1095
1096 testValues := map[string]*string{
1097 "host": nil,
1098 "port": nil,
1099 "endpoint": nil,
1100 }
1101
1102 mutatedTestValues := map[string]string{
1103 "host": "localhost",
1104 "port": "6060",
1105 "endpoint": "/public",
1106 }
1107
1108 for name := range testValues {
1109 testValues[name] = flagSet.String(name, "", "test")
1110 }
1111
1112 err := v.BindPFlags(flagSet)
1113 require.NoError(t, err, "error binding flag set")
1114
1115 flagSet.VisitAll(func(flag *pflag.Flag) {
1116 flag.Value.Set(mutatedTestValues[flag.Name])
1117 flag.Changed = true
1118 })
1119
1120 for name, expected := range mutatedTestValues {
1121 assert.Equal(t, expected, v.Get(name))
1122 }
1123}
1124
1125func TestBindPFlagsStringSlice(t *testing.T) {
1126 tests := []struct {

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
StringMethod · 0.80
BindPFlagsMethod · 0.80
VisitAllMethod · 0.65
GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected