test: use ready() and call() to avoid using clone() (#1176)

This commit is contained in:
azzamsa 2022-07-20 19:19:15 +07:00 committed by GitHub
parent b243e171fd
commit a3eaa332e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
}