Skip to content

Commit

Permalink
Merge pull request #36 from digital-society-coop/remove-http-body-util
Browse files Browse the repository at this point in the history
Use `axum::body::to_bytes` instead of `http-body-util`
  • Loading branch information
connec committed Dec 23, 2023
2 parents b01b01b + cb1854e commit ca4c50f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ tower-service = "0.3"

[dev-dependencies]
axum-sqlx-tx = { path = ".", features = ["runtime-tokio-rustls", "sqlite"] }
axum = "0.7.1"
http-body-util = "0.1.0"
axum = "0.7.2"
hyper = "1.0.1"
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tower = "0.4.12"
21 changes: 15 additions & 6 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use axum::{middleware, response::IntoResponse};
use axum_sqlx_tx::State;
use http_body_util::BodyExt;
use sqlx::{sqlite::SqliteArguments, Arguments as _};
use tower::ServiceExt;

Expand Down Expand Up @@ -124,7 +123,9 @@ async fn extract_from_middleware_and_handler() {
.await
.unwrap();
let status = response.status();
let body = response.into_body().collect().await.unwrap().to_bytes();
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap();

assert!(status.is_success());
assert_eq!(body.as_ref(), b"[[1,\"bobby tables\"]]");
Expand Down Expand Up @@ -165,7 +166,9 @@ async fn middleware_cloning_request_extensions() {
.await
.unwrap();
let status = response.status();
let body = response.into_body().collect().await.unwrap().to_bytes();
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap();
dbg!(body);

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

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

let body = response.into_body().collect().await.unwrap().to_bytes();
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap();
assert_eq!(body, format!("{}", axum_sqlx_tx::Error::MissingExtension));
}

Expand Down Expand Up @@ -296,7 +301,9 @@ async fn layer_error_override() {
.await
.unwrap();
let status = response.status();
let body = response.into_body().collect().await.unwrap().to_bytes();
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap();

assert!(status.is_client_error());
assert_eq!(body, "internal server error");
Expand Down Expand Up @@ -443,7 +450,9 @@ where
.await
.unwrap();
let status = response.status();
let body = response.into_body().collect().await.unwrap().to_bytes();
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
.await
.unwrap();

(pool, Response { status, body })
}
Expand Down

0 comments on commit ca4c50f

Please sign in to comment.