mirror of
https://github.com/tokio-rs/axum.git
synced 2025-09-27 04:50:31 +00:00
test: use ready()
and call()
to avoid using clone()
(#1176)
This commit is contained in:
parent
b243e171fd
commit
a3eaa332e4
@ -56,7 +56,8 @@ mod tests {
|
||||
};
|
||||
use serde_json::{json, Value};
|
||||
use std::net::{SocketAddr, TcpListener};
|
||||
use tower::ServiceExt; // for `app.oneshot()`
|
||||
use tower::Service; // for `call`
|
||||
use tower::ServiceExt; // for `oneshot` and `ready`
|
||||
|
||||
#[tokio::test]
|
||||
async fn hello_world() {
|
||||
@ -148,4 +149,19 @@ mod tests {
|
||||
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
|
||||
assert_eq!(&body[..], b"Hello, World!");
|
||||
}
|
||||
|
||||
// You can use `ready()` and `call()` to avoid using `clone()`
|
||||
// in multiple request
|
||||
#[tokio::test]
|
||||
async fn multiple_request() {
|
||||
let mut app = app();
|
||||
|
||||
let request = Request::builder().uri("/").body(Body::empty()).unwrap();
|
||||
let response = app.ready().await.unwrap().call(request).await.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
|
||||
let request = Request::builder().uri("/").body(Body::empty()).unwrap();
|
||||
let response = app.ready().await.unwrap().call(request).await.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user