From cd763554306107fd308da3c757d659428d473a72 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Thu, 8 Jun 2023 22:48:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Preparando=20PageTop=20para=20los?= =?UTF-8?q?=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/Cargo.toml | 3 --- pagetop/src/app.rs | 4 ++++ pagetop/tests/health_check.rs | 15 +++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pagetop/Cargo.toml b/pagetop/Cargo.toml index 3ea567e3..3cf6584a 100644 --- a/pagetop/Cargo.toml +++ b/pagetop/Cargo.toml @@ -77,9 +77,6 @@ optional = true version = "0.11.0" optional = true -[dev-dependencies] -tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] } - [build-dependencies] pagetop-build = { version = "0.0", path = "../pagetop-build" } diff --git a/pagetop/src/app.rs b/pagetop/src/app.rs index dbb39ddd..83e17065 100644 --- a/pagetop/src/app.rs +++ b/pagetop/src/app.rs @@ -86,6 +86,10 @@ impl Application { pub fn run(self) -> Result { Ok(self.server) } + + pub fn server(self) -> Server { + self.server + } } fn print_on_startup() { diff --git a/pagetop/tests/health_check.rs b/pagetop/tests/health_check.rs index dd980796..0898211a 100644 --- a/pagetop/tests/health_check.rs +++ b/pagetop/tests/health_check.rs @@ -1,12 +1,15 @@ +use pagetop::prelude::*; + +struct HealthCheck; + +impl ModuleTrait for HealthCheck {} + async fn spawn_app() { - let server = pagetop::Application::prepare(None) - .await? - .run()? - .expect("Failed to prepare server"); - let _ = tokio::spawn(server); + let server = Application::prepare(&HealthCheck).unwrap().server(); + let _ = actix_web::rt::spawn(server); } -#[tokio::test] +#[actix_web::test] async fn health_check_works() { spawn_app(); }