Merge branch '103' into 'master'

Ensure app exists before listing its routes

Closes #103

See merge request !106
This commit is contained in:
Reed Allman
2017-07-25 10:16:07 -07:00
2 changed files with 9 additions and 6 deletions

View File

@@ -23,6 +23,10 @@ func (s *Server) handleRouteList(c *gin.Context) {
name, ok := appName.(string)
if exists && ok && name != "" {
routes, err = s.Datastore.GetRoutesByApp(ctx, name, filter)
// if there are no routes for the app, check if the app exists to return 404 if it does not
if len(routes) == 0 {
_, err = s.Datastore.GetApp(ctx, name)
}
} else {
routes, err = s.Datastore.GetRoutes(ctx, filter)
}

View File

@@ -115,6 +115,9 @@ func TestRoutePut(t *testing.T) {
func TestRouteDelete(t *testing.T) {
buf := setLogBuffer()
routes := models.Routes{{AppName: "a", Path: "/myroute"}}
apps := models.Apps{{Name: "a", Routes: routes, Config: nil}}
for i, test := range []struct {
ds models.Datastore
logDB models.FnLog
@@ -124,11 +127,7 @@ func TestRouteDelete(t *testing.T) {
expectedError error
}{
{datastore.NewMock(), logs.NewMock(), "/v1/apps/a/routes/missing", "", http.StatusNotFound, models.ErrRoutesNotFound},
{datastore.NewMockInit(nil,
[]*models.Route{
{Path: "/myroute", AppName: "a"},
}, nil, nil,
), logs.NewMock(), "/v1/apps/a/routes/myroute", "", http.StatusOK, nil},
{datastore.NewMockInit(apps, routes, nil, nil), logs.NewMock(), "/v1/apps/a/routes/myroute", "", http.StatusOK, nil},
} {
rnr, cancel := testRunner(t)
srv := testServer(test.ds, &mqs.Mock{}, test.logDB, rnr, DefaultEnqueue)
@@ -170,7 +169,7 @@ func TestRouteList(t *testing.T) {
expectedCode int
expectedError error
}{
{"/v1/apps/a/routes", "", http.StatusOK, nil},
{"/v1/apps/a/routes", "", http.StatusNotFound, models.ErrAppsNotFound},
} {
_, rec := routerRequest(t, srv.Router, "GET", test.path, nil)