Skip to content

Commit 963771f

Browse files
DSET-4455: Fix flaky test on MacOS (#55)
* DSET-4455: Fix flaky test on MacOS * Add comments explaning the sort interface
1 parent 84b074e commit 963771f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/client/add_events_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type (
7373

7474
const attributeKey = "key"
7575

76+
// byKey implement sort.Interface - https://pkg.go.dev/sort#Interface
7677
type byKey [][]tAttr
7778

7879
func (s byKey) Len() int {
@@ -83,8 +84,16 @@ func (s byKey) Swap(i, j int) {
8384
s[i], s[j] = s[j], s[i]
8485
}
8586

87+
// Less returns true if ith element is nil or it's string representation
88+
// is before jth element.
8689
func (s byKey) Less(i, j int) bool {
87-
return s[i][0][attributeKey].(string) < s[j][0][attributeKey].(string)
90+
if s[i][0][attributeKey] == nil {
91+
return true
92+
} else if s[j][0][attributeKey] == nil {
93+
return false
94+
} else {
95+
return s[i][0][attributeKey].(string) < s[j][0][attributeKey].(string)
96+
}
8897
}
8998

9099
func TestAddEventsRetry(t *testing.T) {

0 commit comments

Comments
 (0)