diff options
| author | tv <tv@krebsco.de> | 2026-10-26 21:36:09 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-26 21:36:09 +0100 |
| commit | 137b1547f847ff2402ea9e634b64ee2196a75075 (patch) | |
| tree | c6bce410e1c8cb2434be268275220df2afa18fdb /src/remake/api.rs | |
| parent | f1f367d1e2438c87e1e90df14d56aa10f2bd7b8b (diff) | |
add remake tests on the simulator
Diffstat (limited to 'src/remake/api.rs')
| -rw-r--r-- | src/remake/api.rs | 55 |
1 files changed, 55 insertions, 0 deletions
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<H: Host>(State(host): State<H>) -> 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<H: Host>( + 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<H: Host>( + 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<H: Host>(host: &H, id: &str) -> Option<JsonValue> { + let report = load_report(host, id).await?; + Some(serde_json::to_value(report).expect("report")) + } +} |
