mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Fix fake handler so it can be used for more than one call.
This commit is contained in:
parent
3737b4e4e2
commit
b6a260940c
@ -166,7 +166,7 @@ func TestDoRequest(t *testing.T) {
|
||||
if body != expectedBody {
|
||||
t.Errorf("Expected body: '%s', saw: '%s'", expectedBody, body)
|
||||
}
|
||||
fakeHandler.ValidateRequest(t, "/foo/bar", "GET", &fakeHandler.ResponseBody)
|
||||
fakeHandler.ValidateRequest(t, "/foo/bar", "GET", nil)
|
||||
}
|
||||
|
||||
func TestRunController(t *testing.T) {
|
||||
|
@ -32,6 +32,7 @@ type LogInterface interface {
|
||||
// FakeHandler is to assist in testing HTTP requests.
|
||||
type FakeHandler struct {
|
||||
RequestReceived *http.Request
|
||||
RequestBody string
|
||||
StatusCode int
|
||||
ResponseBody string
|
||||
// For logging - you can use a *testing.T
|
||||
@ -48,7 +49,7 @@ func (f *FakeHandler) ServeHTTP(response http.ResponseWriter, request *http.Requ
|
||||
if err != nil && f.T != nil {
|
||||
f.T.Logf("Received read error: %#v", err)
|
||||
}
|
||||
f.ResponseBody = string(bodyReceived)
|
||||
f.RequestBody = string(bodyReceived)
|
||||
}
|
||||
|
||||
func (f FakeHandler) ValidateRequest(t TestInterface, expectedPath, expectedMethod string, body *string) {
|
||||
@ -59,8 +60,8 @@ func (f FakeHandler) ValidateRequest(t TestInterface, expectedPath, expectedMeth
|
||||
t.Errorf("Unexpected method: %s", f.RequestReceived.Method)
|
||||
}
|
||||
if body != nil {
|
||||
if *body != f.ResponseBody {
|
||||
t.Errorf("Received body:\n%s\n Doesn't match expected body:\n%s", f.ResponseBody, *body)
|
||||
if *body != f.RequestBody {
|
||||
t.Errorf("Received body:\n%s\n Doesn't match expected body:\n%s", f.RequestBody, *body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user