Skip to content

Commit

Permalink
Improve binding removals and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jan 21, 2024
1 parent c020452 commit ab3aad6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
10 changes: 9 additions & 1 deletion spine/binding_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ func (c *BindingManagerImpl) RemoveBinding(data model.BindingManagementDeleteCal
return fmt.Errorf("server feature '%s' in local device '%s' not found", data.ServerAddress, *c.localDevice.Address())
}

if err := c.checkRoleAndType(serverFeature, model.RoleTypeServer, serverFeature.Type()); err != nil {
return err
}

if !c.HasLocalFeatureRemoteBinding(serverFeature.Address(), clientFeature.Address()) {
return fmt.Errorf("the feature '%s' address has no binding", data.ClientAddress)
}

c.mux.Lock()
defer c.mux.Unlock()

Expand All @@ -121,7 +129,7 @@ func (c *BindingManagerImpl) RemoveBinding(data model.BindingManagementDeleteCal
}

if len(newBindingEntries) == len(c.bindingEntries) {
return errors.New("could not find requested BindingId to be removed")
return errors.New("could not find requested binding to be removed")
}

c.bindingEntries = newBindingEntries
Expand Down
35 changes: 33 additions & 2 deletions spine/binding_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,41 @@ func (suite *BindingManagerSuite) Test_Bindings() {
assert.Equal(suite.T(), 1, len(entries))

bindingDelete := model.BindingManagementDeleteCallType{
ClientAddress: remoteFeature.Address(),
ServerAddress: localFeature.Address(),
ClientAddress: util.Ptr(model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType("dummy")),
Entity: []model.AddressEntityType{1000},
Feature: util.Ptr(model.AddressFeatureType(1000)),
}),
ServerAddress: util.Ptr(model.FeatureAddressType{
Device: util.Ptr(model.AddressDeviceType("dummy")),
Entity: []model.AddressEntityType{1000},
Feature: util.Ptr(model.AddressFeatureType(1000)),
}),
}

err = bindingMgr.RemoveBinding(bindingDelete, suite.remoteDevice)
assert.NotNil(suite.T(), err)

bindingDelete.ClientAddress = remoteServerFeature.Address()

err = bindingMgr.RemoveBinding(bindingDelete, suite.remoteDevice)
assert.NotNil(suite.T(), err)

bindingDelete.ServerAddress = localClientFeature.Address()

err = bindingMgr.RemoveBinding(bindingDelete, suite.remoteDevice)
assert.NotNil(suite.T(), err)

err = bindingMgr.RemoveBinding(bindingDelete, suite.remoteDevice)
assert.NotNil(suite.T(), err)

bindingDelete.ServerAddress = localFeature.Address()

err = bindingMgr.RemoveBinding(bindingDelete, suite.remoteDevice)
assert.NotNil(suite.T(), err)

bindingDelete.ClientAddress = remoteFeature.Address()

err = bindingMgr.RemoveBinding(bindingDelete, suite.remoteDevice)
assert.Nil(suite.T(), err)

Expand Down

0 comments on commit ab3aad6

Please sign in to comment.