Skip to content

Commit

Permalink
test: use ready() and call() to avoid using clone() (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
azzamsa committed Jul 20, 2022
1 parent b243e17 commit a3eaa33
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion examples/testing/src/main.rs
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit a3eaa33

Please sign in to comment.