(t *testing.T)
| 126 | } |
| 127 | |
| 128 | func TestContainerWaitErrorHandling(t *testing.T) { |
| 129 | for _, test := range []struct { |
| 130 | name string |
| 131 | rdr io.Reader |
| 132 | exp error |
| 133 | }{ |
| 134 | {name: "invalid json", rdr: strings.NewReader(`{]`), exp: errors.New("{]")}, |
| 135 | {name: "context canceled", rdr: iotest.ErrReader(context.Canceled), exp: context.Canceled}, |
| 136 | {name: "context deadline exceeded", rdr: iotest.ErrReader(context.DeadlineExceeded), exp: context.DeadlineExceeded}, |
| 137 | {name: "connection reset", rdr: iotest.ErrReader(syscall.ECONNRESET), exp: syscall.ECONNRESET}, |
| 138 | } { |
| 139 | t.Run(test.name, func(t *testing.T) { |
| 140 | ctx, cancel := context.WithCancel(t.Context()) |
| 141 | defer cancel() |
| 142 | |
| 143 | client, err := New(WithMockClient(func(req *http.Request) (*http.Response, error) { |
| 144 | return &http.Response{ |
| 145 | StatusCode: http.StatusOK, |
| 146 | Body: io.NopCloser(test.rdr), |
| 147 | }, nil |
| 148 | })) |
| 149 | assert.NilError(t, err) |
| 150 | wait := client.ContainerWait(ctx, "container_id", ContainerWaitOptions{}) |
| 151 | select { |
| 152 | case err := <-wait.Error: |
| 153 | assert.Check(t, is.Equal(err.Error(), test.exp.Error())) |
| 154 | return |
| 155 | case result := <-wait.Result: |
| 156 | t.Errorf("expected to not get a wait result, got %d", result.StatusCode) |
| 157 | return |
| 158 | } |
| 159 | // Unexpected - we should not reach this line |
| 160 | }) |
| 161 | } |
| 162 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…