mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
@@ -14,7 +14,11 @@ func (s *Server) handleAppCreate(c *gin.Context) {
|
||||
|
||||
err := c.BindJSON(&wapp)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
if models.IsAPIError(err) {
|
||||
handleErrorResponse(c, err)
|
||||
} else {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,11 @@ func (s *Server) handleAppUpdate(c *gin.Context) {
|
||||
|
||||
err := c.BindJSON(&wapp)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
if models.IsAPIError(err) {
|
||||
handleErrorResponse(c, err)
|
||||
} else {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,11 @@ func (s *Server) handleRunnerEnqueue(c *gin.Context) {
|
||||
var call models.Call
|
||||
err := c.BindJSON(&call)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
if models.IsAPIError(err) {
|
||||
handleErrorResponse(c, err)
|
||||
} else {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -92,7 +96,11 @@ func (s *Server) handleRunnerStart(c *gin.Context) {
|
||||
var call models.Call
|
||||
err := c.BindJSON(&call)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
if models.IsAPIError(err) {
|
||||
handleErrorResponse(c, err)
|
||||
} else {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -143,7 +151,11 @@ func (s *Server) handleRunnerFinish(c *gin.Context) {
|
||||
}
|
||||
err := c.BindJSON(&body)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
if models.IsAPIError(err) {
|
||||
handleErrorResponse(c, err)
|
||||
} else {
|
||||
handleErrorResponse(c, models.ErrInvalidJSON)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ func TestRootMiddleware(t *testing.T) {
|
||||
{Name: "myapp2", Config: models.Config{}},
|
||||
},
|
||||
[]*models.Route{
|
||||
{Path: "/", AppName: "myapp", Image: "fnproject/hello", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||
{Path: "/", AppName: "myapp", Image: "fnproject/hello", Type: "sync", Memory: 128, CPUs: 100, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||
{Path: "/myroute", AppName: "myapp", Image: "fnproject/hello", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||
{Path: "/app2func", AppName: "myapp2", Image: "fnproject/hello", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}},
|
||||
Config: map[string]string{"NAME": "johnny"},
|
||||
|
||||
@@ -141,6 +141,9 @@ func (s *Server) ensureApp(ctx context.Context, wroute *models.RouteWrapper, met
|
||||
func bindRoute(c *gin.Context, method string, wroute *models.RouteWrapper) error {
|
||||
err := c.BindJSON(wroute)
|
||||
if err != nil {
|
||||
if models.IsAPIError(err) {
|
||||
return err
|
||||
}
|
||||
return models.ErrInvalidJSON
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ func TestRouteCreate(t *testing.T) {
|
||||
{datastore.NewMock(), logs.NewMock(), http.MethodPost, "/v1/apps/a/routes", `{ "route": { "image": "fnproject/hello", "type": "sync" } }`, http.StatusBadRequest, models.ErrRoutesMissingPath},
|
||||
{datastore.NewMock(), logs.NewMock(), http.MethodPost, "/v1/apps/a/routes", `{ "route": { "image": "fnproject/hello", "path": "myroute", "type": "sync" } }`, http.StatusBadRequest, models.ErrRoutesInvalidPath},
|
||||
{datastore.NewMock(), logs.NewMock(), http.MethodPost, "/v1/apps/$/routes", `{ "route": { "image": "fnproject/hello", "path": "/myroute", "type": "sync" } }`, http.StatusBadRequest, models.ErrAppsInvalidName},
|
||||
{datastore.NewMock(), logs.NewMock(), http.MethodPost, "/v1/apps/a/routes", `{ "route": { "image": "fnproject/hello", "path": "/myroute", "type": "sync", "cpus": "-100" } }`, http.StatusBadRequest, models.ErrInvalidCPUs},
|
||||
{datastore.NewMockInit(nil,
|
||||
[]*models.Route{
|
||||
{
|
||||
@@ -118,6 +119,8 @@ func TestRouteCreate(t *testing.T) {
|
||||
|
||||
// success
|
||||
{datastore.NewMock(), logs.NewMock(), http.MethodPost, "/v1/apps/a/routes", `{ "route": { "image": "fnproject/hello", "path": "/myroute", "type": "sync" } }`, http.StatusOK, nil},
|
||||
{datastore.NewMock(), logs.NewMock(), http.MethodPost, "/v1/apps/a/routes", `{ "route": { "image": "fnproject/hello", "path": "/myroute", "type": "sync", "cpus": "100m" } }`, http.StatusOK, nil},
|
||||
{datastore.NewMock(), logs.NewMock(), http.MethodPost, "/v1/apps/a/routes", `{ "route": { "image": "fnproject/hello", "path": "/myroute", "type": "sync", "cpus": "0.2" } }`, http.StatusOK, nil},
|
||||
} {
|
||||
test.run(t, i, buf)
|
||||
}
|
||||
@@ -332,6 +335,7 @@ func TestRouteUpdate(t *testing.T) {
|
||||
{ds, logs.NewMock(), http.MethodPatch, "/v1/apps/a/routes/myroute/do", `{ "route": { "type": "async", "timeout": 121, "idle_timeout": 240 } }`, http.StatusOK, nil}, // should work if async
|
||||
{ds, logs.NewMock(), http.MethodPatch, "/v1/apps/a/routes/myroute/do", `{ "route": { "idle_timeout": 3601 } }`, http.StatusBadRequest, models.ErrRoutesInvalidIdleTimeout},
|
||||
{ds, logs.NewMock(), http.MethodPatch, "/v1/apps/a/routes/myroute/do", `{ "route": { "memory": 100000000000000 } }`, http.StatusBadRequest, models.ErrRoutesInvalidMemory},
|
||||
{ds, logs.NewMock(), http.MethodPatch, "/v1/apps/a/routes/myroute/do", `{ "route": { "cpus": "foo" } }`, http.StatusBadRequest, models.ErrInvalidCPUs},
|
||||
// TODO this should be correct, waiting for patch to come in
|
||||
//{ds, logs.NewMock(), http.MethodPatch, "/v1/apps/b/routes/myroute/dont", `{ "route": {} }`, http.StatusNotFound, models.ErrAppsNotFound},
|
||||
{ds, logs.NewMock(), http.MethodPatch, "/v1/apps/a/routes/myroute/dont", `{ "route": {} }`, http.StatusNotFound, models.ErrRoutesNotFound},
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestRouteRunnerAsyncExecution(t *testing.T) {
|
||||
[]*models.Route{
|
||||
{Type: "async", Path: "/hot-http", AppName: "myapp", Image: "fnproject/fn-test-utils", Format: "http", Config: map[string]string{"test": "true"}, Memory: 128, Timeout: 4, IdleTimeout: 30},
|
||||
{Type: "async", Path: "/hot-json", AppName: "myapp", Image: "fnproject/fn-test-utils", Format: "json", Config: map[string]string{"test": "true"}, Memory: 128, Timeout: 4, IdleTimeout: 30},
|
||||
{Type: "async", Path: "/myroute", AppName: "myapp", Image: "fnproject/hello", Config: map[string]string{"test": "true"}, Memory: 128, Timeout: 30, IdleTimeout: 30},
|
||||
{Type: "async", Path: "/myroute", AppName: "myapp", Image: "fnproject/hello", Config: map[string]string{"test": "true"}, Memory: 128, CPUs: 200, Timeout: 30, IdleTimeout: 30},
|
||||
{Type: "async", Path: "/myerror", AppName: "myapp", Image: "fnproject/error", Config: map[string]string{"test": "true"}, Memory: 128, Timeout: 30, IdleTimeout: 30},
|
||||
{Type: "async", Path: "/myroute/:param", AppName: "myapp", Image: "fnproject/hello", Config: map[string]string{"test": "true"}, Memory: 128, Timeout: 30, IdleTimeout: 30},
|
||||
}, nil,
|
||||
|
||||
Reference in New Issue
Block a user