diff --git a/spine/model/usecaseinformation_additions.go b/spine/model/usecaseinformation_additions.go index 685247af..d30bc5af 100644 --- a/spine/model/usecaseinformation_additions.go +++ b/spine/model/usecaseinformation_additions.go @@ -44,10 +44,9 @@ func (u *UseCaseInformationDataType) Remove(useCaseName UseCaseNameType) { for _, item := range u.UseCaseSupport { if item.UseCaseName != nil && *item.UseCaseName != useCaseName { - continue + usecases = append(usecases, item) } - usecases = append(usecases, item) } u.UseCaseSupport = usecases diff --git a/spine/model/usecaseinformation_additions_test.go b/spine/model/usecaseinformation_additions_test.go new file mode 100644 index 00000000..b91af46b --- /dev/null +++ b/spine/model/usecaseinformation_additions_test.go @@ -0,0 +1,47 @@ +package model + +import ( + "testing" + + "github.com/enbility/eebus-go/util" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +func TestUseCaseInformationDataTypeSuite(t *testing.T) { + suite.Run(t, new(UseCaseInformationDataTypeSuite)) +} + +type UseCaseInformationDataTypeSuite struct { + suite.Suite +} + +func (s *UseCaseInformationDataTypeSuite) SetupSuite() {} +func (s *UseCaseInformationDataTypeSuite) TearDownTest() {} + +func (s *UseCaseInformationDataTypeSuite) BeforeTest(suiteName, testName string) {} + +func (s *UseCaseInformationDataTypeSuite) Test_AdditionsAndRemovals() { + ucs := &UseCaseInformationDataType{} + assert.NotNil(s.T(), ucs) + assert.Equal(s.T(), 0, len(ucs.UseCaseSupport)) + + uc := UseCaseSupportType{} + ucs.Add(uc) + assert.Equal(s.T(), 0, len(ucs.UseCaseSupport)) + + uc = UseCaseSupportType{ + UseCaseName: util.Ptr(UseCaseNameTypeControlOfBattery), + } + ucs.Add(uc) + assert.Equal(s.T(), 1, len(ucs.UseCaseSupport)) + + ucs.Add(uc) + assert.Equal(s.T(), 1, len(ucs.UseCaseSupport)) + + ucs.Remove(UseCaseNameTypeCoordinatedEVCharging) + assert.Equal(s.T(), 1, len(ucs.UseCaseSupport)) + + ucs.Remove(UseCaseNameTypeControlOfBattery) + assert.Equal(s.T(), 0, len(ucs.UseCaseSupport)) +}