mirror of https://github.com/realaravinth/gitpad
feat: add tests for health meta route
parent
6fc667ffc9
commit
9c35c6f99b
|
@ -67,15 +67,17 @@ async fn health(db: DB) -> impl Responder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(build_details);
|
|
||||||
cfg.service(health);
|
cfg.service(health);
|
||||||
|
cfg.service(build_details);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use actix_web::{http::StatusCode, test, App};
|
use actix_web::{http::StatusCode, test, App};
|
||||||
|
|
||||||
|
use crate::api::v1::meta::Health;
|
||||||
use crate::routes::services;
|
use crate::routes::services;
|
||||||
|
use crate::tests::*;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
@ -91,4 +93,22 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,11 +104,9 @@ macro_rules! post_request {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! get_works {
|
macro_rules! get_request {
|
||||||
($app:expr,$route:expr ) => {
|
($app:expr,$route:expr ) => {
|
||||||
let list_sitekey_resp =
|
test::call_service(&$app, test::TestRequest::get().uri($route).to_request()).await
|
||||||
test::call_service(&$app, test::TestRequest::get().uri($route).to_request()).await;
|
|
||||||
assert_eq!(list_sitekey_resp.status(), StatusCode::OK);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue