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

Function TestTransformResponseNegotiate

rest/request_test.go:599–737  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

597}
598
599func TestTransformResponseNegotiate(t *testing.T) {
600 invalid := []byte("aaaaa")
601 uri, _ := url.Parse("http://localhost")
602 testCases := []struct {
603 Response *http.Response
604 Data []byte
605 Created bool
606 Error bool
607 ErrFn func(err error) bool
608
609 ContentType string
610 Called bool
611 ExpectContentType string
612 Decoder runtime.Decoder
613 NegotiateErr error
614 }{
615 {
616 ContentType: "application/json",
617 Response: &http.Response{
618 StatusCode: 401,
619 Header: http.Header{"Content-Type": []string{"application/json"}},
620 Body: ioutil.NopCloser(bytes.NewReader(invalid)),
621 },
622 Error: true,
623 ErrFn: func(err error) bool {
624 return err.Error() != "aaaaa" && apierrors.IsUnauthorized(err)
625 },
626 },
627 {
628 ContentType: "application/json",
629 Response: &http.Response{
630 StatusCode: 401,
631 Header: http.Header{"Content-Type": []string{"application/protobuf"}},
632 Body: ioutil.NopCloser(bytes.NewReader(invalid)),
633 },
634 Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
635
636 Called: true,
637 ExpectContentType: "application/protobuf",
638
639 Error: true,
640 ErrFn: func(err error) bool {
641 return err.Error() != "aaaaa" && apierrors.IsUnauthorized(err)
642 },
643 },
644 {
645 ContentType: "application/json",
646 Response: &http.Response{
647 StatusCode: 500,
648 Header: http.Header{"Content-Type": []string{"application/,others"}},
649 },
650 Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
651
652 Error: true,
653 ErrFn: func(err error) bool {
654 return err.Error() == "Internal error occurred: mime: expected token after slash" && err.(apierrors.APIStatus).Status().Code == 500
655 },
656 },

Callers

nothing calls this directly

Calls 7

transformResponseMethod · 0.95
defaultSerializersFunction · 0.85
defaultContentConfigFunction · 0.85
NewRequestFunction · 0.85
ErrorMethod · 0.65
ErrorfMethod · 0.65
ParseMethod · 0.45

Tested by

no test coverage detected