Files
kapow/internal/client/route_remove_test.go
pancho horrillo f98784088d 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
2019-10-06 09:41:12 +02:00

43 lines
886 B
Go

package client
import (
"net/http"
"testing"
gock "gopkg.in/h2non/gock.v1"
)
func TestRemoveRouteOKExistent(t *testing.T) {
defer gock.Off()
gock.New("http://localhost:8080").
Delete("/routes/ROUTE_FOO").
Reply(http.StatusNoContent)
err := RemoveRoute("http://localhost:8080", "ROUTE_FOO")
if err != nil {
t.Errorf("unexpected error: %q", err)
}
if !gock.IsDone() {
t.Errorf("No endpoint called")
}
}
func TestRemoveRouteErrorNonExistent(t *testing.T) {
defer gock.Off()
gock.New("http://localhost:8080").
Delete("/routes/ROUTE_BAD").
Reply(http.StatusNotFound)
err := RemoveRoute("http://localhost:8080", "ROUTE_BAD")
if err == nil {
t.Errorf("Error not reported for nonexistent route")
} else if err.Error() != "Not Found" {
t.Errorf(`Error mismatch: got %q, want "Not Found"`, err)
}
if !gock.IsDone() {
t.Errorf("No endpoint called")
}
}