From b6a260940c7661baea30599c5f5ad370de3c9633 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Tue, 17 Jun 2014 17:36:27 -0700 Subject: [PATCH] Fix fake handler so it can be used for more than one call. --- pkg/cloudcfg/cloudcfg_test.go | 2 +- pkg/util/fake_handler.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/cloudcfg/cloudcfg_test.go b/pkg/cloudcfg/cloudcfg_test.go index 7b0142e7282..de23e61216b 100644 --- a/pkg/cloudcfg/cloudcfg_test.go +++ b/pkg/cloudcfg/cloudcfg_test.go @@ -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) { diff --git a/pkg/util/fake_handler.go b/pkg/util/fake_handler.go index f6b4adb7253..94936a69993 100644 --- a/pkg/util/fake_handler.go +++ b/pkg/util/fake_handler.go @@ -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) } } }