From 3941dbed3507d3a8e5d703b956e9ec23a114bf4f Mon Sep 17 00:00:00 2001 From: Vecna Date: Fri, 8 Sep 2023 15:39:50 -0400 Subject: [PATCH] Add endpoint to artificially advance days (for testing) --- crates/lox-distributor/src/lox_context.rs | 14 +++++++++++++- crates/lox-distributor/src/request_handler.rs | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index 2bdad8e..38d67cd 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -113,7 +113,7 @@ impl LoxServerContext { ba_obj.bridge_update(&bridgeline) } - #[cfg(test)] + //#[cfg(test)] /// For testing only: manually advance the day by the given number /// of days. 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 { + 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 { diff --git a/crates/lox-distributor/src/request_handler.rs b/crates/lox-distributor/src/request_handler.rs index 764c7ab..d2b4c46 100644 --- a/crates/lox-distributor/src/request_handler.rs +++ b/crates/lox-distributor/src/request_handler.rs @@ -55,6 +55,11 @@ pub async fn handle( let bytes = body::to_bytes(req.into_body()).await.unwrap(); 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. Ok(Response::builder()