| 47 | } |
| 48 | |
| 49 | func TestAddFlag(t *testing.T) { |
| 50 | t.Parallel() |
| 51 | |
| 52 | tests := []struct { |
| 53 | name string |
| 54 | input string |
| 55 | want []string |
| 56 | }{ |
| 57 | { |
| 58 | name: "not passed", |
| 59 | input: "", |
| 60 | want: []string{}, |
| 61 | }, |
| 62 | { |
| 63 | name: "one file", |
| 64 | input: "--attach ./login.png", |
| 65 | want: []string{"./login.png"}, |
| 66 | }, |
| 67 | { |
| 68 | name: "repeated, in the order written", |
| 69 | input: "--attach './login.png#FIRST' --attach ./error-state.png", |
| 70 | want: []string{"./login.png#FIRST", "./error-state.png"}, |
| 71 | }, |
| 72 | { |
| 73 | name: "a comma is part of the filename", |
| 74 | input: "--attach './before,after.png'", |
| 75 | want: []string{"./before,after.png"}, |
| 76 | }, |
| 77 | } |
| 78 | |
| 79 | for _, tt := range tests { |
| 80 | t.Run(tt.name, func(t *testing.T) { |
| 81 | t.Parallel() |
| 82 | |
| 83 | // Given a command with the repeatable attachment flag |
| 84 | cmd, attachFlag := attachCmd(t, tt.input) |
| 85 | |
| 86 | // When the parsed flag values are read |
| 87 | values, err := cmd.Flags().GetStringArray("attach") |
| 88 | |
| 89 | // Then values retain their spelling and order |
| 90 | require.NoError(t, err) |
| 91 | assert.Equal(t, tt.want, values) |
| 92 | assert.Equal(t, tt.input != "", attachFlag.Changed(), "Changed reports whether --attach was supplied") |
| 93 | flag := cmd.Flags().Lookup("attach") |
| 94 | assert.Empty(t, flag.Shorthand) |
| 95 | assert.Equal(t, "Attach an image or video `file`, in '<file>#<image alt text>' format", flag.Usage) |
| 96 | }) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | func TestAttachmentTelemetry(t *testing.T) { |
| 101 | t.Parallel() |