Fix failing test.

This commit is contained in:
LukeMathWalker 2021-02-15 21:26:43 +00:00
parent f2ea222c96
commit 3359c5f921
2 changed files with 6 additions and 5 deletions

View file

@ -10,7 +10,7 @@ use std::net::TcpListener;
use tracing_actix_web::TracingLogger;
pub struct Application {
address: String,
port: u16,
server: Server,
}
@ -35,13 +35,14 @@ impl Application {
configuration.application.host, configuration.application.port
);
let listener = TcpListener::bind(&address)?;
let port = listener.local_addr().unwrap().port();
let server = run(listener, connection_pool, email_client)?;
Ok(Self { address, server })
Ok(Self { port, server })
}
pub fn address(&self) -> &str {
&self.address
pub fn port(&self) -> u16 {
self.port
}
pub async fn run_until_stopped(self) -> Result<(), std::io::Error> {

View file

@ -48,7 +48,7 @@ pub async fn spawn_app() -> TestApp {
let application = Application::build(configuration.clone())
.await
.expect("Failed to build application.");
let address = application.address().to_owned();
let address = format!("http://localhost:{}", application.port());
let _ = tokio::spawn(application.run_until_stopped());
TestApp {