New set of tests to test new error cases
(t *testing.T)
| 543 | |
| 544 | // New set of tests to test new error cases |
| 545 | func TestDockerFetcherOpen(t *testing.T) { |
| 546 | tests := []struct { |
| 547 | name string |
| 548 | mockedStatus int |
| 549 | mockedErr error |
| 550 | want io.ReadCloser |
| 551 | wantErr bool |
| 552 | wantServerMessageError bool |
| 553 | wantPlainError bool |
| 554 | retries int |
| 555 | lastHost bool |
| 556 | }{ |
| 557 | { |
| 558 | name: "should return status and error.message if it exists if the registry request fails", |
| 559 | mockedStatus: http.StatusInternalServerError, |
| 560 | mockedErr: Errors{Error{ |
| 561 | Code: ErrorCodeUnknown, |
| 562 | Message: "Test Error", |
| 563 | }}, |
| 564 | want: nil, |
| 565 | wantErr: true, |
| 566 | wantServerMessageError: true, |
| 567 | lastHost: false, |
| 568 | }, |
| 569 | { |
| 570 | name: "should return just status if the registry request fails and does not return a docker error", |
| 571 | mockedStatus: http.StatusInternalServerError, |
| 572 | mockedErr: errors.New("Non-docker error"), |
| 573 | want: nil, |
| 574 | wantErr: true, |
| 575 | wantPlainError: true, |
| 576 | lastHost: false, |
| 577 | }, { |
| 578 | name: "should return StatusRequestTimeout after exhausting attempts", |
| 579 | mockedStatus: http.StatusRequestTimeout, |
| 580 | mockedErr: errors.New(http.StatusText(http.StatusRequestTimeout)), |
| 581 | want: nil, |
| 582 | wantErr: true, |
| 583 | wantPlainError: true, |
| 584 | retries: maxAttempts - 1, |
| 585 | lastHost: true, |
| 586 | }, { |
| 587 | name: "should return StatusTooManyRequests after exhausting attempts", |
| 588 | mockedStatus: http.StatusTooManyRequests, |
| 589 | mockedErr: errors.New(http.StatusText(http.StatusTooManyRequests)), |
| 590 | want: nil, |
| 591 | wantErr: true, |
| 592 | wantPlainError: true, |
| 593 | retries: maxAttempts - 1, |
| 594 | lastHost: true, |
| 595 | }, |
| 596 | { |
| 597 | name: "should retry once after 500", |
| 598 | mockedStatus: http.StatusInternalServerError, |
| 599 | mockedErr: Errors{Error{ |
| 600 | Code: ErrorCodeUnknown, |
| 601 | Message: "Test Error", |
| 602 | }}, |
nothing calls this directly
no test coverage detected
searching dependent graphs…