(t *testing.T)
| 327 | } |
| 328 | |
| 329 | func Test_gistDelete(t *testing.T) { |
| 330 | tests := []struct { |
| 331 | name string |
| 332 | httpStubs func(*httpmock.Registry) |
| 333 | hostname string |
| 334 | gistID string |
| 335 | wantErr error |
| 336 | wantErrString string |
| 337 | }{ |
| 338 | { |
| 339 | name: "successful delete", |
| 340 | httpStubs: func(reg *httpmock.Registry) { |
| 341 | reg.Register( |
| 342 | httpmock.REST("DELETE", "gists/1234"), |
| 343 | httpmock.StatusStringResponse(204, "{}"), |
| 344 | ) |
| 345 | }, |
| 346 | hostname: "github.com", |
| 347 | gistID: "1234", |
| 348 | }, |
| 349 | { |
| 350 | name: "when a gist is not found, it returns a NotFoundError", |
| 351 | httpStubs: func(reg *httpmock.Registry) { |
| 352 | reg.Register( |
| 353 | httpmock.REST("DELETE", "gists/1234"), |
| 354 | httpmock.StatusStringResponse(404, "{}"), |
| 355 | ) |
| 356 | }, |
| 357 | hostname: "github.com", |
| 358 | gistID: "1234", |
| 359 | wantErr: shared.NotFoundErr, // To make sure we return the pre-defined error instance. |
| 360 | wantErrString: "not found", |
| 361 | }, |
| 362 | { |
| 363 | name: "when there is a non-404 error deleting the gist, that error is returned", |
| 364 | httpStubs: func(reg *httpmock.Registry) { |
| 365 | reg.Register( |
| 366 | httpmock.REST("DELETE", "gists/1234"), |
| 367 | httpmock.JSONErrorResponse(500, ghAPI.HTTPError{ |
| 368 | StatusCode: 500, |
| 369 | Message: "arbitrary error", |
| 370 | }), |
| 371 | ) |
| 372 | }, |
| 373 | hostname: "github.com", |
| 374 | gistID: "1234", |
| 375 | wantErrString: "HTTP 500: arbitrary error (https://api.github.com/gists/1234)", |
| 376 | }, |
| 377 | } |
| 378 | |
| 379 | for _, tt := range tests { |
| 380 | t.Run(tt.name, func(t *testing.T) { |
| 381 | reg := &httpmock.Registry{} |
| 382 | tt.httpStubs(reg) |
| 383 | client := api.NewClientFromHTTP(&http.Client{Transport: reg}) |
| 384 | |
| 385 | err := deleteGist(client, tt.hostname, tt.gistID) |
| 386 | if tt.wantErrString == "" && tt.wantErr == nil { |
nothing calls this directly
no test coverage detected