I have a CLI application that does some http requests to user input dependant urls.
I used to test this using https://httpbin.org, but that is brittle and doesn'twork when there's no network connection (the site is also very slow right now for some reason).
So I switched to mockito
, for a simple echo test server similar to httpbin's base64 endpoint.
fn setup_mockito_test_server() -> mockito::ServerGuard { let mut server = mockito::Server::new(); server .mock("GET", mockito::Matcher::Regex(r"^/echo/.*$".to_string())) .with_status(200) .with_header("content-type", "text/plain") .with_body_from_request(|req| req.path()[6..].as_bytes().to_owned()) .create(); server}#[test]fn example_test() { let server = setup_mockito_test_server(); let resp = reqwest::blocking::get(format!("{}/echo/foobar", server.url())) .unwrap().text().unwrap(); assert_eq!(resp, "foobar");}
This works great, but to test some different code paths I need to use TLS (https).I did a quick google search but neither mockito
, httpmock
nor wiremock
seem to support this out of the box.
How can I create an equivalent test server with HTTPS support?