mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-24 16:30:26 +00:00
This splits up the code into a `lib` and a `bin` to make the runtime usable from other crates. Co-authored-by: Paweł Romanowski <pawroman@pawroman.dev>
32 lines
772 B
Rust
32 lines
772 B
Rust
use http::StatusCode;
|
|
use wiremock::matchers::path;
|
|
use wiremock::{Mock, MockServer, ResponseTemplate};
|
|
|
|
#[allow(unused)]
|
|
pub async fn get_mock_server<S>(response_code: S) -> MockServer
|
|
where
|
|
S: Into<StatusCode>,
|
|
{
|
|
get_mock_server_with_content(response_code, None).await
|
|
}
|
|
|
|
pub async fn get_mock_server_with_content<S>(response_code: S, content: Option<&str>) -> MockServer
|
|
where
|
|
S: Into<StatusCode>,
|
|
{
|
|
let mock_server = MockServer::start().await;
|
|
let template = ResponseTemplate::new(response_code.into());
|
|
|
|
let template = if let Some(s) = content {
|
|
template.set_body_string(s)
|
|
} else {
|
|
template
|
|
};
|
|
|
|
Mock::given(path("/"))
|
|
.respond_with(template)
|
|
.mount(&mock_server)
|
|
.await;
|
|
|
|
mock_server
|
|
}
|