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

Function TestFakeHandlerWrongBody

util/testing/fake_handler_test.go:129–154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

127}
128
129func TestFakeHandlerWrongBody(t *testing.T) {
130 handler := FakeHandler{StatusCode: http.StatusOK}
131 server := httptest.NewServer(&handler)
132 defer server.Close()
133 method := "GET"
134 path := "/foo/bar"
135 body := "somebody"
136 fakeT := fakeError{}
137
138 req, err := http.NewRequest(method, server.URL+path, bytes.NewBufferString(body))
139 if err != nil {
140 t.Errorf("unexpected error: %v", err)
141 }
142
143 client := http.Client{}
144 _, err = client.Do(req)
145 if err != nil {
146 t.Errorf("unexpected error: %v", err)
147 }
148
149 otherbody := "otherbody"
150 handler.ValidateRequest(&fakeT, path, method, &otherbody)
151 if len(fakeT.errors) != 1 {
152 t.Errorf("Unexpected error set: %#v", fakeT.errors)
153 }
154}
155
156func TestFakeHandlerNilBody(t *testing.T) {
157 handler := FakeHandler{StatusCode: http.StatusOK}

Callers

nothing calls this directly

Calls 4

ValidateRequestMethod · 0.95
CloseMethod · 0.65
ErrorfMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected