Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit 35e6034

Browse files
Added test for removeElement.
1 parent 4b6acc6 commit 35e6034

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

actions/rules/action_state_to_metastate.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@ type ActionStateToMetaState struct {
2323
// make sure the rule is implementing the interface.
2424
var _ Action = ActionStateToMetaState{}
2525

26-
/*
27-
func (act ActionStateToMetaState) containsUUID(s []uuid.UUID, e uuid.UUID) bool {
28-
for _, a := range s {
29-
if a == e {
30-
return true
31-
}
32-
}
33-
return false
34-
}
35-
*/
36-
3726
func (act ActionStateToMetaState) contains(s []interface{}, e interface{}) bool {
3827
for _, a := range s {
3928
if a == e {
@@ -53,16 +42,6 @@ func (act ActionStateToMetaState) removeElement(s []interface{}, e interface{})
5342
}
5443
}
5544
return s
56-
57-
/*
58-
for idx, a := range s {
59-
if a == e {
60-
s = append(s[:idx], s[idx+1:]...)
61-
// we don't return here as there may be multiple copies of e in s.
62-
}
63-
}
64-
return s
65-
*/
6645
}
6746

6847
// difference returns the differences between two slices. It returns two slices containing

actions/rules/action_state_to_metastate_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,53 @@ func (s *ActionStateToMetastateSuite) TestContainsElement() {
6464
})
6565
}
6666

67+
func (s *ActionStateToMetastateSuite) TestRemoveElement() {
68+
s.T().Run("removing an existing element", func(t *testing.T) {
69+
fxt := tf.NewTestFixture(t, s.DB, tf.CreateWorkItemEnvironment())
70+
action := ActionStateToMetaState{
71+
Db: s.GormDB,
72+
Ctx: s.Ctx,
73+
UserID: &fxt.Identities[0].ID,
74+
}
75+
// there is no other way of creating an []interface{}.
76+
// but we have plenty of memory, so be it.
77+
var a []interface{}
78+
a = append(a, 0)
79+
a = append(a, 1)
80+
a = append(a, 2)
81+
a = append(a, 3)
82+
a = append(a, 2)
83+
a = action.removeElement(a, 2)
84+
require.Len(t, a, 3)
85+
require.False(t, action.contains(a, 2))
86+
a = action.removeElement(a, 1)
87+
require.Len(t, a, 2)
88+
require.False(t, action.contains(a, 1))
89+
})
90+
s.T().Run("removing a non-existing element", func(t *testing.T) {
91+
fxt := tf.NewTestFixture(t, s.DB, tf.CreateWorkItemEnvironment())
92+
action := ActionStateToMetaState{
93+
Db: s.GormDB,
94+
Ctx: s.Ctx,
95+
UserID: &fxt.Identities[0].ID,
96+
}
97+
// there is no other way of creating an []interface{}.
98+
// but we have plenty of memory, so be it.
99+
var a []interface{}
100+
a = append(a, 0)
101+
a = append(a, 1)
102+
a = append(a, 2)
103+
a = append(a, 3)
104+
a = append(a, 2)
105+
a = action.removeElement(a, 4)
106+
require.Len(t, a, 5)
107+
require.True(t, action.contains(a, 0))
108+
require.True(t, action.contains(a, 1))
109+
require.True(t, action.contains(a, 2))
110+
require.True(t, action.contains(a, 3))
111+
})
112+
}
113+
67114
func (s *ActionStateToMetastateSuite) TestActionExecution() {
68115
// Note on the fixture: by default, the created board is attached to the type group
69116
// with the same index. The columns on each board are as follows:

0 commit comments

Comments
 (0)