summaryrefslogtreecommitdiffstats
path: root/src/remake/api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/remake/api.rs')
-rw-r--r--src/remake/api.rs55
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"))
+ }
+}