MCPcopy Create free account
hub / github.com/cli/cli / TestDelete

Function TestDelete

pkg/cmd/issue/artifact/client/client_test.go:525–585  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

523}
524
525func 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)

Callers

nothing calls this directly

Calls 14

VerifyMethod · 0.95
RegisterMethod · 0.95
DeleteMethod · 0.95
NewFunction · 0.92
StatusStringResponseFunction · 0.92
StringResponseFunction · 0.92
NewWithHostFunction · 0.92
StatusJSONResponseFunction · 0.92
RESTFunction · 0.92
NewArtifactClientFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected