Skip to content

Commit cb1854e

Browse files
committed
refactor: use axum::body::to_bytes instead of http-body-util
1 parent b01b01b commit cb1854e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ tower-service = "0.3"
3939

4040
[dev-dependencies]
4141
axum-sqlx-tx = { path = ".", features = ["runtime-tokio-rustls", "sqlite"] }
42-
axum = "0.7.1"
43-
http-body-util = "0.1.0"
42+
axum = "0.7.2"
4443
hyper = "1.0.1"
4544
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
4645
tower = "0.4.12"

tests/lib.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use axum::{middleware, response::IntoResponse};
22
use axum_sqlx_tx::State;
3-
use http_body_util::BodyExt;
43
use sqlx::{sqlite::SqliteArguments, Arguments as _};
54
use tower::ServiceExt;
65

@@ -124,7 +123,9 @@ async fn extract_from_middleware_and_handler() {
124123
.await
125124
.unwrap();
126125
let status = response.status();
127-
let body = response.into_body().collect().await.unwrap().to_bytes();
126+
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
127+
.await
128+
.unwrap();
128129

129130
assert!(status.is_success());
130131
assert_eq!(body.as_ref(), b"[[1,\"bobby tables\"]]");
@@ -165,7 +166,9 @@ async fn middleware_cloning_request_extensions() {
165166
.await
166167
.unwrap();
167168
let status = response.status();
168-
let body = response.into_body().collect().await.unwrap().to_bytes();
169+
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
170+
.await
171+
.unwrap();
169172
dbg!(body);
170173

171174
assert!(status.is_success());
@@ -227,7 +230,9 @@ async fn missing_layer() {
227230

228231
assert!(response.status().is_server_error());
229232

230-
let body = response.into_body().collect().await.unwrap().to_bytes();
233+
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
234+
.await
235+
.unwrap();
231236
assert_eq!(body, format!("{}", axum_sqlx_tx::Error::MissingExtension));
232237
}
233238

@@ -296,7 +301,9 @@ async fn layer_error_override() {
296301
.await
297302
.unwrap();
298303
let status = response.status();
299-
let body = response.into_body().collect().await.unwrap().to_bytes();
304+
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
305+
.await
306+
.unwrap();
300307

301308
assert!(status.is_client_error());
302309
assert_eq!(body, "internal server error");
@@ -443,7 +450,9 @@ where
443450
.await
444451
.unwrap();
445452
let status = response.status();
446-
let body = response.into_body().collect().await.unwrap().to_bytes();
453+
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
454+
.await
455+
.unwrap();
447456

448457
(pool, Response { status, body })
449458
}

0 commit comments

Comments
 (0)