test(cli): stabilize HTTP fixture response dates

This commit is contained in:
ldm0
2026-10-11 18:06:49 +08:00
parent f57431be78
commit 31af12ca14
+11 -11
View File
@@ -3,6 +3,7 @@ use axum::{
Router,
extract::Path,
http::{HeaderValue, StatusCode, header},
middleware::map_response,
response::{Html, IntoResponse, Redirect, Response},
routing::get,
};
@@ -25,6 +26,15 @@ const HTML: &str =
"<!doctype html><title>HTTP fixture</title><h1>HTTP fixture</h1><p>response body</p>";
const RAW_BODY: &[u8] = b"\0\xffraw HTTP error body";
async fn fixture_response_date(mut response: Response) -> Response {
// Separate CLI invocations must receive identical headers for JSON comparisons.
response.headers_mut().insert(
header::DATE,
HeaderValue::from_static("Wed, 01 Jan 2020 00:00:00 GMT"),
);
response
}
struct HttpFailureFixture {
base_url: String,
task: JoinHandle<()>,
@@ -100,17 +110,7 @@ impl HttpFailureFixture {
.into_response()
}),
)
.layer(axum::middleware::map_response(
|mut response: Response| async move {
// Separate requests must have identical fixture headers when
// the test compares their complete selected-format output.
response.headers_mut().insert(
header::DATE,
HeaderValue::from_static("Thu, 01 Jan 1970 00:00:00 GMT"),
);
response
},
));
.layer(map_response(fixture_response_date));
let listener = TcpListener::bind("127.0.0.1:0").await?;
let base_url = format!("http://{}", listener.local_addr()?);
let task = tokio::spawn(async move {