Skip to content

Commit

Permalink
Make array comparision in test deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanh committed Nov 23, 2020
1 parent 2e8db3a commit baa7353
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions components/event-publisher-proxy/pkg/subscribed/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ func TestConvertEventsMapToSlice(t *testing.T) {
{
name: "should return events from the map in a slice",
inputMap: map[Event]bool{
NewEvent("bar", "v2"): true,
NewEvent("foo", "v1"): true,
NewEvent("bar", "v2"): true,
},
wantedEvents: []Event{
NewEvent("bar", "v2"),
NewEvent("foo", "v1"),
NewEvent("bar", "v2"),
},
}, {
name: "should return no events for an empty map of events",
Expand All @@ -108,8 +108,17 @@ func TestConvertEventsMapToSlice(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
gotEvents := ConvertEventsMapToSlice(tc.inputMap)
if !reflect.DeepEqual(tc.wantedEvents, gotEvents) {
t.Errorf("incorrect slice of events, wanted: %v, got: %v", tc.wantedEvents, gotEvents)
for _, event := range gotEvents {
found := false
for _, wantEvent := range tc.wantedEvents {
if event == wantEvent {
found = true
continue
}
}
if !found {
t.Errorf("incorrect slice of events, wanted: %v, got: %v", tc.wantedEvents, gotEvents)
}
}
})
}
Expand Down

0 comments on commit baa7353

Please sign in to comment.