|
17 | 17 | * under the License. |
18 | 18 | */ |
19 | 19 | /// Asserts that a [Response] has a status code >=200 and <300 |
| 20 | +
|
20 | 21 | #[macro_export] |
21 | 22 | macro_rules! assert_response_success { |
22 | 23 | ($response:ident) => {{ |
23 | | - assert!( |
24 | | - $response.status_code().is_success(), |
25 | | - "expected response to be successful but was {}", |
26 | | - $response.status_code().as_u16() |
27 | | - ); |
| 24 | + let status_code = $response.status_code(); |
| 25 | + if !status_code.is_success() { |
| 26 | + let text = $response |
| 27 | + .text() |
| 28 | + .await |
| 29 | + .unwrap_or("[no response]".to_string()); |
| 30 | + panic!( |
| 31 | + "expected response to be successful but was {}. Response: {}", |
| 32 | + status_code, text |
| 33 | + ); |
| 34 | + } |
28 | 35 | }}; |
29 | 36 | } |
30 | 37 |
|
31 | 38 | /// Asserts that a [Response] has a status code >=200 and <300 or matches the passed status |
32 | 39 | #[macro_export] |
33 | 40 | macro_rules! assert_response_success_or { |
34 | 41 | ($response:ident, $status:expr) => {{ |
35 | | - assert!( |
36 | | - $response.status_code().is_success() || $response.status_code().as_u16() == $status, |
37 | | - "expected response to be successful or {} but was {}", |
38 | | - $status, |
39 | | - $response.status_code().as_u16() |
40 | | - ); |
| 42 | + let status_code = $response.status_code(); |
| 43 | + if !status_code.is_success() && status_code.as_u16() != $status { |
| 44 | + let text = $response |
| 45 | + .text() |
| 46 | + .await |
| 47 | + .unwrap_or("[no response]".to_string()); |
| 48 | + panic!( |
| 49 | + "expected response to be successful or {} but was {}", |
| 50 | + $status, |
| 51 | + status_code.as_u16() |
| 52 | + ); |
| 53 | + } |
| 54 | + }}; |
| 55 | +} |
| 56 | + |
| 57 | +/// Asserts that a [Response] has a status that matches the passed status |
| 58 | +#[macro_export] |
| 59 | +macro_rules! assert_response_status_code { |
| 60 | + ($response:ident, $status:expr) => {{ |
| 61 | + let status_code = $response.status_code(); |
| 62 | + if status_code.as_u16() != $status { |
| 63 | + let text = $response |
| 64 | + .text() |
| 65 | + .await |
| 66 | + .unwrap_or("[no response]".to_string()); |
| 67 | + panic!( |
| 68 | + "expected response to be {} but was {}", |
| 69 | + $status, |
| 70 | + status_code.as_u16() |
| 71 | + ); |
| 72 | + } |
41 | 73 | }}; |
42 | 74 | } |
43 | 75 |
|
|
0 commit comments