(t *testing.T)
| 193 | } |
| 194 | |
| 195 | func TestFlagUserAssets(t *testing.T) { |
| 196 | tests := []struct { |
| 197 | name string |
| 198 | setup func(t *testing.T) |
| 199 | input string |
| 200 | wantPaths []string |
| 201 | wantAlts []string |
| 202 | wantErr string |
| 203 | // wantErrIs covers an error whose text the operating system words |
| 204 | // differently, so the assertion cannot be on the message. |
| 205 | wantErrIs error |
| 206 | }{ |
| 207 | { |
| 208 | name: "not passed", |
| 209 | input: "", |
| 210 | }, |
| 211 | { |
| 212 | name: "one file", |
| 213 | input: "--attach ./shot.png", |
| 214 | wantPaths: []string{"./shot.png"}, |
| 215 | }, |
| 216 | { |
| 217 | name: "a filename containing a hash stays whole", |
| 218 | input: "--attach './shot#dark.png'", |
| 219 | wantPaths: []string{"./shot#dark.png"}, |
| 220 | wantAlts: []string{"shot#dark"}, |
| 221 | }, |
| 222 | { |
| 223 | name: "alt text can contain a hash", |
| 224 | input: "--attach './caption.png#first#second'", |
| 225 | wantPaths: []string{"./caption.png"}, |
| 226 | wantAlts: []string{"first#second"}, |
| 227 | }, |
| 228 | { |
| 229 | name: "the longest existing path wins", |
| 230 | input: "--attach './shot#dark.png#first.png#second'", |
| 231 | wantPaths: []string{"./shot#dark.png#first.png"}, |
| 232 | wantAlts: []string{"second"}, |
| 233 | }, |
| 234 | { |
| 235 | name: "a missing path falls back at the last hash", |
| 236 | input: "--attach './gone.png#caption'", |
| 237 | wantErr: "./gone.png: ", |
| 238 | wantErrIs: fs.ErrNotExist, |
| 239 | }, |
| 240 | { |
| 241 | name: "too many attachments are rejected before filesystem validation", |
| 242 | input: strings.Repeat("--attach ./missing.txt ", maxAttachments+1), |
| 243 | wantErr: "`--attach` accepts at most 50 values per command", |
| 244 | }, |
| 245 | { |
| 246 | name: "a file that does not exist", |
| 247 | input: "--attach ./gone.png", |
| 248 | wantErr: "./gone.png: ", |
| 249 | wantErrIs: fs.ErrNotExist, |
| 250 | }, |
| 251 | { |
| 252 | // An explicitly empty value is invalid, not an absent flag. |
nothing calls this directly
no test coverage detected