(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func Test_FlagValuesMap(t *testing.T) { |
| 11 | flagSet := pflag.NewFlagSet("test", pflag.ContinueOnError) |
| 12 | flagSet.String("string", "", "") |
| 13 | flagSet.Int("int", 0, "") |
| 14 | flagSet.Bool("bool", false, "") |
| 15 | flagSet.Float64("float64", 0.0, "") |
| 16 | flagSet.StringSlice("stringSlice", []string{}, "") |
| 17 | flagSet.IntSlice("intSlice", []int{}, "") |
| 18 | flagSet.BoolSlice("boolSlice", []bool{}, "") |
| 19 | flagSet.Float64Slice("float64Slice", []float64{}, "") |
| 20 | flagSet.Var(&JSONValue{}, "json", "") |
| 21 | |
| 22 | _ = flagSet.Set("string", "string") |
| 23 | _ = flagSet.Set("int", "1") |
| 24 | _ = flagSet.Set("bool", "true") |
| 25 | _ = flagSet.Set("float64", "1.0") |
| 26 | _ = flagSet.Set("stringSlice", "string") |
| 27 | _ = flagSet.Set("intSlice", "1") |
| 28 | _ = flagSet.Set("boolSlice", "true") |
| 29 | _ = flagSet.Set("float64Slice", "1.0") |
| 30 | _ = flagSet.Set("json", `["json"]`) |
| 31 | |
| 32 | flagValuesMap, err := FlagValuesMap(flagSet) |
| 33 | if err != nil { |
| 34 | t.Errorf("unexpected error: %v", err) |
| 35 | } |
| 36 | |
| 37 | assert.Equal(t, "string", flagValuesMap["string"]) |
| 38 | assert.Equal(t, 1, flagValuesMap["int"]) |
| 39 | assert.Equal(t, true, flagValuesMap["bool"]) |
| 40 | assert.Equal(t, 1.0, flagValuesMap["float64"]) |
| 41 | assert.Equal(t, []string{"string"}, flagValuesMap["stringSlice"]) |
| 42 | assert.Equal(t, []int{1}, flagValuesMap["intSlice"]) |
| 43 | assert.Equal(t, []bool{true}, flagValuesMap["boolSlice"]) |
| 44 | assert.Equal(t, []float64{1.0}, flagValuesMap["float64Slice"]) |
| 45 | assert.Equal(t, []interface{}{"json"}, flagValuesMap["json"]) |
| 46 | } |
nothing calls this directly
no test coverage detected