use super::*;
#[test]
fn grant_stream_health_reports_the_cursor_and_blocks_readiness_before_ready()
-> Result<(), Box<dyn std::error::Error>> {
let state = served(SharedReadinessState::new(
ReadinessState::ready_without_cluster(),
));
let owner = crate::auth_membership::grant_stream::StreamState::for_log(
lys_pass::membership::GrantLog {
identity: "health-log".into(),
epoch: 1,
},
);
state
.grant_stream
.set(owner)
.map_err(|_| "owner already installed")?;
let response = String::from_utf8(response_for_request(
b"GET /health HTTP/1.1\r\n\r\n",
&state,
)?)?;
let health = json_body(&response)?;
assert_eq!(health["grant_stream"]["readiness"], "not_ready");
assert!(health["grant_stream"]["cursor"].is_null());
assert!(health["grant_stream"]["last_error"].is_null());
let response = String::from_utf8(response_for_request(
b"GET /ready HTTP/1.1\r\n\r\n",
&state,
)?)?;
assert_status(&response, 503);
let ready = json_body(&response)?;
assert_eq!(ready["ready"], false);
assert_eq!(
ready["unmet_conditions"],
serde_json::json!(["grant_stream_ready"])
);
Ok(())
}