(t *testing.T)
| 523 | } |
| 524 | |
| 525 | func TestDelete(t *testing.T) { |
| 526 | tests := []struct { |
| 527 | name string |
| 528 | repo ghrepo.Interface |
| 529 | number int |
| 530 | response httpmock.Responder |
| 531 | wantURL string |
| 532 | wantErr string |
| 533 | }{ |
| 534 | // A successful delete can get 204 No Content, or 200 with the deleted |
| 535 | // artifact's number. |
| 536 | { |
| 537 | name: "deletes the artifact when the API answers 204 No Content", |
| 538 | repo: ghrepo.New("monalisa", "monas-cafe"), |
| 539 | number: 5, |
| 540 | response: httpmock.StatusStringResponse(204, ""), |
| 541 | wantURL: "https://api.github.com/repos/monalisa/monas-cafe/issues/142/artifacts/5", |
| 542 | }, |
| 543 | { |
| 544 | name: "deletes the artifact when the API answers 200 with its number", |
| 545 | repo: ghrepo.New("monalisa", "monas-cafe"), |
| 546 | number: 7, |
| 547 | response: httpmock.StringResponse(`{"number":7,"deleted":true}`), |
| 548 | wantURL: "https://api.github.com/repos/monalisa/monas-cafe/issues/142/artifacts/7", |
| 549 | }, |
| 550 | { |
| 551 | name: "a repository on a ghe.com host", |
| 552 | repo: ghrepo.NewWithHost("monalisa", "monas-cafe", "monas-cafe.ghe.com"), |
| 553 | number: 5, |
| 554 | response: httpmock.StatusStringResponse(204, ""), |
| 555 | wantURL: "https://api.monas-cafe.ghe.com/repos/monalisa/monas-cafe/issues/142/artifacts/5", |
| 556 | }, |
| 557 | { |
| 558 | name: "an API error is returned as the API gives it", |
| 559 | repo: ghrepo.New("monalisa", "monas-cafe"), |
| 560 | number: 9, |
| 561 | response: httpmock.StatusJSONResponse(404, map[string]string{"message": "Not Found"}), |
| 562 | wantURL: "https://api.github.com/repos/monalisa/monas-cafe/issues/142/artifacts/9", |
| 563 | wantErr: "HTTP 404: Not Found (https://api.github.com/repos/monalisa/monas-cafe/issues/142/artifacts/9)", |
| 564 | }, |
| 565 | } |
| 566 | |
| 567 | for _, tt := range tests { |
| 568 | t.Run(tt.name, func(t *testing.T) { |
| 569 | reg := &httpmock.Registry{} |
| 570 | defer reg.Verify(t) |
| 571 | reg.Register(httpmock.REST("DELETE", fmt.Sprintf("repos/monalisa/monas-cafe/issues/142/artifacts/%d", tt.number)), tt.response) |
| 572 | |
| 573 | c := NewArtifactClient(&http.Client{Transport: reg}) |
| 574 | err := c.Delete(tt.repo, 142, tt.number) |
| 575 | |
| 576 | require.Len(t, reg.Requests, 1) |
| 577 | assert.Equal(t, tt.wantURL, reg.Requests[0].URL.String()) |
| 578 | if tt.wantErr != "" { |
| 579 | require.EqualError(t, err, tt.wantErr) |
| 580 | return |
| 581 | } |
| 582 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected