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

Function TestDoRequestFailed

rest/client_test.go:87–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestDoRequestFailed(t *testing.T) {
88 status := &metav1.Status{
89 Code: http.StatusNotFound,
90 Status: metav1.StatusFailure,
91 Reason: metav1.StatusReasonNotFound,
92 Message: " \"\" not found",
93 Details: &metav1.StatusDetails{},
94 }
95 expectedBody, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), status)
96 fakeHandler := utiltesting.FakeHandler{
97 StatusCode: 404,
98 ResponseBody: string(expectedBody),
99 T: t,
100 }
101 testServer := httptest.NewServer(&fakeHandler)
102 defer testServer.Close()
103
104 c, err := restClient(testServer)
105 if err != nil {
106 t.Fatalf("unexpected error: %v", err)
107 }
108 err = c.Get().Do().Error()
109 if err == nil {
110 t.Errorf("unexpected non-error")
111 }
112 ss, ok := err.(errors.APIStatus)
113 if !ok {
114 t.Errorf("unexpected error type %v", err)
115 }
116 actual := ss.Status()
117 if !reflect.DeepEqual(status, &actual) {
118 t.Errorf("Unexpected mis-match: %s", diff.ObjectReflectDiff(status, &actual))
119 }
120}
121
122func TestDoRawRequestFailed(t *testing.T) {
123 status := &metav1.Status{

Callers

nothing calls this directly

Calls 7

restClientFunction · 0.85
CloseMethod · 0.65
ErrorMethod · 0.65
DoMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65
EncodeMethod · 0.45

Tested by

no test coverage detected