From 137b1547f847ff2402ea9e634b64ee2196a75075 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 26 Oct 2026 21:36:09 +0100 Subject: add remake tests on the simulator --- src/remake/api.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/remake/api.rs') diff --git a/src/remake/api.rs b/src/remake/api.rs index 0c2ab10..309bdbd 100644 --- a/src/remake/api.rs +++ b/src/remake/api.rs @@ -1009,3 +1009,58 @@ pub(crate) async fn epochs(State(host): State) -> Response { })) .into_response() } + +/// For tests on the simulator (`simtest`): the remake endpoints without HTTP, answering +/// with the status and the JSON body. +#[cfg(test)] +pub(crate) mod testing { + use super::*; + + async fn into_json(response: Response) -> (StatusCode, JsonValue) { + let status = response.status(); + let bytes = axum::body::to_bytes(response.into_body(), usize::MAX) + .await + .expect("response body"); + ( + status, + serde_json::from_slice(&bytes).unwrap_or(JsonValue::Null), + ) + } + + /// `POST /admin/remakes` with `body` and `?force=`. + pub(crate) async fn start( + host: H, + body: JsonValue, + force: Option<&str>, + ) -> (StatusCode, JsonValue) { + let query = StartQuery { + force: force.map(str::to_owned), + ..StartQuery::default() + }; + let mut headers = HeaderMap::new(); + headers.insert( + CONTENT_TYPE, + axum::http::HeaderValue::from_static("application/json"), + ); + into_json(start_kind(host, query, &headers, Bytes::from(body.to_string())).await).await + } + + /// `DELETE /admin/remakes/{id}` with `?force=`. + pub(crate) async fn abort( + host: H, + id: &str, + force: Option<&str>, + ) -> (StatusCode, JsonValue) { + let query = AbortQuery { + wait: false, + force: force.map(str::to_owned), + }; + into_json(abort_by_id(host, id.to_owned(), query).await).await + } + + /// `GET /admin/remakes/{id}`: the report, if the remake exists here. + pub(crate) async fn report(host: &H, id: &str) -> Option { + let report = load_report(host, id).await?; + Some(serde_json::to_value(report).expect("report")) + } +} -- cgit v1.3.1