64 lines
1.5 KiB
Rust
64 lines
1.5 KiB
Rust
use actix_web::{web, HttpResponse, Responder};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{GIT_COMMIT_HASH, VERSION};
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct BuildDetails {
|
|
pub version: &'static str,
|
|
pub git_commit_hash: &'static str,
|
|
}
|
|
|
|
pub mod routes {
|
|
pub struct Meta {
|
|
pub build_details: &'static str,
|
|
pub health: &'static str,
|
|
}
|
|
|
|
impl Meta {
|
|
pub const fn new() -> Self {
|
|
Self {
|
|
build_details: "/api/v1/meta/build",
|
|
health: "/api/v1/meta/health",
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub const META: routes::Meta = routes::Meta::new();
|
|
|
|
/// emmits build details of the bninary
|
|
#[actix_web_codegen_const_routes::get(path = "META.build_details")]
|
|
async fn build_details() -> impl Responder {
|
|
let build = BuildDetails {
|
|
version: VERSION,
|
|
git_commit_hash: GIT_COMMIT_HASH,
|
|
};
|
|
HttpResponse::Ok().json(build)
|
|
}
|
|
|
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
|
cfg.service(build_details);
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use actix_web::{http::StatusCode, test, App};
|
|
|
|
use super::services;
|
|
|
|
#[actix_rt::test]
|
|
async fn build_details_works() {
|
|
let app = test::init_service(App::new().configure(services)).await;
|
|
|
|
let resp = test::call_service(
|
|
&app,
|
|
test::TestRequest::get()
|
|
.uri(super::META.build_details)
|
|
.to_request(),
|
|
)
|
|
.await;
|
|
assert_eq!(resp.status(), StatusCode::OK);
|
|
}
|
|
}
|