From 77d15630ca3e5b2ce06dc23850b4c41ea5c64051 Mon Sep 17 00:00:00 2001 From: LukeMathWalker Date: Mon, 15 Feb 2021 21:28:36 +0000 Subject: [PATCH] Fix test. --- src/startup.rs | 9 +++++---- tests/api/helpers.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/startup.rs b/src/startup.rs index aa68ba0..6b93720 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -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> { diff --git a/tests/api/helpers.rs b/tests/api/helpers.rs index 661824d..29cc2f9 100644 --- a/tests/api/helpers.rs +++ b/tests/api/helpers.rs @@ -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 {