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:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user