(t *testing.T)
| 143 | } |
| 144 | |
| 145 | func TestFlagUserAssets(t *testing.T) { |
| 146 | tests := []struct { |
| 147 | name string |
| 148 | setup func(t *testing.T) |
| 149 | input string |
| 150 | wantPaths []string |
| 151 | wantAlts []string |
| 152 | wantErr string |
| 153 | // wantErrIs covers an error whose text the operating system words |
| 154 | // differently, so the assertion cannot be on the message. |
| 155 | wantErrIs error |
| 156 | }{ |
| 157 | { |
| 158 | name: "not passed", |
| 159 | input: "", |
| 160 | }, |
| 161 | { |
| 162 | name: "one file", |
| 163 | input: "--attach ./shot.png", |
| 164 | wantPaths: []string{"./shot.png"}, |
| 165 | }, |
| 166 | { |
| 167 | name: "a filename containing a hash stays whole", |
| 168 | input: "--attach './shot#dark.png'", |
| 169 | wantPaths: []string{"./shot#dark.png"}, |
| 170 | wantAlts: []string{"shot#dark"}, |
| 171 | }, |
| 172 | { |
| 173 | name: "alt text can contain a hash", |
| 174 | input: "--attach './caption.png#first#second'", |
| 175 | wantPaths: []string{"./caption.png"}, |
| 176 | wantAlts: []string{"first#second"}, |
| 177 | }, |
| 178 | { |
| 179 | name: "the longest existing path wins", |
| 180 | input: "--attach './shot#dark.png#first.png#second'", |
| 181 | wantPaths: []string{"./shot#dark.png#first.png"}, |
| 182 | wantAlts: []string{"second"}, |
| 183 | }, |
| 184 | { |
| 185 | name: "a missing path falls back at the last hash", |
| 186 | input: "--attach './gone.png#caption'", |
| 187 | wantErr: "./gone.png: ", |
| 188 | wantErrIs: fs.ErrNotExist, |
| 189 | }, |
| 190 | { |
| 191 | name: "several files, in the order written", |
| 192 | input: "--attach ./b.png --attach ./a.png", |
| 193 | wantPaths: []string{"./b.png", "./a.png"}, |
| 194 | }, |
| 195 | { |
| 196 | name: "too many attachments are rejected before filesystem validation", |
| 197 | input: strings.Repeat("--attach ./missing.txt ", maxAttachments+1), |
| 198 | wantErr: "`--attach` accepts at most 50 values per command", |
| 199 | }, |
| 200 | { |
| 201 | name: "a file that does not exist", |
| 202 | input: "--attach ./gone.png", |
nothing calls this directly
no test coverage detected