(t *testing.T)
| 370 | } |
| 371 | |
| 372 | func TestNewUploader(t *testing.T) { |
| 373 | const badPermissionErr = "attaching files requires write access to the repository" |
| 374 | |
| 375 | tests := []struct { |
| 376 | name string |
| 377 | host string |
| 378 | targetRepository int64 |
| 379 | viewerPermission string |
| 380 | wantErr string |
| 381 | }{ |
| 382 | { |
| 383 | name: "github.com", |
| 384 | host: "github.com", |
| 385 | targetRepository: 42, |
| 386 | viewerPermission: "WRITE", |
| 387 | }, |
| 388 | { |
| 389 | name: "data residency tenant", |
| 390 | host: "acme.ghe.com", |
| 391 | targetRepository: 7, |
| 392 | viewerPermission: "WRITE", |
| 393 | }, |
| 394 | { |
| 395 | name: "rejects an enterprise server host", |
| 396 | host: "github.example.com", |
| 397 | targetRepository: 42, |
| 398 | viewerPermission: "WRITE", |
| 399 | wantErr: "attaching files is not supported on GitHub Enterprise Server", |
| 400 | }, |
| 401 | { |
| 402 | // This row defends a message, not an order. On an enterprise server |
| 403 | // the permission message would tell the user to get write access, |
| 404 | // and that remedy does not work there. The other checks are free to |
| 405 | // move. |
| 406 | name: "reports the host before the permission", |
| 407 | host: "github.example.com", |
| 408 | targetRepository: 42, |
| 409 | viewerPermission: "READ", |
| 410 | wantErr: "attaching files is not supported on GitHub Enterprise Server", |
| 411 | }, |
| 412 | { |
| 413 | // A caller that never fetched the id hands over a zero, and an |
| 414 | // upload cannot be taken back, so it stops before the endpoint. |
| 415 | name: "rejects an unresolved target", |
| 416 | host: "github.com", |
| 417 | targetRepository: 0, |
| 418 | viewerPermission: "WRITE", |
| 419 | wantErr: "could not determine which repository to attach files to", |
| 420 | }, |
| 421 | { |
| 422 | name: "rejects a negative target", |
| 423 | host: "github.com", |
| 424 | targetRepository: -1, |
| 425 | viewerPermission: "WRITE", |
| 426 | wantErr: "could not determine which repository to attach files to", |
| 427 | }, |
| 428 | { |
| 429 | name: "admin permission", |
nothing calls this directly
no test coverage detected