-
Notifications
You must be signed in to change notification settings - Fork 21
test: replace reflect.DeepEqual with error comparison in CBOR tests #1274
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
…tests Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
📝 WalkthroughWalkthroughThree test functions in Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
No issues found across 1 file
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
cbor/decode_test.go (1)
112-113: LGTM! Improved error comparison.The replacement of
reflect.DeepEqualwith explicit nil-ness and message comparison is more robust for error testing. This pattern correctly handles all cases: both nil, one nil/one non-nil, and both non-nil with message comparison.Consider extracting this error comparison pattern into a helper function to reduce duplication across the three test functions:
func compareErrors(t *testing.T, got, want error) { if (got == nil) != (want == nil) || (got != nil && want != nil && got.Error() != want.Error()) { t.Fatalf( "did not find expected error\n got: %#v\n wanted: %#v", got, want, ) } }Then replace lines 112-113 with
compareErrors(t, err, test.Error).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
cbor/decode_test.go(3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: wolf31o2
Repo: blinklabs-io/gouroboros PR: 1093
File: ledger/mary/pparams.go:143-150
Timestamp: 2025-11-04T15:54:22.683Z
Learning: In the blinklabs-io/gouroboros repository, the design goal for CBOR round-trip tests is to achieve byte-identical encoding WITHOUT using stored CBOR (cbor.DecodeStoreCbor). Instead, the approach uses proper field types (pointers for optional fields) and relies on the cbor package's deterministic encoding (SortCoreDeterministic) to ensure reproducible output. The stored CBOR pattern should not be suggested as a solution for round-trip fidelity in this codebase.
📚 Learning: 2025-11-04T15:54:22.683Z
Learnt from: wolf31o2
Repo: blinklabs-io/gouroboros PR: 1093
File: ledger/mary/pparams.go:143-150
Timestamp: 2025-11-04T15:54:22.683Z
Learning: In the blinklabs-io/gouroboros repository, the design goal for CBOR round-trip tests is to achieve byte-identical encoding WITHOUT using stored CBOR (cbor.DecodeStoreCbor). Instead, the approach uses proper field types (pointers for optional fields) and relies on the cbor package's deterministic encoding (SortCoreDeterministic) to ensure reproducible output. The stored CBOR pattern should not be suggested as a solution for round-trip fidelity in this codebase.
Applied to files:
cbor/decode_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Analyze (go)
🔇 Additional comments (2)
cbor/decode_test.go (2)
171-172: LGTM! Consistent error comparison improvement.The same robust error comparison pattern is correctly applied here, replacing the unreliable
reflect.DeepEqualfor error testing.
260-261: LGTM! Error comparison pattern consistently applied.The same robust error comparison pattern is correctly applied to this third test function, completing the refactoring of all error comparisons in this file.
Summary by cubic
Replaced reflect.DeepEqual with direct error comparison in CBOR tests to correctly match expected errors and avoid brittle failures.
Updated tests for ListLength, DecodeIdFromList, and DecodeById to compare nilness and err.Error() strings.
Written for commit 03dc972. Summary will update automatically on new commits.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.