mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Addressing comments
This commit is contained in:
@@ -11,8 +11,6 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var bad routeResponse
|
|
||||||
|
|
||||||
/* handleRouteCreateOrUpdate is used to handle POST PUT and PATCH for routes.
|
/* handleRouteCreateOrUpdate is used to handle POST PUT and PATCH for routes.
|
||||||
Post will only create route if its not there and create app if its not.
|
Post will only create route if its not there and create app if its not.
|
||||||
create only
|
create only
|
||||||
@@ -79,43 +77,38 @@ func (s *Server) changeRoute(ctx context.Context, wroute *models.RouteWrapper) e
|
|||||||
|
|
||||||
// ensureApp will only execute if it is on put
|
// ensureApp will only execute if it is on put
|
||||||
func (s *Server) ensureRoute(ctx context.Context, method string, wroute *models.RouteWrapper) (routeResponse, error) {
|
func (s *Server) ensureRoute(ctx context.Context, method string, wroute *models.RouteWrapper) (routeResponse, error) {
|
||||||
resp := routeResponse{"Route successfully created", nil}
|
bad := new(routeResponse)
|
||||||
up := routeResponse{"Route successfully updated", nil}
|
|
||||||
|
|
||||||
switch method {
|
switch method {
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
err := s.submitRoute(ctx, wroute)
|
err := s.submitRoute(ctx, wroute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bad, err
|
return *bad, err
|
||||||
}
|
}
|
||||||
resp.Route = wroute.Route
|
return routeResponse{"Route successfully created", wroute.Route}, nil
|
||||||
return resp, nil
|
|
||||||
case http.MethodPut:
|
case http.MethodPut:
|
||||||
_, err := s.Datastore.GetRoute(ctx, wroute.Route.AppName, wroute.Route.Path)
|
_, err := s.Datastore.GetRoute(ctx, wroute.Route.AppName, wroute.Route.Path)
|
||||||
if err != nil && err == models.ErrRoutesNotFound {
|
if err != nil && err == models.ErrRoutesNotFound {
|
||||||
err := s.submitRoute(ctx, wroute)
|
err := s.submitRoute(ctx, wroute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bad, err
|
return *bad, err
|
||||||
}
|
}
|
||||||
resp.Route = wroute.Route
|
return routeResponse{"Route successfully created", wroute.Route}, nil
|
||||||
return resp, nil
|
|
||||||
} else {
|
} else {
|
||||||
err := s.changeRoute(ctx, wroute)
|
err := s.changeRoute(ctx, wroute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bad, err
|
return *bad, err
|
||||||
}
|
}
|
||||||
up.Route = wroute.Route
|
return routeResponse{"Route successfully updated", wroute.Route}, nil
|
||||||
return up, nil
|
|
||||||
}
|
}
|
||||||
case http.MethodPatch:
|
case http.MethodPatch:
|
||||||
err := s.changeRoute(ctx, wroute)
|
err := s.changeRoute(ctx, wroute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bad, err
|
return *bad, err
|
||||||
}
|
}
|
||||||
up.Route = wroute.Route
|
return routeResponse{"Route successfully updated", wroute.Route}, nil
|
||||||
return up, nil
|
|
||||||
}
|
}
|
||||||
return bad, nil
|
return *bad, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureApp will only execute if it is on post or put. Patch is not allowed to create apps.
|
// ensureApp will only execute if it is on post or put. Patch is not allowed to create apps.
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/funcy/functions_go/client"
|
"github.com/funcy/functions_go/client"
|
||||||
"github.com/funcy/functions_go/client/apps"
|
"github.com/funcy/functions_go/client/apps"
|
||||||
@@ -59,7 +58,7 @@ func CreateAppNoAssert(ctx context.Context, fnclient *client.Functions, appName
|
|||||||
},
|
},
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
return fnclient.Apps.PostApps(cfg)
|
return fnclient.Apps.PostApps(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +83,7 @@ func CreateUpdateApp(t *testing.T, ctx context.Context, fnclient *client.Functio
|
|||||||
},
|
},
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
appPayload, err := fnclient.Apps.PatchAppsApp(cfg)
|
appPayload, err := fnclient.Apps.PatchAppsApp(cfg)
|
||||||
CheckAppResponseError(t, err)
|
CheckAppResponseError(t, err)
|
||||||
return appPayload
|
return appPayload
|
||||||
@@ -95,7 +94,7 @@ func DeleteApp(t *testing.T, ctx context.Context, fnclient *client.Functions, ap
|
|||||||
App: appName,
|
App: appName,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
_, err := fnclient.Apps.DeleteAppsApp(cfg)
|
_, err := fnclient.Apps.DeleteAppsApp(cfg)
|
||||||
CheckAppResponseError(t, err)
|
CheckAppResponseError(t, err)
|
||||||
}
|
}
|
||||||
@@ -105,7 +104,7 @@ func GetApp(t *testing.T, ctx context.Context, fnclient *client.Functions, appNa
|
|||||||
App: appName,
|
App: appName,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
app, err := fnclient.Apps.GetAppsApp(cfg)
|
app, err := fnclient.Apps.GetAppsApp(cfg)
|
||||||
CheckAppResponseError(t, err)
|
CheckAppResponseError(t, err)
|
||||||
return app.Payload.App
|
return app.Payload.App
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package tests
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/funcy/functions_go/client"
|
"github.com/funcy/functions_go/client"
|
||||||
"github.com/funcy/functions_go/client/routes"
|
"github.com/funcy/functions_go/client/routes"
|
||||||
@@ -112,7 +111,7 @@ func createRoute(ctx context.Context, fnclient *client.Functions, appName, image
|
|||||||
},
|
},
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
return fnclient.Routes.PostAppsAppRoutes(cfg)
|
return fnclient.Routes.PostAppsAppRoutes(cfg)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -130,7 +129,7 @@ func deleteRoute(ctx context.Context, fnclient *client.Functions, appName, route
|
|||||||
Route: routePath,
|
Route: routePath,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
return fnclient.Routes.DeleteAppsAppRoutesRoute(cfg)
|
return fnclient.Routes.DeleteAppsAppRoutesRoute(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +143,7 @@ func ListRoutes(t *testing.T, ctx context.Context, fnclient *client.Functions, a
|
|||||||
App: appName,
|
App: appName,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
routesResponse, err := fnclient.Routes.GetAppsAppRoutes(cfg)
|
routesResponse, err := fnclient.Routes.GetAppsAppRoutes(cfg)
|
||||||
CheckRouteResponseError(t, err)
|
CheckRouteResponseError(t, err)
|
||||||
return routesResponse.Payload.Routes
|
return routesResponse.Payload.Routes
|
||||||
@@ -156,7 +155,7 @@ func GetRoute(t *testing.T, ctx context.Context, fnclient *client.Functions, app
|
|||||||
Route: routePath,
|
Route: routePath,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
routeResponse, err := fnclient.Routes.GetAppsAppRoutesRoute(cfg)
|
routeResponse, err := fnclient.Routes.GetAppsAppRoutesRoute(cfg)
|
||||||
CheckRouteResponseError(t, err)
|
CheckRouteResponseError(t, err)
|
||||||
return routeResponse.Payload.Route
|
return routeResponse.Payload.Route
|
||||||
@@ -217,7 +216,6 @@ func UpdateRoute(t *testing.T, ctx context.Context, fnclient *client.Functions,
|
|||||||
},
|
},
|
||||||
Route: routePath,
|
Route: routePath,
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
|
|
||||||
return fnclient.Routes.PatchAppsAppRoutesRoute(cfg)
|
return fnclient.Routes.PatchAppsAppRoutesRoute(cfg)
|
||||||
}
|
}
|
||||||
@@ -247,7 +245,7 @@ func DeployRoute(t *testing.T, ctx context.Context, fnclient *client.Functions,
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cfg.WithTimeout(time.Second * 60)
|
|
||||||
route, err := fnclient.Routes.PutAppsAppRoutesRoute(cfg)
|
route, err := fnclient.Routes.PutAppsAppRoutesRoute(cfg)
|
||||||
CheckRouteResponseError(t, err)
|
CheckRouteResponseError(t, err)
|
||||||
return route.Payload.Route
|
return route.Payload.Route
|
||||||
|
|||||||
@@ -118,8 +118,9 @@ func RandStringBytes(n int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetupDefaultSuite() *SuiteSetup {
|
func SetupDefaultSuite() *SuiteSetup {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||||
ss := &SuiteSetup{
|
ss := &SuiteSetup{
|
||||||
Context: context.Background(),
|
Context: ctx,
|
||||||
Client: APIClient(),
|
Client: APIClient(),
|
||||||
AppName: RandStringBytes(10),
|
AppName: RandStringBytes(10),
|
||||||
RoutePath: "/" + RandStringBytes(10),
|
RoutePath: "/" + RandStringBytes(10),
|
||||||
@@ -128,7 +129,7 @@ func SetupDefaultSuite() *SuiteSetup {
|
|||||||
RouteType: "async",
|
RouteType: "async",
|
||||||
RouteConfig: map[string]string{},
|
RouteConfig: map[string]string{},
|
||||||
RouteHeaders: map[string][]string{},
|
RouteHeaders: map[string][]string{},
|
||||||
Cancel: func() {},
|
Cancel: cancel,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := ss.Client.Version.GetVersion(nil)
|
_, ok := ss.Client.Version.GetVersion(nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user