mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
server updates (#566)
* server updates - improved route create/update validation/defaults - improved/added route test cases * cleanup * negative concurrency check
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
8a9678e4af
commit
1d0ba54b35
@@ -22,7 +22,7 @@ func (s *Server) handleAppDelete(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
||||
return
|
||||
}
|
||||
|
||||
//TODO allow this? #528
|
||||
if len(routes) > 0 {
|
||||
log.WithError(err).Debug(models.ErrDeleteAppsWithRoutes)
|
||||
c.JSON(http.StatusBadRequest, simpleError(models.ErrDeleteAppsWithRoutes))
|
||||
|
||||
@@ -31,18 +31,14 @@ func (s *Server) handleRouteCreate(c *gin.Context) {
|
||||
|
||||
wroute.Route.AppName = c.MustGet(api.AppName).(string)
|
||||
|
||||
if err := wroute.Validate(); err != nil {
|
||||
wroute.Route.SetDefaults()
|
||||
|
||||
if err := wroute.Validate(false); err != nil {
|
||||
log.WithError(err).Debug(models.ErrRoutesCreate)
|
||||
c.JSON(http.StatusBadRequest, simpleError(err))
|
||||
return
|
||||
}
|
||||
|
||||
if wroute.Route.Image == "" {
|
||||
log.WithError(models.ErrRoutesValidationMissingImage).Debug(models.ErrRoutesCreate)
|
||||
c.JSON(http.StatusBadRequest, simpleError(models.ErrRoutesValidationMissingImage))
|
||||
return
|
||||
}
|
||||
|
||||
// err = s.Runner.EnsureImageExists(ctx, &task.Config{
|
||||
// Image: wroute.Route.Image,
|
||||
// })
|
||||
|
||||
@@ -50,11 +50,14 @@ func TestRouteCreate(t *testing.T) {
|
||||
|
||||
if test.expectedError != nil {
|
||||
resp := getErrorResponse(t, rec)
|
||||
|
||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||
if resp.Error == nil {
|
||||
t.Log(buf.String())
|
||||
t.Errorf("Test %d: Expected error message to have `%s`, but it was nil",
|
||||
i, test.expectedError)
|
||||
} else if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||
t.Log(buf.String())
|
||||
t.Errorf("Test %d: Expected error message to have `%s`, but it was `%s`",
|
||||
i, test.expectedError.Error(), resp.Error.Message)
|
||||
i, test.expectedError, resp.Error.Message)
|
||||
}
|
||||
}
|
||||
cancel()
|
||||
@@ -193,6 +196,8 @@ func TestRouteUpdate(t *testing.T) {
|
||||
// errors
|
||||
{datastore.NewMock(), "/v1/apps/a/routes/myroute/do", ``, http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
{datastore.NewMock(), "/v1/apps/a/routes/myroute/do", `{}`, http.StatusBadRequest, models.ErrRoutesMissingNew},
|
||||
{datastore.NewMock(), "/v1/apps/a/routes/myroute/do", `{ "route": { "type": "invalid-type" } }`, http.StatusBadRequest, nil},
|
||||
{datastore.NewMock(), "/v1/apps/a/routes/myroute/do", `{ "route": { "format": "invalid-format" } }`, http.StatusBadRequest, nil},
|
||||
|
||||
// success
|
||||
{datastore.NewMockInit(nil,
|
||||
@@ -223,8 +228,8 @@ func TestRouteUpdate(t *testing.T) {
|
||||
|
||||
if rec.Code != test.expectedCode {
|
||||
t.Log(buf.String())
|
||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||
i, test.expectedCode, rec.Code)
|
||||
t.Errorf("Test %d: Expected status code to be %d but was %d: %s",
|
||||
i, test.expectedCode, rec.Code, rec.Body.String())
|
||||
}
|
||||
|
||||
if test.expectedError != nil {
|
||||
|
||||
@@ -39,6 +39,12 @@ func (s *Server) handleRouteUpdate(c *gin.Context) {
|
||||
wroute.Route.AppName = c.MustGet(api.AppName).(string)
|
||||
wroute.Route.Path = path.Clean(c.MustGet(api.Path).(string))
|
||||
|
||||
if err := wroute.Validate(true); err != nil {
|
||||
log.WithError(err).Debug(models.ErrRoutesUpdate)
|
||||
c.JSON(http.StatusBadRequest, simpleError(err))
|
||||
return
|
||||
}
|
||||
|
||||
if wroute.Route.Image != "" {
|
||||
// err = s.Runner.EnsureImageExists(ctx, &task.Config{
|
||||
// Image: wroute.Route.Image,
|
||||
|
||||
Reference in New Issue
Block a user