(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func 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 | } |
nothing calls this directly
no test coverage detected