health_check test
This commit is contained in:
27
tests/health_check.rs
Normal file
27
tests/health_check.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use tokio::net::TcpListener;
|
||||
use zero2prod::app;
|
||||
|
||||
#[tokio::test]
|
||||
async fn health_check_works() {
|
||||
let addr = spawn_app().await;
|
||||
let client = reqwest::Client::new();
|
||||
let response = client
|
||||
.get(&format!("http://{}/health_check", addr))
|
||||
.send()
|
||||
.await
|
||||
.expect("Failed to execute request");
|
||||
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(Some(0), response.content_length());
|
||||
}
|
||||
|
||||
async fn spawn_app() -> String {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
|
||||
tokio::spawn(async move {
|
||||
axum::serve(listener, app()).await.unwrap();
|
||||
});
|
||||
|
||||
addr.to_string()
|
||||
}
|
||||
Reference in New Issue
Block a user