github.com/enbility/spine-go@v0.7.0/spine/entity_remote_test.go (about) 1 package spine 2 3 import ( 4 "testing" 5 6 "github.com/enbility/spine-go/mocks" 7 "github.com/enbility/spine-go/model" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/mock" 10 "github.com/stretchr/testify/suite" 11 ) 12 13 func TestEntityRemoteSuite(t *testing.T) { 14 suite.Run(t, new(EntityRemoteTestSuite)) 15 } 16 17 type EntityRemoteTestSuite struct { 18 suite.Suite 19 } 20 21 func (s *EntityRemoteTestSuite) Test_Entity() { 22 deviceAddress := model.AddressDeviceType("") 23 device := mocks.NewDeviceRemoteInterface(s.T()) 24 device.EXPECT().Address().Return(&deviceAddress) 25 device.EXPECT().AddEntity(mock.Anything) 26 27 entity := NewEntityRemote(device, model.EntityTypeTypeCEM, NewAddressEntityType([]uint{1})) 28 device.AddEntity(entity) 29 30 assert.Equal(s.T(), device, entity.Device()) 31 32 entity.UpdateDeviceAddress(model.AddressDeviceType("new")) 33 34 f := NewFeatureRemote(1, entity, model.FeatureTypeTypeElectricalConnection, model.RoleTypeClient) 35 entity.AddFeature(f) 36 assert.Equal(s.T(), 1, len(entity.Features())) 37 38 f1 := entity.FeatureOfAddress(nil) 39 assert.Nil(s.T(), f1) 40 41 f1 = entity.FeatureOfAddress(f.Address().Feature) 42 assert.NotNil(s.T(), f1) 43 44 fakeAddress := model.AddressFeatureType(5) 45 f1 = entity.FeatureOfAddress(&fakeAddress) 46 assert.Nil(s.T(), f1) 47 48 f1 = entity.FeatureOfTypeAndRole(model.FeatureTypeTypeElectricalConnection, model.RoleTypeClient) 49 assert.NotNil(s.T(), f1) 50 51 f1 = entity.FeatureOfTypeAndRole(model.FeatureTypeTypeElectricalConnection, model.RoleTypeServer) 52 assert.Nil(s.T(), f1) 53 54 entity.RemoveAllFeatures() 55 assert.Equal(s.T(), 0, len(entity.Features())) 56 }