Normalize internal/client/*_test.go

* Adjust test style for easy reading, by using literals instead of vars
* Move comparison to the `bytes` domain, instead of `string`
* Simplify testing code by using bytes.Buffer directly
* More consistent naming of variables and dummies (HANDLE_{FOO,BAR,BAD})
* Consistent testing style of gock.IsDone()
* Stick to 80-column
This commit is contained in:
pancho horrillo
2019-10-06 09:41:12 +02:00
parent 25409a2cee
commit f98784088d
6 changed files with 78 additions and 92 deletions
+9 -9
View File
@@ -1,7 +1,6 @@
package client
import (
"bufio"
"bytes"
"net/http"
"testing"
@@ -12,13 +11,13 @@ import (
func TestWriteContentToWriter(t *testing.T) {
defer gock.Off()
gock.New("http://localhost").
Get("/handlers/THIS-IS-THE-HANDLER-ID/request/body").
Get("/handlers/HANDLER_BAR/request/body").
Reply(http.StatusOK).
Body(bytes.NewReader([]byte("FOO")))
BodyString("FOO")
var b bytes.Buffer
buf := bufio.NewWriter(&b)
err := GetData("http://localhost", "THIS-IS-THE-HANDLER-ID", "/request/body", buf)
err := GetData(
"http://localhost", "HANDLER_BAR", "/request/body", &b)
if err != nil {
t.Errorf("Unexpected error: %q", err)
@@ -28,7 +27,7 @@ func TestWriteContentToWriter(t *testing.T) {
t.Errorf("Received content mismatch: %q != %q", b.Bytes(), []byte("FOO"))
}
if gock.IsDone() == false {
if !gock.IsDone() {
t.Error("No expected endpoint called")
}
}
@@ -36,16 +35,17 @@ func TestWriteContentToWriter(t *testing.T) {
func TestPropagateHTTPError(t *testing.T) {
defer gock.Off()
gock.New("http://localhost").
Get("/handlers/THIS-IS-THE-HANDLER-ID/request/body").
Get("/handlers/HANDLER_BAR/request/body").
Reply(http.StatusTeapot)
err := GetData("http://localhost", "THIS-IS-THE-HANDLER-ID", "/request/body", nil)
err := GetData(
"http://localhost", "HANDLER_BAR", "/request/body", nil)
if err == nil {
t.Errorf("Expected error not returned")
}
if gock.IsDone() == false {
if !gock.IsDone() {
t.Error("No expected endpoint called")
}
}