use std::{
path::Path,
process::{Child, Command, Stdio},
time::Duration,
};
use crate::util::http::{test_request::TestRequest, test_response::response_body_str};
struct ChildGuard(Child);
impl Drop for ChildGuard {
fn drop(&mut self) {
let _ = self.0.kill();
let _ = self.0.wait();
}
}
#[tokio::test]
async fn health_over_https() {
let example_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/secure-with-tls");
let child = Command::new(env!("CARGO_BIN_EXE_apimock"))
.current_dir(&example_dir)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("failed to spawn apimock for the secure-with-tls example");
let _guard = ChildGuard(child);
tokio::time::sleep(Duration::from_millis(600)).await;
let response = TestRequest::default("/health", 3443)
.with_https()
.send()
.await;
assert_eq!(response_body_str(response).await, "ok, over https");
}