internal/client/{get,set}_test.go: send io.Writer() based on []byte
* internal/client/get_test.go:
- Revert changes when setting the Body of the mock (gock).
- Revert over-eager line splitting.
* internal/client/set_test.go:
- Use bytes.NewReader([]byte("200")) instead of strings.NewReader("200")
Thanks to @nilp0inter for the feedback!
This commit is contained in:
@@ -13,11 +13,10 @@ func TestWriteContentToWriter(t *testing.T) {
|
||||
gock.New("http://localhost").
|
||||
Get("/handlers/HANDLER_BAR/request/body").
|
||||
Reply(http.StatusOK).
|
||||
BodyString("FOO")
|
||||
Body(bytes.NewReader([]byte("FOO")))
|
||||
|
||||
var b bytes.Buffer
|
||||
err := GetData(
|
||||
"http://localhost", "HANDLER_BAR", "/request/body", &b)
|
||||
err := GetData("http://localhost", "HANDLER_BAR", "/request/body", &b)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %q", err)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package client_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
gock "gopkg.in/h2non/gock.v1"
|
||||
@@ -19,7 +19,10 @@ func TestSetDataSuccessOnCorrectRequest(t *testing.T) {
|
||||
|
||||
if err := client.SetData(
|
||||
"http://localhost:8080",
|
||||
"HANDLER_FOO", "/response/status/code", strings.NewReader("200")); err != nil {
|
||||
"HANDLER_FOO",
|
||||
"/response/status/code",
|
||||
bytes.NewReader([]byte("200")),
|
||||
); err != nil {
|
||||
t.Error("Unexpected error")
|
||||
}
|
||||
|
||||
@@ -37,7 +40,10 @@ func TestSetDataErrIfBadHandlerID(t *testing.T) {
|
||||
|
||||
if err := client.SetData(
|
||||
"http://localhost:8080",
|
||||
"HANDLER_BAD", "/response/status/code", strings.NewReader("200")); err == nil {
|
||||
"HANDLER_BAD",
|
||||
"/response/status/code",
|
||||
bytes.NewReader([]byte("200")),
|
||||
); err == nil {
|
||||
t.Error("Expected error not present")
|
||||
} else if err.Error() != "Not Found" {
|
||||
t.Errorf(`Error mismatch: expected "Not Found", got %q`, err)
|
||||
|
||||
Reference in New Issue
Block a user