Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit f338aac

Browse files
committed
Fix the mas-http tests
1 parent dcb9bde commit f338aac

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

crates/http/tests/client_layers.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use anyhow::{bail, Context};
1818
use bytes::{Buf, Bytes};
1919
use headers::{ContentType, HeaderMapExt};
2020
use http::{header::ACCEPT, HeaderValue, Request, Response, StatusCode};
21+
use http_body_util::{BodyExt, Empty};
2122
use mas_http::{
2223
BodyToBytesResponseLayer, BytesToBodyRequestLayer, CatchHttpCodesLayer,
2324
FormUrlencodedRequestLayer, JsonRequestLayer, JsonResponseLayer,
@@ -51,7 +52,7 @@ async fn test_http_errors() {
5152
);
5253
let svc = layer.layer(service_fn(handle));
5354

54-
let request = Request::new(hyper::Body::empty());
55+
let request = Request::new(Empty::<Bytes>::new());
5556

5657
let res = svc.oneshot(request).await;
5758
let err = res.expect_err("the request should fail");
@@ -60,7 +61,7 @@ async fn test_http_errors() {
6061

6162
#[tokio::test]
6263
async fn test_json_request_body() {
63-
async fn handle<B>(request: Request<B>) -> Result<Response<hyper::Body>, anyhow::Error>
64+
async fn handle<B>(request: Request<B>) -> Result<Response<Empty<Bytes>>, anyhow::Error>
6465
where
6566
B: http_body::Body + Send,
6667
B::Error: std::error::Error + Send + Sync + 'static,
@@ -74,12 +75,12 @@ async fn test_json_request_body() {
7475
bail!("Content-Type header is not application/json")
7576
}
7677

77-
let bytes = hyper::body::to_bytes(request.into_body()).await?;
78+
let bytes = request.into_body().collect().await?.to_bytes();
7879
if bytes.to_vec() != br#"{"hello":"world"}"#.to_vec() {
7980
bail!("Body mismatch")
8081
}
8182

82-
let res = Response::new(hyper::Body::empty());
83+
let res = Response::new(Empty::new());
8384
Ok(res)
8485
}
8586

@@ -111,7 +112,7 @@ async fn test_json_response_body() {
111112
let layer = (JsonResponseLayer::default(), BodyToBytesResponseLayer);
112113
let svc = layer.layer(service_fn(handle));
113114

114-
let request = Request::new(hyper::Body::empty());
115+
let request = Request::new(Empty::<Bytes>::new());
115116

116117
let res = svc.oneshot(request).await;
117118
let response = res.expect("the request to succeed");
@@ -121,7 +122,7 @@ async fn test_json_response_body() {
121122

122123
#[tokio::test]
123124
async fn test_urlencoded_request_body() {
124-
async fn handle<B>(request: Request<B>) -> Result<Response<hyper::Body>, anyhow::Error>
125+
async fn handle<B>(request: Request<B>) -> Result<Response<Empty<Bytes>>, anyhow::Error>
125126
where
126127
B: http_body::Body + Send,
127128
B::Error: std::error::Error + Send + Sync + 'static,
@@ -135,10 +136,10 @@ async fn test_urlencoded_request_body() {
135136
bail!("Content-Type header is not application/x-form-urlencoded")
136137
}
137138

138-
let bytes = hyper::body::to_bytes(request.into_body()).await?;
139+
let bytes = request.into_body().collect().await?.to_bytes();
139140
assert_eq!(bytes.to_vec(), br"hello=world".to_vec());
140141

141-
let res = Response::new(hyper::Body::empty());
142+
let res = Response::new(Empty::new());
142143
Ok(res)
143144
}
144145

0 commit comments

Comments
 (0)