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

Function TestWrappers

transport/transport_test.go:349–401  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

347}
348
349func TestWrappers(t *testing.T) {
350 resp1 := &http.Response{}
351 wrapperResp1 := func(rt http.RoundTripper) http.RoundTripper {
352 return &fakeRoundTripper{Resp: resp1}
353 }
354 resp2 := &http.Response{}
355 wrapperResp2 := func(rt http.RoundTripper) http.RoundTripper {
356 return &fakeRoundTripper{Resp: resp2}
357 }
358
359 tests := []struct {
360 name string
361 fns []WrapperFunc
362 wantNil bool
363 want func(*http.Response) bool
364 }{
365 {fns: []WrapperFunc{}, wantNil: true},
366 {fns: []WrapperFunc{nil, nil}, wantNil: true},
367 {fns: []WrapperFunc{nil}, wantNil: false},
368
369 {fns: []WrapperFunc{nil, wrapperResp1}, want: func(resp *http.Response) bool { return resp == resp1 }},
370 {fns: []WrapperFunc{wrapperResp1, nil}, want: func(resp *http.Response) bool { return resp == resp1 }},
371 {fns: []WrapperFunc{nil, wrapperResp1, nil}, want: func(resp *http.Response) bool { return resp == resp1 }},
372 {fns: []WrapperFunc{nil, wrapperResp1, wrapperResp2}, want: func(resp *http.Response) bool { return resp == resp2 }},
373 {fns: []WrapperFunc{wrapperResp1, wrapperResp2}, want: func(resp *http.Response) bool { return resp == resp2 }},
374 {fns: []WrapperFunc{wrapperResp2, wrapperResp1}, want: func(resp *http.Response) bool { return resp == resp1 }},
375
376 {fns: []WrapperFunc{testChain("1")}, want: func(resp *http.Response) bool { return resp.Header.Get("Value") == "1" }},
377 {fns: []WrapperFunc{testChain("1"), testChain("2")}, want: func(resp *http.Response) bool { return resp.Header.Get("Value") == "12" }},
378 {fns: []WrapperFunc{testChain("2"), testChain("1")}, want: func(resp *http.Response) bool { return resp.Header.Get("Value") == "21" }},
379 {fns: []WrapperFunc{testChain("1"), testChain("2"), testChain("3")}, want: func(resp *http.Response) bool { return resp.Header.Get("Value") == "123" }},
380 }
381 for _, tt := range tests {
382 t.Run(tt.name, func(t *testing.T) {
383 got := Wrappers(tt.fns...)
384 if got == nil != tt.wantNil {
385 t.Errorf("Wrappers() = %v", got)
386 return
387 }
388 if got == nil {
389 return
390 }
391
392 rt := &fakeRoundTripper{Resp: &http.Response{}}
393 nested := got(rt)
394 req := &http.Request{}
395 resp, _ := nested.RoundTrip(req)
396 if tt.want != nil && !tt.want(resp) {
397 t.Errorf("unexpected response: %#v", resp)
398 }
399 })
400 }
401}
402
403func Test_contextCanceller_RoundTrip(t *testing.T) {
404 tests := []struct {

Callers

nothing calls this directly

Calls 6

testChainFunction · 0.85
WrappersFunction · 0.85
GetMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65
RoundTripMethod · 0.45

Tested by

no test coverage detected