From baa73536e636daf405eb509d66c29c77386afd44 Mon Sep 17 00:00:00 2001 From: Sayan Hazra Date: Mon, 23 Nov 2020 14:33:40 +0100 Subject: [PATCH] Make array comparision in test deterministic --- .../pkg/subscribed/helpers_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/components/event-publisher-proxy/pkg/subscribed/helpers_test.go b/components/event-publisher-proxy/pkg/subscribed/helpers_test.go index 82a81b4e2c5d..1d81936ec079 100644 --- a/components/event-publisher-proxy/pkg/subscribed/helpers_test.go +++ b/components/event-publisher-proxy/pkg/subscribed/helpers_test.go @@ -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", @@ -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) + } } }) }