Add internal/client/route_remove{,_test}.go

Co-authored-by: Héctor Hurtado <hector.hurtado@bbva.com>
This commit is contained in:
pancho horrillo
2019-10-03 18:22:18 +02:00
parent 306889c958
commit 013cd4d637
2 changed files with 51 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
package client
import (
"net/http"
"testing"
gock "gopkg.in/h2non/gock.v1"
)
func TestRemoveRouteExistent(t *testing.T) {
const (
host = "http://localhost:8080"
routeID = "ROUTE_ID_OLDER_BUT_IT_CHECKS_OUT"
)
defer gock.Off()
gock.New(host).Delete("/routes/" + routeID).Reply(http.StatusNoContent)
err := RemoveRoute(host, routeID)
if err != nil {
t.Errorf("unexpected error: %s", err)
}
}
func TestRemoveRouteNonExistent(t *testing.T) {
const (
host = "http://localhost:8080"
routeID = "ROUTE_THIS_ONE_WONT_WORK_BUDDY"
)
expected := http.StatusText(http.StatusNotFound)
defer gock.Off()
gock.New(host).Delete("/routes/" + routeID).Reply(http.StatusNotFound)
err := RemoveRoute(host, routeID)
if err == nil {
t.Errorf("error not reported for nonexistent route")
} else if err.Error() != expected {
t.Errorf("error mismatch: expected %s, got %s", expected, err)
}
}