Add endpoint to artificially advance days (for testing)

This commit is contained in:
Vecna 2023-09-08 15:39:50 -04:00
parent 4f67f033c7
commit 3941dbed35
2 changed files with 18 additions and 1 deletions

View File

@ -113,7 +113,7 @@ impl LoxServerContext {
ba_obj.bridge_update(&bridgeline) ba_obj.bridge_update(&bridgeline)
} }
#[cfg(test)] //#[cfg(test)]
/// For testing only: manually advance the day by the given number /// For testing only: manually advance the day by the given number
/// of days. /// of days.
pub fn advance_days_test(&self, num: u16) { pub fn advance_days_test(&self, num: u16) {
@ -388,6 +388,18 @@ impl LoxServerContext {
} }
} }
} }
//#[cfg(test)]
/// For testing only: manually advance the day by the given number
/// of days and send back the current day.
pub fn advance_days_with_response_test(self, request: Bytes) -> Response<Body> {
let req: u16 = match serde_json::from_slice(&request) {
Ok(req) => req,
Err(e) => return prepare_error_header(e.to_string()),
};
self.advance_days_test(req);
self.send_today()
}
} }
fn prepare_header(response: String) -> Response<Body> { fn prepare_header(response: String) -> Response<Body> {

View File

@ -55,6 +55,11 @@ pub async fn handle(
let bytes = body::to_bytes(req.into_body()).await.unwrap(); let bytes = body::to_bytes(req.into_body()).await.unwrap();
cloned_context.verify_and_send_blockage_migration(bytes) cloned_context.verify_and_send_blockage_migration(bytes)
}), }),
//#[cfg(test)]
(&Method::POST, "/advancedays") => Ok::<_, Infallible>({
let bytes = body::to_bytes(req.into_body()).await.unwrap();
cloned_context.advance_days_with_response_test(bytes)
}),
_ => { _ => {
// Return 404 not found response. // Return 404 not found response.
Ok(Response::builder() Ok(Response::builder()