Skip to content

Commit 115efba

Browse files
committed
fix: non-deterministic test failures by addressing the issue with the keys function test.
The problem was that Go maps have randomized iteration order, so when the keys function returns a slice of map keys, the order could vary between test runs, causing the test to fail when comparing against an expected ordered slice.
1 parent aa9cd0a commit 115efba

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

funcs_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,18 @@ func TestFuncs_MapOperations(t *testing.T) {
487487
result := v(tt.inputs[0].(map[any]any))
488488
expected := tt.expected.([]any)
489489
assert.Len(t, result, len(expected))
490-
if tt.funcName == "values" {
490+
switch tt.funcName {
491+
case "values":
491492
// For values function, check that all expected values are present (order not guaranteed)
492493
for _, val := range expected {
493494
assert.Contains(t, result, val)
494495
}
495-
} else {
496+
case "keys":
497+
// For keys function, check that all expected keys are present (order not guaranteed)
498+
for _, key := range expected {
499+
assert.Contains(t, result, key)
500+
}
501+
default:
496502
assert.Equal(t, tt.expected, result)
497503
}
498504
case func(map[any]any, any) bool:

0 commit comments

Comments
 (0)