diff --git a/spine/binding_manager.go b/spine/binding_manager.go index 8f51ddc..73fd2a0 100644 --- a/spine/binding_manager.go +++ b/spine/binding_manager.go @@ -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() @@ -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 diff --git a/spine/binding_manager_test.go b/spine/binding_manager_test.go index 43e364f..90304e4 100644 --- a/spine/binding_manager_test.go +++ b/spine/binding_manager_test.go @@ -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)