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

Method ValidateRequest

util/testing/fake_handler.go:109–139  ·  view source on GitHub ↗

ValidateRequest verifies that FakeHandler received a request with expected path, method, and body.

(t TestInterface, expectedPath, expectedMethod string, body *string)

Source from the content-addressed store, hash-verified

107
108// ValidateRequest verifies that FakeHandler received a request with expected path, method, and body.
109func (f *FakeHandler) ValidateRequest(t TestInterface, expectedPath, expectedMethod string, body *string) {
110 f.lock.Lock()
111 defer f.lock.Unlock()
112 if f.requestCount != 1 {
113 t.Logf("Expected 1 call, but got %v. Only the last call is recorded and checked.", f.requestCount)
114 }
115 f.hasBeenChecked = true
116
117 expectURL, err := url.Parse(expectedPath)
118 if err != nil {
119 t.Errorf("Couldn't parse %v as a URL.", expectedPath)
120 }
121 if f.RequestReceived == nil {
122 t.Errorf("Unexpected nil request received for %s", expectedPath)
123 return
124 }
125 if f.RequestReceived.URL.Path != expectURL.Path {
126 t.Errorf("Unexpected request path for request %#v, received: %q, expected: %q", f.RequestReceived, f.RequestReceived.URL.Path, expectURL.Path)
127 }
128 if e, a := expectURL.Query(), f.RequestReceived.URL.Query(); !reflect.DeepEqual(e, a) {
129 t.Errorf("Unexpected query for request %#v, received: %q, expected: %q", f.RequestReceived, a, e)
130 }
131 if f.RequestReceived.Method != expectedMethod {
132 t.Errorf("Unexpected method: %q, expected: %q", f.RequestReceived.Method, expectedMethod)
133 }
134 if body != nil {
135 if *body != f.RequestBody {
136 t.Errorf("Received body:\n%s\n Doesn't match expected body:\n%s", f.RequestBody, *body)
137 }
138 }
139}

Callers 12

TestDoRequestNewWayFunction · 0.95
TestDoRequestNewWayObjFunction · 0.95
TestDoRequestNewWayFileFunction · 0.95
TestWasCreatedFunction · 0.95
TestFakeHandlerPathFunction · 0.95
TestFakeHandlerWrongPathFunction · 0.95
TestFakeHandlerWrongBodyFunction · 0.95
TestFakeHandlerNilBodyFunction · 0.95
validateFunction · 0.80

Calls 3

LogfMethod · 0.65
ErrorfMethod · 0.65
ParseMethod · 0.45

Tested by 12

TestDoRequestNewWayFunction · 0.76
TestDoRequestNewWayObjFunction · 0.76
TestDoRequestNewWayFileFunction · 0.76
TestWasCreatedFunction · 0.76
TestFakeHandlerPathFunction · 0.76
TestFakeHandlerWrongPathFunction · 0.76
TestFakeHandlerWrongBodyFunction · 0.76
TestFakeHandlerNilBodyFunction · 0.76
validateFunction · 0.64