mirror of
https://github.com/CodingIsOurPassion/CodingIsOurPassion.git
synced 2025-01-04 18:59:30 -06:00
26 lines
648 B
Rust
26 lines
648 B
Rust
pub struct TestApp {
|
|
pub socket_addr: std::net::SocketAddr,
|
|
}
|
|
|
|
impl TestApp {
|
|
pub async fn spawn() -> Self {
|
|
let api = lakewatch::startup::Application::new();
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.0:0")
|
|
.await
|
|
.expect("Failed to bind random port!");
|
|
|
|
let socket_addr = api.run(listener, false).await.expect("Failed to run API!");
|
|
|
|
Self { socket_addr }
|
|
}
|
|
|
|
pub fn url(&self, path: &str) -> String {
|
|
return format!(
|
|
"http://{}:{}/{}",
|
|
self.socket_addr.ip(),
|
|
self.socket_addr.port(),
|
|
path
|
|
);
|
|
}
|
|
}
|