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.
This commit is contained in:
pancho horrillo
2019-10-08 05:28:29 +02:00
parent 10586bae95
commit 7ba54b32b3
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ func TestWriteContentToWriter(t *testing.T) {
gock.New("http://localhost"). gock.New("http://localhost").
Get("/handlers/HANDLER_BAR/request/body"). Get("/handlers/HANDLER_BAR/request/body").
Reply(http.StatusOK). Reply(http.StatusOK).
Body(bytes.NewReader([]byte("FOO"))) BodyString("FOO")
var b bytes.Buffer var b bytes.Buffer
err := GetData("http://localhost", "HANDLER_BAR", "/request/body", &b) err := GetData("http://localhost", "HANDLER_BAR", "/request/body", &b)
+3 -3
View File
@@ -1,8 +1,8 @@
package client_test package client_test
import ( import (
"bytes"
"net/http" "net/http"
"strings"
"testing" "testing"
gock "gopkg.in/h2non/gock.v1" gock "gopkg.in/h2non/gock.v1"
@@ -21,7 +21,7 @@ func TestSetDataSuccessOnCorrectRequest(t *testing.T) {
"http://localhost:8080", "http://localhost:8080",
"HANDLER_FOO", "HANDLER_FOO",
"/response/status/code", "/response/status/code",
bytes.NewReader([]byte("200")), strings.NewReader("200"),
); err != nil { ); err != nil {
t.Error("Unexpected error") t.Error("Unexpected error")
} }
@@ -42,7 +42,7 @@ func TestSetDataErrIfBadHandlerID(t *testing.T) {
"http://localhost:8080", "http://localhost:8080",
"HANDLER_BAD", "HANDLER_BAD",
"/response/status/code", "/response/status/code",
bytes.NewReader([]byte("200")), strings.NewReader("200"),
); err == nil { ); err == nil {
t.Error("Expected error not present") t.Error("Expected error not present")
} else if err.Error() != "Not Found" { } else if err.Error() != "Not Found" {