feat: add health endpoint and tests
This commit is contained in:
parent
68d50b69dd
commit
7cc4a9301f
1 changed files with 21 additions and 31 deletions
|
@ -69,7 +69,7 @@ async fn health(ctx: crate::AppCtx) -> impl Responder {
|
|||
|
||||
resp_builder.db(ctx.db.ping().await);
|
||||
|
||||
HttpResponse::Ok() //.json(resp_builder.build().unwrap())
|
||||
HttpResponse::Ok().json(resp_builder.build().unwrap())
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
|
@ -100,34 +100,24 @@ pub mod tests {
|
|||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
// #[actix_rt::test]
|
||||
// async fn health_works_pg() {
|
||||
// let data = crate::tests::pg::get_data().await;
|
||||
// health_works(data).await;
|
||||
// }
|
||||
//
|
||||
// #[actix_rt::test]
|
||||
// async fn health_works_maria() {
|
||||
// let data = crate::tests::maria::get_data().await;
|
||||
// health_works(data).await;
|
||||
// }
|
||||
//
|
||||
// pub async fn health_works(data: ArcCtx) {
|
||||
// println!("{}", API_V1_ROUTES.meta.health);
|
||||
// let data = &data;
|
||||
// let app = get_app!(data).await;
|
||||
//
|
||||
// let resp = test::call_service(
|
||||
// &app,
|
||||
// test::TestRequest::get()
|
||||
// .uri(API_V1_ROUTES.meta.health)
|
||||
// .to_request(),
|
||||
// )
|
||||
// .await;
|
||||
// assert_eq!(resp.status(), StatusCode::OK);
|
||||
//
|
||||
// let health_resp: Health = test::read_body_json(resp).await;
|
||||
// assert!(health_resp.db);
|
||||
// assert_eq!(health_resp.redis, Some(true));
|
||||
// }
|
||||
#[actix_rt::test]
|
||||
async fn health_works() {
|
||||
use actix_web::test;
|
||||
|
||||
let settings = Settings::new().unwrap();
|
||||
let ctx = AppCtx::new(crate::ctx::Ctx::new(&settings).await);
|
||||
let app = test::init_service(App::new().app_data(ctx.clone()).configure(services)).await;
|
||||
|
||||
let resp = test::call_service(
|
||||
&app,
|
||||
test::TestRequest::get()
|
||||
.uri(API_V1_ROUTES.meta.health)
|
||||
.to_request(),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
|
||||
let health_resp: super::Health = test::read_body_json(resp).await;
|
||||
assert!(health_resp.db);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue