From 7ba54b32b3ec8e0db11ca2db2aaa67e8b19bb7f5 Mon Sep 17 00:00:00 2001 From: pancho horrillo Date: Tue, 8 Oct 2019 05:28:29 +0200 Subject: [PATCH] Revert to using strings for simplicity It is safe in this case. * gock.BodyString(body string) coerces body into a []byte * client.SetData() eventually resolves to a call to http.Client.Do(), which handles the string gracefully as well. --- internal/client/get_test.go | 2 +- internal/client/set_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/client/get_test.go b/internal/client/get_test.go index 74832ec..0772a24 100644 --- a/internal/client/get_test.go +++ b/internal/client/get_test.go @@ -13,7 +13,7 @@ func TestWriteContentToWriter(t *testing.T) { gock.New("http://localhost"). Get("/handlers/HANDLER_BAR/request/body"). Reply(http.StatusOK). - Body(bytes.NewReader([]byte("FOO"))) + BodyString("FOO") var b bytes.Buffer err := GetData("http://localhost", "HANDLER_BAR", "/request/body", &b) diff --git a/internal/client/set_test.go b/internal/client/set_test.go index 6e61c60..8e4fb50 100644 --- a/internal/client/set_test.go +++ b/internal/client/set_test.go @@ -1,8 +1,8 @@ package client_test import ( - "bytes" "net/http" + "strings" "testing" gock "gopkg.in/h2non/gock.v1" @@ -21,7 +21,7 @@ func TestSetDataSuccessOnCorrectRequest(t *testing.T) { "http://localhost:8080", "HANDLER_FOO", "/response/status/code", - bytes.NewReader([]byte("200")), + strings.NewReader("200"), ); err != nil { t.Error("Unexpected error") } @@ -42,7 +42,7 @@ func TestSetDataErrIfBadHandlerID(t *testing.T) { "http://localhost:8080", "HANDLER_BAD", "/response/status/code", - bytes.NewReader([]byte("200")), + strings.NewReader("200"), ); err == nil { t.Error("Expected error not present") } else if err.Error() != "Not Found" {