DDtKey / protect-endpoints

Authorization extension for popular web-frameworks to protect your endpoints
Apache License 2.0
202 stars 14 forks source link

Mismatch between compiler message and function arg position in tests #33

Closed CuriousCorrelation closed 2 years ago

CuriousCorrelation commented 2 years ago

Message on failing a test with common::test_body(left, right) fn look like this:

---- proc_macro::different_fn_types::test_str stdout ----
thread '...' panicked at 'assertion failed: `(left == right)`
  left: `"Hi!"`,
 right: `"Hello!"`', tests/file...
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

which corrosponds to

common::test_body("Hello!", "Hi!").await;

The lhs/rhs mismatch between compiler's message and the function params is due to the underlying assert_eq! swap of expected and received args

pub async fn test_body(resp: ServiceResponse, expected_body: &str) {
│   let body = test::read_body(resp).await;

│   assert_eq!(expected_body, String::from_utf8(body.to_vec()).unwrap());
}

Swapping lhs and rhs

pub async fn test_body(resp: ServiceResponse, expected_body: &str) {
│   let body = test::read_body(resp).await;

│   assert_eq!(String::from_utf8(body.to_vec()).unwrap(), expected_body);
}

fixes this issue.

This follows The Rust Book convention of

assert_eq!(actual, expected);

I have a PR ready to go if this feels like a worthwhile issue and doesn't violate library wide chosen convention.

DDtKey commented 2 years ago

Go ahead 🙂