use poem::{handler, http::StatusCode};
#[handler]
pub fn liveness() -> &'static str {
"ok"
}
pub fn readiness(ready: bool) -> (StatusCode, &'static str) {
if ready {
(StatusCode::OK, "ready")
} else {
(StatusCode::SERVICE_UNAVAILABLE, "not ready")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn should_answer_200_when_dependencies_are_ready() {
let (status, body) = readiness(true);
assert_eq!(status, StatusCode::OK);
assert_eq!(body, "ready");
}
#[test]
fn should_answer_503_when_a_dependency_is_down() {
let (status, _) = readiness(false);
assert_eq!(status, StatusCode::SERVICE_UNAVAILABLE);
}
}