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

Skip to content

Commit 521aed8

Browse files
committed
test(coderd/database/dbauthz): compare outputs with cmp
This produces a more readable diff than that of the assert library.
1 parent 3a81aac commit 521aed8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

coderd/database/dbauthz/setup_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12+
"github.com/google/go-cmp/cmp"
1213
"github.com/google/uuid"
1314
"github.com/open-policy-agent/opa/topdown"
1415
"github.com/stretchr/testify/require"
@@ -198,11 +199,9 @@ func (s *MethodTestSuite) Subtest(testCaseF func(db database.Store, check *expec
198199
s.Equal(len(testCase.outputs), len(outputs), "method %q returned unexpected number of outputs", methodName)
199200
for i := range outputs {
200201
a, b := testCase.outputs[i].Interface(), outputs[i].Interface()
201-
if reflect.TypeOf(a).Kind() == reflect.Slice || reflect.TypeOf(a).Kind() == reflect.Array {
202-
// Order does not matter
203-
s.ElementsMatch(a, b, "method %q returned unexpected output %d", methodName, i)
204-
} else {
205-
s.Equal(a, b, "method %q returned unexpected output %d", methodName, i)
202+
// Use cmp.Diff to get a nice diff of the two values.
203+
if diff := cmp.Diff(a, b); diff != "" {
204+
s.Failf("compare outputs failed", "method %q returned unexpected output %d (-want +got):\n%s", methodName, i, diff)
206205
}
207206
}
208207
}

0 commit comments

Comments
 (0)