mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-12-02 22:26:31 +00:00
Fix test.
This commit is contained in:
parent
04c53d49da
commit
77d15630ca
2 changed files with 6 additions and 5 deletions
|
@ -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> {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue