MCPcopy
hub / github.com/grpc/grpc-go / TestStringWithAllowedValues

Method TestStringWithAllowedValues

benchmark/flags/flags_test.go:38–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36}
37
38func (s) TestStringWithAllowedValues(t *testing.T) {
39 const defaultVal = "default"
40 tests := []struct {
41 args string
42 allowed []string
43 wantVal string
44 wantErr bool
45 }{
46 {"-workloads=all", []string{"unary", "streaming", "all"}, "all", false},
47 {"-workloads=disallowed", []string{"unary", "streaming", "all"}, defaultVal, true},
48 }
49
50 for _, test := range tests {
51 flag.CommandLine = flag.NewFlagSet("test", flag.ContinueOnError)
52 var w = StringWithAllowedValues("workloads", defaultVal, "usage", test.allowed)
53 err := flag.CommandLine.Parse([]string{test.args})
54 switch {
55 case !test.wantErr && err != nil:
56 t.Errorf("failed to parse command line args {%v}: %v", test.args, err)
57 case test.wantErr && err == nil:
58 t.Errorf("flag.Parse(%v) = nil, want non-nil error", test.args)
59 default:
60 if *w != test.wantVal {
61 t.Errorf("flag value is %v, want %v", *w, test.wantVal)
62 }
63 }
64 }
65}
66
67func (s) TestDurationSlice(t *testing.T) {
68 defaultVal := []time.Duration{time.Second, time.Nanosecond}

Callers

nothing calls this directly

Calls 3

StringWithAllowedValuesFunction · 0.85
ParseMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected