feat(test): health_check route
This commit is contained in:
parent
229ede166c
commit
8d90f9e8e6
1909
Cargo.lock
generated
Normal file
1909
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@ -5,4 +5,14 @@ edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "src/main.rs"
|
||||
name = "email_newsletter_api"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4.5.1"
|
||||
reqwest = "0.12.2"
|
||||
tokio = { version = "1.36.0", features = ["full"] }
|
||||
|
16
src/lib.rs
Normal file
16
src/lib.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
||||
|
||||
async fn healthcheck_route() -> impl Responder{
|
||||
return HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
|
||||
pub async fn run() -> Result<(), std::io::Error>{
|
||||
HttpServer::new(||{
|
||||
App::new()
|
||||
.route("/healthcheck", web::get().to(healthcheck_route))
|
||||
})
|
||||
.bind("127.0.0.1:8000")?
|
||||
.run()
|
||||
.await
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use email_newsletter_api::run;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), std::io::Error>{
|
||||
run().await
|
||||
}
|
||||
|
15
tests/health_check.rs
Normal file
15
tests/health_check.rs
Normal file
@ -0,0 +1,15 @@
|
||||
#[tokio::test]
|
||||
async fn health_check_works(){
|
||||
spawn_app().await.expect("Failed to spawn our app.");
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let response = client.get("http://127.0.0.1:8000/health_check").send().await.expect("Failed to execute health_check request.");
|
||||
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(Some(0), response.content_length());
|
||||
}
|
||||
|
||||
async fn spawn_app() -> Result<(), std::io::Error> {
|
||||
email_newsletter_api::run().await
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user