Fixed tests for listRoutes and removeRoute
This commit is contained in:
@@ -9,6 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/BBVA/kapow/internal/server/model"
|
"github.com/BBVA/kapow/internal/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -80,8 +82,8 @@ func TestAddRouteReturnsCreated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
respJson := model.Route{}
|
respJson := model.Route{}
|
||||||
if err := json.Unmarshal(resp.Body.Bytes(), &respJson); err == nil {
|
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?
|
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"}
|
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) {
|
func TestRemoveRouteReturnsNotFound(t *testing.T) {
|
||||||
t.Skip("****** WIP ******")
|
|
||||||
req := httptest.NewRequest(http.MethodDelete, "/routes/ROUTE_XXXXXXXXXXXXXXXXXX", nil)
|
req := httptest.NewRequest(http.MethodDelete, "/routes/ROUTE_XXXXXXXXXXXXXXXXXX", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
handler := http.HandlerFunc(removeRoute)
|
handler := mux.NewRouter()
|
||||||
|
handler.HandleFunc("/routes/{id}", removeRoute).
|
||||||
|
Methods("DELETE")
|
||||||
|
|
||||||
funcRemove = func(id string) error {
|
funcRemove = func(id string) error {
|
||||||
if id == "ROUTE_XXXXXXXXXXXXXXXXXX" {
|
if id == "ROUTE_XXXXXXXXXXXXXXXXXX" {
|
||||||
@@ -113,11 +116,16 @@ func TestRemoveRouteReturnsNotFound(t *testing.T) {
|
|||||||
func TestRemoveRouteReturnsNoContent(t *testing.T) {
|
func TestRemoveRouteReturnsNoContent(t *testing.T) {
|
||||||
req := httptest.NewRequest(http.MethodDelete, "/routes/ROUTE_XXXXXXXXXXXXXXXXXX", nil)
|
req := httptest.NewRequest(http.MethodDelete, "/routes/ROUTE_XXXXXXXXXXXXXXXXXX", nil)
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
handler := http.HandlerFunc(removeRoute)
|
handler := mux.NewRouter()
|
||||||
|
handler.HandleFunc("/routes/{id}", removeRoute).
|
||||||
|
Methods("DELETE")
|
||||||
|
|
||||||
funcRemove = func(id string) error {
|
funcRemove = func(id string) error {
|
||||||
|
if id == "ROUTE_XXXXXXXXXXXXXXXXXX" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return errors.New(id)
|
||||||
|
}
|
||||||
|
|
||||||
handler.ServeHTTP(resp, req)
|
handler.ServeHTTP(resp, req)
|
||||||
if resp.Code != http.StatusNoContent {
|
if resp.Code != http.StatusNoContent {
|
||||||
@@ -125,13 +133,11 @@ func TestRemoveRouteReturnsNoContent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: ListRoutes is a get, no path params, call
|
|
||||||
func TestListRoutesReturnsEmptyList(t *testing.T) {
|
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()
|
resp := httptest.NewRecorder()
|
||||||
handler := http.HandlerFunc(removeRoute)
|
handler := http.HandlerFunc(listRoutes)
|
||||||
|
|
||||||
funcList = func() []model.Route {
|
funcList = func() []model.Route {
|
||||||
|
|
||||||
@@ -139,8 +145,8 @@ func TestListRoutesReturnsEmptyList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handler.ServeHTTP(resp, req)
|
handler.ServeHTTP(resp, req)
|
||||||
if resp.Code != http.StatusNotFound {
|
if resp.Code != http.StatusOK {
|
||||||
t.Errorf("HTTP status mistmacht. Expected: %d, got: %d", http.StatusNotFound, resp.Code)
|
t.Errorf("HTTP status mistmacht. Expected: %d, got: %d", http.StatusOK, resp.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ct := resp.Header().Get("Content-Type"); ct != "application/json" {
|
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) {
|
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()
|
resp := httptest.NewRecorder()
|
||||||
handler := http.HandlerFunc(removeRoute)
|
handler := http.HandlerFunc(listRoutes)
|
||||||
|
|
||||||
funcList = func() []model.Route {
|
funcList = func() []model.Route {
|
||||||
return []model.Route{
|
return []model.Route{
|
||||||
|
|||||||
Reference in New Issue
Block a user