From 9c35c6f99bb3c0b57a5c7af53b0b16d2518e8a08 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sun, 13 Feb 2022 16:27:42 +0530 Subject: [PATCH] feat: add tests for health meta route --- src/api/v1/meta.rs | 22 +++++++++++++++++++++- src/tests.rs | 6 ++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/api/v1/meta.rs b/src/api/v1/meta.rs index 74c9040..6a74b6b 100644 --- a/src/api/v1/meta.rs +++ b/src/api/v1/meta.rs @@ -67,15 +67,17 @@ async fn health(db: DB) -> impl Responder { } pub fn services(cfg: &mut web::ServiceConfig) { - cfg.service(build_details); cfg.service(health); + cfg.service(build_details); } #[cfg(test)] mod tests { use actix_web::{http::StatusCode, test, App}; + use crate::api::v1::meta::Health; use crate::routes::services; + use crate::tests::*; use crate::*; #[actix_rt::test] @@ -91,4 +93,22 @@ mod tests { .await; assert_eq!(resp.status(), StatusCode::OK); } + + #[actix_rt::test] + async fn health_works() { + let config = [ + sqlx_postgres::get_data().await, + sqlx_sqlite::get_data().await, + ]; + + for (db, data) in config.iter() { + let app = get_app!(data, db).await; + let resp = + get_request!(&app, &V1_API_ROUTES.meta.health); + assert_eq!(resp.status(), StatusCode::OK); + + let health: Health = test::read_body_json(resp).await; + assert!(health.db); + } + } } diff --git a/src/tests.rs b/src/tests.rs index 1dee081..8b1fedd 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -104,11 +104,9 @@ macro_rules! post_request { } #[macro_export] -macro_rules! get_works { +macro_rules! get_request { ($app:expr,$route:expr ) => { - let list_sitekey_resp = - test::call_service(&$app, test::TestRequest::get().uri($route).to_request()).await; - assert_eq!(list_sitekey_resp.status(), StatusCode::OK); + test::call_service(&$app, test::TestRequest::get().uri($route).to_request()).await }; }