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