mirror of
https://github.com/kristoferssolo/zero2prod.git
synced 2026-02-04 06:42:07 +00:00
test: write tests
Finished chapter 3.5
This commit is contained in:
25
tests/health_check.rs
Normal file
25
tests/health_check.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use tokio::net::TcpListener;
|
||||
use zero2prod::app;
|
||||
|
||||
#[tokio::test]
|
||||
async fn health_check() {
|
||||
spawn_app();
|
||||
let client = reqwest::Client::new();
|
||||
let response = client
|
||||
.get("http://localhost:8000/health_check")
|
||||
.send()
|
||||
.await
|
||||
.expect("Failed to execute request.");
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(Some(0), response.content_length());
|
||||
}
|
||||
|
||||
fn spawn_app() {
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 8000));
|
||||
let _ = tokio::spawn(async move {
|
||||
let listener = TcpListener::bind(addr).await.unwrap();
|
||||
axum::serve(listener, app()).await.unwrap();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user