MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / TestStringArrayFlag

Function TestStringArrayFlag

utilities/string_array_flag_test.go:11–50  ·  utilities/string_array_flag_test.go::TestStringArrayFlag
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestStringArrayFlag(t *testing.T) {
12 tests := []struct {
13 name string
14 flags []string
15 want string
16 }{
17 {
18 name: "No Value",
19 flags: []string{},
20 want: "",
21 },
22 {
23 name: "Single Value",
24 flags: []string{"--my_flag=1"},
25 want: "1",
26 },
27 {
28 name: "Repeated Value",
29 flags: []string{"--my_flag=1", "--my_flag=2"},
30 want: "1,2",
31 },
32 {
33 name: "Repeated Same Value",
34 flags: []string{"--my_flag=1", "--my_flag=1"},
35 want: "1,1",
36 },
37 }
38 for _, tt := range tests {
39 t.Run(tt.name, func(t *testing.T) {
40 flagSet := flag.NewFlagSet("test", flag.PanicOnError)
41 result := utilities.StringArrayFlag(flagSet, "my_flag", "repeated flag")
42 if err := flagSet.Parse(tt.flags); err != nil {
43 t.Errorf("flagSet.Parse() failed with %v", err)
44 }
45 if !reflect.DeepEqual(result.String(), tt.want) {
46 t.Errorf("StringArrayFlag() = %v, want %v", result.String(), tt.want)
47 }
48 })
49 }
50}

Callers

nothing calls this directly

Calls 3

StringArrayFlagFunction · 0.92
ParseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected