MCPcopy
hub / github.com/moby/moby / TestContainerWaitErrorHandling

Function TestContainerWaitErrorHandling

client/container_wait_test.go:128–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func 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}

Callers

nothing calls this directly

Calls 10

WithMockClientFunction · 0.85
CheckMethod · 0.80
EqualMethod · 0.80
ErrorfMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
RunMethod · 0.65
ContextMethod · 0.65
ContainerWaitMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…