MCPcopy
hub / github.com/kubernetes/client-go / TestV2ErrorStreamReading

Function TestV2ErrorStreamReading

tools/remotecommand/v2_test.go:180–228  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func TestV2ErrorStreamReading(t *testing.T) {
181 tests := []struct {
182 name string
183 stream io.Reader
184 expectedError error
185 }{
186 {
187 name: "error reading from stream",
188 stream: &fakeReader{errors.New("foo")},
189 expectedError: errors.New("error reading from error stream: foo"),
190 },
191 {
192 name: "stream returns an error",
193 stream: strings.NewReader("some error"),
194 expectedError: errors.New("error executing remote command: some error"),
195 },
196 }
197
198 for _, test := range tests {
199 h := newStreamProtocolV2(StreamOptions{}).(*streamProtocolV2)
200 h.errorStream = test.stream
201
202 ch := watchErrorStream(h.errorStream, &errorDecoderV2{})
203 if ch == nil {
204 t.Fatalf("%s: unexpected nil channel", test.name)
205 }
206
207 var err error
208 select {
209 case err = <-ch:
210 case <-time.After(wait.ForeverTestTimeout):
211 t.Fatalf("%s: timed out", test.name)
212 }
213
214 if test.expectedError != nil {
215 if err == nil {
216 t.Errorf("%s: expected an error", test.name)
217 } else if e, a := test.expectedError, err; e.Error() != a.Error() {
218 t.Errorf("%s: expected %q, got %q", test.name, e, a)
219 }
220 continue
221 }
222
223 if test.expectedError == nil && err != nil {
224 t.Errorf("%s: unexpected error: %v", test.name, err)
225 continue
226 }
227 }
228}

Callers

nothing calls this directly

Calls 4

newStreamProtocolV2Function · 0.85
watchErrorStreamFunction · 0.85
ErrorfMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected