Fixed tests for listRoutes and removeRoute
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/BBVA/kapow/internal/server/model"
|
||||
)
|
||||
|
||||
@@ -80,8 +82,8 @@ func TestAddRouteReturnsCreated(t *testing.T) {
|
||||
}
|
||||
|
||||
respJson := model.Route{}
|
||||
if err := json.Unmarshal(resp.Body.Bytes(), &respJson); err == nil {
|
||||
t.Errorf("Invalid JSON response. %s", resp.Body.String()) //FIXME: String comparsion not working, comparing against itself?
|
||||
if err := json.Unmarshal(resp.Body.Bytes(), &respJson); err != nil {
|
||||
t.Errorf("Invalid JSON response. %s", resp.Body.String())
|
||||
}
|
||||
|
||||
expectedRouteSpec := model.Route{Method: "GET", Pattern: "/hello", Entrypoint: "/bin/sh -c", Command: "echo Hello World | kapow set /response/body", Index: 0, ID: "ROUTE_XXXXXXXXXXXXXXXXXX"}
|
||||
@@ -91,10 +93,11 @@ func TestAddRouteReturnsCreated(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemoveRouteReturnsNotFound(t *testing.T) {
|
||||
t.Skip("****** WIP ******")
|
||||
req := httptest.NewRequest(http.MethodDelete, "/routes/ROUTE_XXXXXXXXXXXXXXXXXX", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
handler := http.HandlerFunc(removeRoute)
|
||||
handler := mux.NewRouter()
|
||||
handler.HandleFunc("/routes/{id}", removeRoute).
|
||||
Methods("DELETE")
|
||||
|
||||
funcRemove = func(id string) error {
|
||||
if id == "ROUTE_XXXXXXXXXXXXXXXXXX" {
|
||||
@@ -113,10 +116,15 @@ func TestRemoveRouteReturnsNotFound(t *testing.T) {
|
||||
func TestRemoveRouteReturnsNoContent(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodDelete, "/routes/ROUTE_XXXXXXXXXXXXXXXXXX", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
handler := http.HandlerFunc(removeRoute)
|
||||
handler := mux.NewRouter()
|
||||
handler.HandleFunc("/routes/{id}", removeRoute).
|
||||
Methods("DELETE")
|
||||
|
||||
funcRemove = func(id string) error {
|
||||
return nil
|
||||
if id == "ROUTE_XXXXXXXXXXXXXXXXXX" {
|
||||
return nil
|
||||
}
|
||||
return errors.New(id)
|
||||
}
|
||||
|
||||
handler.ServeHTTP(resp, req)
|
||||
@@ -125,13 +133,11 @@ func TestRemoveRouteReturnsNoContent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: ListRoutes is a get, no path params, call
|
||||
func TestListRoutesReturnsEmptyList(t *testing.T) {
|
||||
t.Skip("****** WIP ******")
|
||||
|
||||
req := httptest.NewRequest(http.MethodDelete, "/routes/ROUTE_XXXXXXXXXXXXXXXXXX", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/routes/", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
handler := http.HandlerFunc(removeRoute)
|
||||
handler := http.HandlerFunc(listRoutes)
|
||||
|
||||
funcList = func() []model.Route {
|
||||
|
||||
@@ -139,8 +145,8 @@ func TestListRoutesReturnsEmptyList(t *testing.T) {
|
||||
}
|
||||
|
||||
handler.ServeHTTP(resp, req)
|
||||
if resp.Code != http.StatusNotFound {
|
||||
t.Errorf("HTTP status mistmacht. Expected: %d, got: %d", http.StatusNotFound, resp.Code)
|
||||
if resp.Code != http.StatusOK {
|
||||
t.Errorf("HTTP status mistmacht. Expected: %d, got: %d", http.StatusOK, resp.Code)
|
||||
}
|
||||
|
||||
if ct := resp.Header().Get("Content-Type"); ct != "application/json" {
|
||||
@@ -148,13 +154,11 @@ func TestListRoutesReturnsEmptyList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: ListRoutes is a get, no path params, call
|
||||
func TestListRoutesReturnsTwoElementsList(t *testing.T) {
|
||||
t.Skip("****** WIP ******")
|
||||
|
||||
req := httptest.NewRequest(http.MethodDelete, "/routes/ROUTE_XXXXXXXXXXXXXXXXXX", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/routes", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
handler := http.HandlerFunc(removeRoute)
|
||||
handler := http.HandlerFunc(listRoutes)
|
||||
|
||||
funcList = func() []model.Route {
|
||||
return []model.Route{
|
||||
|
||||
Reference in New Issue
Block a user