Added update action to manageServiceRoutes. Table is embedded; skip opts

This commit is contained in:
Milos Gajdos
2019-07-10 21:28:32 +01:00
parent 1f744b31a4
commit a0ee7d2092
3 changed files with 27 additions and 20 deletions

View File

@@ -106,17 +106,16 @@ func (t *table) Update(r Route) error {
// check if the route destination has any routes in the table
if _, ok := t.m[service]; !ok {
return ErrRouteNotFound
}
// if the route has been found update it
if _, ok := t.m[service][sum]; ok {
t.m[service] = make(map[uint64]Route)
t.m[service][sum] = r
go t.sendEvent(&Event{Type: Update, Timestamp: time.Now(), Route: r})
go t.sendEvent(&Event{Type: Create, Timestamp: time.Now(), Route: r})
return nil
}
return ErrRouteNotFound
t.m[service][sum] = r
go t.sendEvent(&Event{Type: Update, Timestamp: time.Now(), Route: r})
return nil
}
// List returns a list of all routes in the table

View File

@@ -94,12 +94,13 @@ func TestUpdate(t *testing.T) {
t.Errorf("invalid number of routes. Expected: %d, found: %d", testTableSize, table.Size())
}
// this should error as the destination does not exist
// this should add a new route
route.Service = "rand.dest"
if err := table.Update(route); err != ErrRouteNotFound {
t.Errorf("error updating route. Expected error: %s, found: %s", ErrRouteNotFound, err)
if err := table.Update(route); err != nil {
t.Errorf("error updating route: %s", err)
}
testTableSize += 1
if table.Size() != testTableSize {
t.Errorf("invalid number of routes. Expected: %d, found: %d", testTableSize, table.Size())