442 when missing mandatory fields (WIP)
This commit is contained in:
@@ -3,7 +3,6 @@ package control
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -59,7 +58,14 @@ func addRoute(res http.ResponseWriter, req *http.Request) {
|
|||||||
res.WriteHeader(http.StatusBadRequest)
|
res.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
funcAdd(model.Route{})
|
if route.Method == "" {
|
||||||
|
res.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
created := funcAdd(route)
|
||||||
|
createdBytes, _ := json.Marshal(created)
|
||||||
|
|
||||||
res.WriteHeader(http.StatusCreated)
|
res.WriteHeader(http.StatusCreated)
|
||||||
_, _ = io.Copy(res, req.Body)
|
res.Header().Set("Content-Type", "application/json")
|
||||||
|
res.Write(createdBytes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAddRouteReturnsBadRequestWhenMalformedJSONBody(t *testing.T) {
|
func TestAddRouteReturnsBadRequestWhenMalformedJSONBody(t *testing.T) {
|
||||||
|
|
||||||
reqPayload := `{
|
reqPayload := `{
|
||||||
method": "GET",
|
method": "GET",
|
||||||
url_pattern": "/hello",
|
url_pattern": "/hello",
|
||||||
@@ -33,7 +32,6 @@ func TestAddRouteReturnsBadRequestWhenMalformedJSONBody(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddRouteReturns422ErrorWhenMandatoryFieldsMissing(t *testing.T) {
|
func TestAddRouteReturns422ErrorWhenMandatoryFieldsMissing(t *testing.T) {
|
||||||
t.Skip("****** WIP ******")
|
|
||||||
reqPayload := `{
|
reqPayload := `{
|
||||||
}`
|
}`
|
||||||
|
|
||||||
@@ -83,7 +81,7 @@ 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())
|
t.Errorf("Invalid JSON response. %s", resp.Body.String()) //FIXME: String comparsion not working
|
||||||
}
|
}
|
||||||
|
|
||||||
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"}
|
||||||
|
|||||||
Reference in New Issue
Block a user