mirror of
https://github.com/lexmount/moli.git
synced 2026-10-30 16:07:24 +00:00
test(cli): stabilize HTTP fixture response dates
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user