Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Mar 8, 2020
1 parent a9a475d commit e718f65
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 87 deletions.
6 changes: 4 additions & 2 deletions actix-framed/tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ async fn test_simple() {
)
.finish(|_| future::ok::<_, Error>(Response::NotFound()))
.tcp()
});
})
.await;

assert!(srv.ws_at("/test").await.is_err());

Expand Down Expand Up @@ -108,7 +109,8 @@ async fn test_service() {
.map_err(|_| ()),
),
)
});
})
.await;

// non ws request
let res = srv.get("/index.html").send().await.unwrap();
Expand Down
9 changes: 6 additions & 3 deletions actix-http/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ async fn test_h1_v2() {
HttpService::build()
.finish(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
.tcp()
});
})
.await;

let response = srv.get("/").send().await.unwrap();
assert!(response.status().is_success());
Expand Down Expand Up @@ -61,7 +62,8 @@ async fn test_connection_close() {
.finish(|_| ok::<_, ()>(Response::Ok().body(STR)))
.tcp()
.map(|_| ())
});
})
.await;

let response = srv.get("/").force_close().send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -80,7 +82,8 @@ async fn test_with_query_parameter() {
})
.tcp()
.map(|_| ())
});
})
.await;

let request = srv.request(http::Method::GET, srv.url("/?qp=5"));
let response = request.send().await.unwrap();
Expand Down
41 changes: 27 additions & 14 deletions actix-http/tests/test_openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ async fn test_h2() -> io::Result<()> {
.h2(|_| ok::<_, Error>(Response::Ok().finish()))
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -85,7 +86,8 @@ async fn test_h2_1() -> io::Result<()> {
})
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -103,7 +105,8 @@ async fn test_h2_body() -> io::Result<()> {
})
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send_body(data.clone()).await.unwrap();
assert!(response.status().is_success());
Expand Down Expand Up @@ -131,7 +134,8 @@ async fn test_h2_content_length() {
})
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let header = HeaderName::from_static("content-length");
let value = HeaderValue::from_static("0");
Expand Down Expand Up @@ -192,7 +196,7 @@ async fn test_h2_headers() {
})
.openssl(ssl_acceptor())
.map_err(|_| ())
});
}).await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand Down Expand Up @@ -231,7 +235,8 @@ async fn test_h2_body2() {
.h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -248,7 +253,8 @@ async fn test_h2_head_empty() {
.finish(|_| ok::<_, ()>(Response::Ok().body(STR)))
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.shead("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -273,7 +279,8 @@ async fn test_h2_head_binary() {
})
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.shead("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -295,7 +302,8 @@ async fn test_h2_head_binary2() {
.h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.shead("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -318,7 +326,8 @@ async fn test_h2_body_length() {
})
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -342,7 +351,8 @@ async fn test_h2_body_chunked_explicit() {
})
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -369,7 +379,8 @@ async fn test_h2_response_http_error_handling() {
}))
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
Expand All @@ -386,7 +397,8 @@ async fn test_h2_service_error() {
.h2(|_| err::<Response, Error>(ErrorBadRequest("error")))
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
Expand All @@ -407,7 +419,8 @@ async fn test_h2_on_connect() {
})
.openssl(ssl_acceptor())
.map_err(|_| ())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand Down
47 changes: 31 additions & 16 deletions actix-http/tests/test_rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ async fn test_h1() -> io::Result<()> {
HttpService::build()
.h1(|_| future::ok::<_, Error>(Response::Ok().finish()))
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -58,7 +59,8 @@ async fn test_h2() -> io::Result<()> {
HttpService::build()
.h2(|_| future::ok::<_, Error>(Response::Ok().finish()))
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -75,7 +77,8 @@ async fn test_h1_1() -> io::Result<()> {
future::ok::<_, Error>(Response::Ok().finish())
})
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -92,7 +95,8 @@ async fn test_h2_1() -> io::Result<()> {
future::ok::<_, Error>(Response::Ok().finish())
})
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -109,7 +113,8 @@ async fn test_h2_body1() -> io::Result<()> {
Ok::<_, Error>(Response::Ok().body(body))
})
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send_body(data.clone()).await.unwrap();
assert!(response.status().is_success());
Expand All @@ -136,7 +141,8 @@ async fn test_h2_content_length() {
future::ok::<_, ()>(Response::new(statuses[indx]))
})
.rustls(ssl_acceptor())
});
})
.await;

let header = HeaderName::from_static("content-length");
let value = HeaderValue::from_static("0");
Expand Down Expand Up @@ -195,7 +201,7 @@ async fn test_h2_headers() {
future::ok::<_, ()>(config.body(data.clone()))
})
.rustls(ssl_acceptor())
});
}).await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand Down Expand Up @@ -233,7 +239,8 @@ async fn test_h2_body2() {
HttpService::build()
.h2(|_| future::ok::<_, ()>(Response::Ok().body(STR)))
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -249,7 +256,8 @@ async fn test_h2_head_empty() {
HttpService::build()
.finish(|_| ok::<_, ()>(Response::Ok().body(STR)))
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.shead("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -276,7 +284,8 @@ async fn test_h2_head_binary() {
ok::<_, ()>(Response::Ok().content_length(STR.len() as u64).body(STR))
})
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.shead("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -300,7 +309,8 @@ async fn test_h2_head_binary2() {
HttpService::build()
.h2(|_| ok::<_, ()>(Response::Ok().body(STR)))
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.shead("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -325,7 +335,8 @@ async fn test_h2_body_length() {
)
})
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand All @@ -348,7 +359,8 @@ async fn test_h2_body_chunked_explicit() {
)
})
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert!(response.status().is_success());
Expand Down Expand Up @@ -376,7 +388,8 @@ async fn test_h2_response_http_error_handling() {
}))
}))
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
Expand All @@ -392,7 +405,8 @@ async fn test_h2_service_error() {
HttpService::build()
.h2(|_| err::<Response, Error>(error::ErrorBadRequest("error")))
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert_eq!(response.status(), http::StatusCode::BAD_REQUEST);
Expand All @@ -408,7 +422,8 @@ async fn test_h1_service_error() {
HttpService::build()
.h1(|_| err::<Response, Error>(error::ErrorBadRequest("error")))
.rustls(ssl_acceptor())
});
})
.await;

let response = srv.sget("/").send().await.unwrap();
assert_eq!(response.status(), http::StatusCode::BAD_REQUEST);
Expand Down
Loading

0 comments on commit e718f65

Please sign in to comment.