diff options
author | azzamsa <17734314+azzamsa@users.noreply.github.com> | 2022-07-20 19:19:15 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-20 12:19:15 +0000 |
commit | a3eaa332e4dd3c6d691e64df53563fcf3a6fec5b (patch) | |
tree | 7c53b98e77a79261ba206733ed1261999802976d /examples | |
parent | b243e171fd3a8f6e53ff120b149f7eae53f6adfb (diff) |
test: use `ready()` and `call()` to avoid using `clone()` (#1176)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/testing/src/main.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index 2893188b..0bb9b352 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -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); + } } |