initial commit
This commit is contained in:
31
tests/health_check.rs
Normal file
31
tests/health_check.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::net::TcpListener;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn health_check_works() {
|
||||
// Arrange
|
||||
let address = spawn_app();
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
// Perform a 'reqwest' against endpoint
|
||||
|
||||
let response = client
|
||||
.get(&format!("{}/health_check", &address))
|
||||
.send()
|
||||
.await
|
||||
.expect("Failed to execute request.");
|
||||
|
||||
// Assert our test
|
||||
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 to random port");
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
|
||||
let server = mail_app::run(listener).expect("Failed to bind address");
|
||||
|
||||
let _ = tokio::spawn(server);
|
||||
|
||||
format!("http://127.0.0.1:{}", port)
|
||||
}
|
||||
Reference in New Issue
Block a user