When marformed route then bad request implementation

This commit is contained in:
César Gallego Rodríguez
2019-10-09 10:27:38 +02:00
parent 4164f3e3de
commit 4ca5ef0d54
2 changed files with 10 additions and 2 deletions
+10 -1
View File
@@ -1,8 +1,10 @@
package control
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
@@ -45,11 +47,18 @@ func listRoutes(http.ResponseWriter, *http.Request) {
}
// user.Routes.Append(r model.Route)
// user.Routes.Append(r model.Route) model.Route
var funcAdd func(model.Route) model.Route = user.Routes.Append
func addRoute(res http.ResponseWriter, req *http.Request) {
var route model.Route
payload, _ := ioutil.ReadAll(req.Body)
err := json.Unmarshal(payload, &route)
if err != nil {
res.WriteHeader(http.StatusBadRequest)
return
}
funcAdd(model.Route{})
res.WriteHeader(http.StatusCreated)
_, _ = io.Copy(res, req.Body)
-1
View File
@@ -11,7 +11,6 @@ import (
)
func TestAddRouteWhenMalformedJSONBodyReturnsBadRequest(t *testing.T) {
t.Skip("****** WIP ******")
reqPayload := `{
method": "GET",
url_pattern": "/hello",