Skip to content

Commit a0ac664

Browse files
committed
r1
1 parent 770986b commit a0ac664

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/convert/actix.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ mod actix_tests {
100100
use actix_web::{
101101
ResponseError,
102102
body::to_bytes,
103-
http::header::{RETRY_AFTER, WWW_AUTHENTICATE},
104-
rt::System
103+
http::header::{RETRY_AFTER, WWW_AUTHENTICATE}
105104
};
106105

107106
use crate::{AppCode, AppError, AppErrorKind, ErrorResponse};
@@ -112,8 +111,8 @@ mod actix_tests {
112111
assert_eq!(e.status_code().as_u16(), 422);
113112
}
114113

115-
#[test]
116-
fn error_response_sets_body_and_headers() {
114+
#[actix_web::test] // ← вот это
115+
async fn error_response_sets_body_and_headers() -> Result<(), Box<dyn std::error::Error>> {
117116
let err = AppError::unauthorized("no token")
118117
.with_retry_after_secs(7)
119118
.with_www_authenticate("Bearer");
@@ -122,14 +121,20 @@ mod actix_tests {
122121
assert_eq!(resp.status().as_u16(), 401);
123122

124123
let headers = resp.headers().clone();
125-
assert_eq!(headers.get(RETRY_AFTER).unwrap(), "7");
126-
assert_eq!(headers.get(WWW_AUTHENTICATE).unwrap(), "Bearer");
124+
assert_eq!(
125+
headers.get(RETRY_AFTER).and_then(|v| v.to_str().ok()),
126+
Some("7")
127+
);
128+
assert_eq!(
129+
headers.get(WWW_AUTHENTICATE).and_then(|v| v.to_str().ok()),
130+
Some("Bearer")
131+
);
127132

128-
let bytes = System::new()
129-
.block_on(async { to_bytes(resp.into_body(), usize::MAX).await.expect("body") });
130-
let body: ErrorResponse = serde_json::from_slice(&bytes).expect("json body");
133+
let bytes = to_bytes(resp.into_body()).await?;
134+
let body: ErrorResponse = serde_json::from_slice(&bytes)?;
131135
assert_eq!(body.status, 401);
132136
assert!(matches!(body.code, AppCode::Unauthorized));
133137
assert_eq!(body.message, "no token");
138+
Ok(())
134139
}
135140
}

src/convert/sqlx.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ mod tests {
7777

7878
#[test]
7979
fn other_error_maps_to_database() {
80-
let io_err = io::Error::new(io::ErrorKind::Other, "boom");
80+
// Prefer modern constructor; avoids clippy::io-other-error
81+
let io_err = io::Error::other("boom");
8182
let err: AppError = SqlxError::Io(io_err).into();
8283
assert!(matches!(err.kind, AppErrorKind::Database));
8384
}

0 commit comments

Comments
 (0)