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

Derive PartialEq for Json extractor #2742

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jkylling
Copy link

Motivation

It should be possible to test handlers using

assert_eq!((StatusCode::OK, Json(MyStruct)), my_handler().await);

Currently, this can only be achieved with

let (status_code, Json(response)) = my_handler().await;
assert_eq!(StatusCode::OK, status_code);
assert_eq!(MyStruct, response);

Solution

@jplatte
Copy link
Member

jplatte commented May 29, 2024

If we do this, we should do it for all the extractors that just consist of a single generic field, including those in axum-extra.

I think your second test code snippet is actually better though, since it will print a simpler / more specific error message if the assert fails.
Is this sort of test code your only motivation for wanting to add this trait impl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants