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

Method TestIntSlice

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

Source from the content-addressed store, hash-verified

94}
95
96func (s) TestIntSlice(t *testing.T) {
97 defaultVal := []int{1, 1024}
98 tests := []struct {
99 args string
100 wantVal []int
101 wantErr bool
102 }{
103 {"-kbps=1", []int{1}, false},
104 {"-kbps=1,2,3", []int{1, 2, 3}, false},
105 {"-kbps=20e4", defaultVal, true},
106 }
107
108 for _, test := range tests {
109 flag.CommandLine = flag.NewFlagSet("test", flag.ContinueOnError)
110 var w = IntSlice("kbps", defaultVal, "usage")
111 err := flag.CommandLine.Parse([]string{test.args})
112 switch {
113 case !test.wantErr && err != nil:
114 t.Errorf("failed to parse command line args {%v}: %v", test.args, err)
115 case test.wantErr && err == nil:
116 t.Errorf("flag.Parse(%v) = nil, want non-nil error", test.args)
117 default:
118 if !reflect.DeepEqual(*w, test.wantVal) {
119 t.Errorf("flag value is %v, want %v", *w, test.wantVal)
120 }
121 }
122 }
123}
124
125func (s) TestStringSlice(t *testing.T) {
126 defaultVal := []string{"bar", "baz"}

Callers

nothing calls this directly

Calls 3

IntSliceFunction · 0.85
ParseMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected