From b83112d35903d7bb83a74e5acfd1815b309906af Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 17 May 2024 23:27:44 +0530 Subject: [PATCH] feat: define types aliases for GenerateRandomStringInterface --- src/main.rs | 15 +++++++++------ src/utils/random_string.rs | 8 ++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 81757cb..e652fae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later - use std::env; use actix_identity::IdentityMiddleware; @@ -11,14 +10,15 @@ use actix_web::{cookie::Key, middleware, App, HttpServer}; use db::migrate::RunMigrations; mod billing; +mod db; mod identity; mod inventory; mod ordering; mod settings; -mod db; +#[cfg(test)] +mod tests; mod utils; - #[actix_web::main] async fn main() { let settings = settings::Settings::new().unwrap(); @@ -39,7 +39,11 @@ async fn main() { let secret_key = Key::from(settings.server.cookie_secret.as_bytes()); let socket_addr = settings.server.get_ip(); - log::info!("Starting server at: {} {}", socket_addr, settings.server.domain); + log::info!( + "Starting server at: {} {}", + socket_addr, + settings.server.domain + ); HttpServer::new(move || { App::new() .wrap(IdentityMiddleware::default()) @@ -53,7 +57,7 @@ async fn main() { .wrap( middleware::DefaultHeaders::new().add(("Permissions-Policy", "interest-cohort=()")), ) - // .configure(auth::adapter::load_adapters(db.pool.clone(), &settings)) + // .configure(auth::adapter::load_adapters(db.pool.clone(), &settings)) .configure(utils::random_string::GenerateRandomString::inject()) }) .bind(&socket_addr) @@ -62,4 +66,3 @@ async fn main() { .await .unwrap(); } - diff --git a/src/utils/random_string.rs b/src/utils/random_string.rs index d61cc95..a1fd9f1 100644 --- a/src/utils/random_string.rs +++ b/src/utils/random_string.rs @@ -7,8 +7,12 @@ use std::sync::Arc; use actix_web::web; use mockall::predicate::*; use mockall::*; +#[cfg(test)] +#[allow(unused_imports)] +use tests::*; -pub type WebGenerateRandomStringInterface = web::Data>; +pub type GenerateRandomStringInterfaceObj = Arc; +pub type WebGenerateRandomStringInterfaceObj = web::Data; #[automock] pub trait GenerateRandomStringInterface: Send + Sync { @@ -34,7 +38,7 @@ impl GenerateRandomStringInterface for GenerateRandomString { impl GenerateRandomString { pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) { - let g = WebGenerateRandomStringInterface::new(Arc::new(GenerateRandomString)); + let g = WebGenerateRandomStringInterfaceObj::new(Arc::new(GenerateRandomString)); let f = move |cfg: &mut web::ServiceConfig| { cfg.app_data(g); };