#![expect(
dead_code,
reason = "mock client is shared across multiple integration-test binaries; \
each binary only references a subset, so the unused-code lint \
would otherwise fire spuriously per-binary."
)]
use std::future::Future;
use std::sync::Mutex;
use saml::http::{HttpClient, HttpRequest, HttpResponse};
pub struct MockHttpClient {
pub recorded: Mutex<Vec<HttpRequest>>,
pub canned_response: Vec<u8>,
pub canned_status: u16,
}
impl MockHttpClient {
pub fn new(canned_response: Vec<u8>, canned_status: u16) -> Self {
Self {
recorded: Mutex::new(Vec::new()),
canned_response,
canned_status,
}
}
}
impl HttpClient for MockHttpClient {
fn send(
&self,
request: HttpRequest,
) -> impl Future<Output = Result<HttpResponse, Box<dyn std::error::Error + Send + Sync>>> + Send
{
let body = self.canned_response.clone();
let status = self.canned_status;
let mut guard = self
.recorded
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
guard.push(request);
drop(guard);
async move {
Ok(HttpResponse {
status,
headers: vec![],
body,
})
}
}
}