-
Notifications
You must be signed in to change notification settings - Fork 881
test(coderd/database/dbauthz): compare outputs with cmp #16161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This produces a more readable diff than that of the assert library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does look way better 👍
// Use cmp.Diff to get a nice diff of the two values. | ||
if diff := cmp.Diff(a, b, cmpopts.EquateEmpty()); diff != "" { | ||
s.Failf("compare outputs failed", "method %q returned unexpected output %d (-want +got):\n%s", methodName, i, diff) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing we lose though is that the order should not matter for slices.
I was using ElementsMatch
before. Does different ordering now break the comparison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, there is cmpopts.SortSlices
but it seems a bit more work to support than ElementsMatch
. 🤔
TBH I'd prefer if all output from the DB was deterministic but that's a huge undertaking to fix it everywhere 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, unsure on the db determinism. I do recall in the past our dbmem and pg implementation had different orders for some listing call.
I did ElementsMatch just to avoid any potential ordering flakes. The order is not something these tests care about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does 6d2b94d
(#16161) seem acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me!
Might be worth throwing in one of the test util packages.
04519f6
to
7ed901b
Compare
This produces a more readable diff than that of the assert library.
After:
Before (hard to parse):