Fix datastore error for inexistent app (#493)

* fix datastore error inexistent app

* fix get route error handling

* fix API errors handling and tests
This commit is contained in:
Pedro Nasser
2017-01-26 20:41:18 -02:00
committed by Travis Reeder
parent 5a91710dbf
commit a80fe9c897
15 changed files with 65 additions and 100 deletions

View File

@@ -229,6 +229,8 @@ func (ds *BoltDatastore) GetApp(ctx context.Context, name string) (*models.App,
return err
}
res = app
} else {
return models.ErrAppsNotFound
}
return nil
})
@@ -239,15 +241,11 @@ func (ds *BoltDatastore) GetApp(ctx context.Context, name string) (*models.App,
}
func (ds *BoltDatastore) getRouteBucketForApp(tx *bolt.Tx, appName string) (*bolt.Bucket, error) {
var err error
// todo: should this be reversed? Make a bucket for each app that contains sub buckets for routes, etc
bp := tx.Bucket(ds.routesBucket)
b := bp.Bucket([]byte(appName))
if b == nil {
b, err = bp.CreateBucket([]byte(appName))
if err != nil {
return nil, err
}
return nil, models.ErrAppsNotFound
}
return b, nil
}
@@ -418,6 +416,10 @@ func (ds *BoltDatastore) GetRoute(ctx context.Context, appName, routePath string
}
v := b.Get([]byte(routePath))
if v == nil {
return models.ErrRoutesNotFound
}
if v != nil {
err = json.Unmarshal(v, &route)
}

View File

@@ -67,7 +67,7 @@ func TestBolt(t *testing.T) {
app, err := ds.GetApp(ctx, testApp.Name)
if err != nil {
t.Log(buf.String())
t.Fatalf("Test GetApp: error: %s", err)
t.Fatalf("Test GetApp: unexpected error: %s", err)
}
if app.Name != testApp.Name {
t.Log(buf.String())
@@ -101,9 +101,9 @@ func TestBolt(t *testing.T) {
t.Fatalf("Test RemoveApp: error: %s", err)
}
app, err = ds.GetApp(ctx, testApp.Name)
if err != nil {
if err != models.ErrAppsNotFound {
t.Log(buf.String())
t.Fatalf("Test GetApp: error: %s", err)
t.Fatalf("Test GetApp: expected error to be `%v`, but it was `%v`", models.ErrAppsNotFound, err)
}
if app != nil {
t.Log(buf.String())
@@ -240,11 +240,7 @@ func TestBolt(t *testing.T) {
}
route, err = ds.GetRoute(ctx, testRoute.AppName, testRoute.Path)
if err != nil {
t.Log(buf.String())
t.Fatalf("Test GetRoute: error: %s", err)
}
if route != nil {
if err != models.ErrRoutesNotFound {
t.Log(buf.String())
t.Fatalf("Test RemoveApp: failed to remove the route")
}