2020-01-15 17:56:07 +01:00
|
|
|
use http_service::Body;
|
|
|
|
use serde_json::json;
|
|
|
|
use std::convert::Into;
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_healthyness() {
|
|
|
|
let mut server = common::setup_server().unwrap();
|
|
|
|
|
|
|
|
// Check that the server is healthy
|
|
|
|
|
|
|
|
let req = http::Request::get("/health").body(Body::empty()).unwrap();
|
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 200);
|
|
|
|
|
|
|
|
// Set the serve Unhealthy
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"health": false,
|
2020-01-23 11:30:18 +01:00
|
|
|
})
|
|
|
|
.to_string()
|
|
|
|
.into_bytes();
|
2020-01-15 17:56:07 +01:00
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::put("/health")
|
|
|
|
.body(Body::from(body))
|
|
|
|
.unwrap();
|
2020-01-15 17:56:07 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 200);
|
|
|
|
|
|
|
|
// Check that the server is unhealthy
|
|
|
|
|
|
|
|
let req = http::Request::get("/health").body(Body::empty()).unwrap();
|
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 503);
|
|
|
|
|
|
|
|
// Set the server healthy
|
|
|
|
|
|
|
|
let body = json!({
|
|
|
|
"health": true,
|
2020-01-23 11:30:18 +01:00
|
|
|
})
|
|
|
|
.to_string()
|
|
|
|
.into_bytes();
|
2020-01-15 17:56:07 +01:00
|
|
|
|
2020-01-23 11:30:18 +01:00
|
|
|
let req = http::Request::put("/health")
|
|
|
|
.body(Body::from(body))
|
|
|
|
.unwrap();
|
2020-01-15 17:56:07 +01:00
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 200);
|
|
|
|
|
|
|
|
// Check if the server is healthy
|
|
|
|
|
|
|
|
let req = http::Request::get("/health").body(Body::empty()).unwrap();
|
|
|
|
let res = server.simulate(req).unwrap();
|
|
|
|
assert_eq!(res.status(), 200);
|
|
|
|
}
|