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