Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04519f6

Browse files
committed
allow slices order variation
1 parent 7ed901b commit 04519f6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

coderd/database/dbauthz/setup_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dbauthz_test
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"fmt"
78
"reflect"
@@ -201,7 +202,15 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *expec
201202
for i := range outputs {
202203
a, b := testCase.outputs[i].Interface(), outputs[i].Interface()
203204
// Use cmp.Diff to get a nice diff of the two values.
204-
if diff := cmp.Diff(a, b, cmpopts.EquateEmpty()); diff != "" {
205+
if diff := cmp.Diff(a, b,
206+
cmpopts.EquateEmpty(),
207+
// Allow order to be ignored.
208+
cmpopts.SortSlices(func(a, b any) bool {
209+
ab, _ := json.Marshal(a)
210+
bb, _ := json.Marshal(b)
211+
return string(ab) < string(bb)
212+
}),
213+
); diff != "" {
205214
s.Failf("compare outputs failed", "method %q returned unexpected output %d (-want +got):\n%s", methodName, i, diff)
206215
}
207216
}

0 commit comments

Comments
 (0)