feat(test): server setup and teardown for tests

- Application server will now be setup on EVERY test and closed after
that test
This commit is contained in:
2024-03-29 15:36:54 -04:00
parent 8d90f9e8e6
commit cd677039b1
3 changed files with 24 additions and 12 deletions

View File

@@ -1,16 +1,17 @@
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use actix_web::{web, App, HttpResponse, HttpServer};
use actix_web::dev::Server;
async fn healthcheck_route() -> impl Responder{
async fn healthcheck_route() -> HttpResponse {
return HttpResponse::Ok().finish()
}
pub async fn run() -> Result<(), std::io::Error>{
HttpServer::new(||{
pub fn run() -> Result<Server, std::io::Error>{
let server = HttpServer::new(||{
App::new()
.route("/healthcheck", web::get().to(healthcheck_route))
.route("/health_check", web::get().to(healthcheck_route))
})
.bind("127.0.0.1:8000")?
.run()
.await
.run();
Ok(server)
}

View File

@@ -2,5 +2,7 @@ use email_newsletter_api::run;
#[tokio::main]
async fn main() -> Result<(), std::io::Error>{
run().await
// Move the error up the call stack
// otherwise await for the HttpServer
run()?.await
}