Skip to content
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

Use inline snapshots for error responses #9505

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Sep 24, 2024

This PR converts most of our error response assertions to inline snapshot assertions powered by insta. Snapshots are a lot easier to update automatically than hardcoded error messages (cargo insta test), and inline snapshots make it easier to comprehend what a test is expecting without having to open multiple files. The latter is obviously only valid for short responses, not for larger JSON documents.

The main benefit of this is that our test code is now a bit more concise (+139 −994 🎉)

The downside of this is that the code needs to be recompiled when the expected error messages change, but it does bring the error messages closer to the test code, which makes the tests a little bit easier to digest. `cargo insta test` makes it fairly easy to update these expectations automatically, even for inline snapshots.
We can hardcode the error messages in our tests but that makes it quite hard to update the error messages, since they have to be updated in multiple places. With insta snapshots they will still have to be updated everywhere but `cargo insta test` can automate this process, which makes it a lot more straight-forward.
@Turbo87 Turbo87 added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ labels Sep 24, 2024
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.09%. Comparing base (92ebff2) to head (e599e46).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9505      +/-   ##
==========================================
- Coverage   89.16%   89.09%   -0.08%     
==========================================
  Files         286      286              
  Lines       29071    28878     -193     
==========================================
- Hits        25921    25728     -193     
  Misses       3150     3150              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Turbo87 Turbo87 merged commit 96910f7 into rust-lang:main Sep 25, 2024
10 checks passed
@Turbo87 Turbo87 deleted the error-snapshots branch September 25, 2024 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant