Verify content type on getRoute method

This commit is contained in:
Héctor Hurtado
2019-10-25 09:02:36 +02:00
parent 56876335b7
commit 26a7b690b7
2 changed files with 21 additions and 1 deletions
-1
View File
@@ -86,7 +86,6 @@ func addRoute(res http.ResponseWriter, req *http.Request) {
return
}
if route.Method == "" {
spec / test / features / control / get / success.feature
res.WriteHeader(http.StatusUnprocessableEntity)
return
}
+21
View File
@@ -420,6 +420,26 @@ func TestGetRouteReturns404sWhenRouteDoesntExist(t *testing.T) {
}
}
func TestGetRouteSetsCorrctContentType(t *testing.T) {
handler := mux.NewRouter()
handler.HandleFunc("/routes/{id}", getRoute).
Methods("GET")
r := httptest.NewRequest(http.MethodGet, "/routes/FOO", nil)
w := httptest.NewRecorder()
user.Routes.Append(model.Route{ID: "FOO"})
handler.ServeHTTP(w, r)
resp := w.Result()
if resp.StatusCode != http.StatusOK {
t.Errorf("HTTP status mismatch. Expected: %d, got: %d", http.StatusOK, resp.StatusCode)
}
if hVal := resp.Header.Get("Content-Type"); hVal != "application/json" {
t.Errorf(`Route mismatch. Expected: "application/json". Got: %s`, hVal)
}
}
func TestGetRouteReturnsTheRequestedRoute(t *testing.T) {
handler := mux.NewRouter()
handler.HandleFunc("/routes/{id}", getRoute).
@@ -427,6 +447,7 @@ func TestGetRouteReturnsTheRequestedRoute(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/routes/FOO", nil)
w := httptest.NewRecorder()
user.Routes.Append(model.Route{ID: "FOO"})
handler.ServeHTTP(w, r)
resp := w.Result()