| 48 | } |
| 49 | |
| 50 | func TestAddFlag(t *testing.T) { |
| 51 | tests := []struct { |
| 52 | name string |
| 53 | input string |
| 54 | want []string |
| 55 | }{ |
| 56 | { |
| 57 | name: "not passed", |
| 58 | input: "", |
| 59 | want: []string{}, |
| 60 | }, |
| 61 | { |
| 62 | name: "one file", |
| 63 | input: "--attach ./login.png", |
| 64 | want: []string{"./login.png"}, |
| 65 | }, |
| 66 | { |
| 67 | name: "repeated, in the order written", |
| 68 | input: "--attach './login.png#FIRST' --attach ./error-state.png", |
| 69 | want: []string{"./login.png#FIRST", "./error-state.png"}, |
| 70 | }, |
| 71 | { |
| 72 | name: "a comma is part of the filename", |
| 73 | input: "--attach './before,after.png'", |
| 74 | want: []string{"./before,after.png"}, |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | for _, tt := range tests { |
| 79 | t.Run(tt.name, func(t *testing.T) { |
| 80 | cmd, attachFlag := attachCmd(t, tt.input) |
| 81 | |
| 82 | slice, ok := attachFlag.flag.Value.(pflag.SliceValue) |
| 83 | require.True(t, ok) |
| 84 | assert.Equal(t, tt.want, slice.GetSlice()) |
| 85 | assert.Equal(t, tt.input != "", attachFlag.Changed()) |
| 86 | assert.Empty(t, attachFlag.flag.Shorthand) |
| 87 | assert.Equal(t, "Attach an image or video `file`, in '<file>#<image alt text>' format", attachFlag.flag.Usage) |
| 88 | assert.Same(t, attachFlag.flag, cmd.Flags().Lookup(flagName)) |
| 89 | }) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | func TestFlagRecordTelemetry(t *testing.T) { |
| 94 | tests := []struct { |