28 lines
695 B
Rust
28 lines
695 B
Rust
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()
|
|
}
|