diff --git a/Cargo.toml b/Cargo.toml index 81344f54..47fc03cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,7 +92,6 @@ const_format = "0.2.32" typed-builder = "0.18.2" num-traits = "0.2.19" log = "0.4.21" -mockall_double = "0.3.1" futures = "0.3.30" validator = { version = "0.18.1", features = ["derive"] } @@ -100,6 +99,7 @@ validator = { version = "0.18.1", features = ["derive"] } cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] } insta = { version = "1.39.0", features = ["toml"] } mockall = "0.12.1" +mockall_double = "0.3.1" rstest = "0.19.0" [workspace] diff --git a/src/app.rs b/src/app.rs index 8ce0f588..93b1f151 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "cli")] use crate::cli::parse_cli; @@ -51,7 +50,7 @@ where #[cfg(not(test))] let context = AppContext::<()>::new::(config).await?; #[cfg(test)] - let context = AppContext::<()>::default(); + let context = AppContext::<()>::test(Some(config), None)?; let state = A::with_state(&context).await?; let context = context.with_custom(state); diff --git a/src/app_context.rs b/src/app_context.rs index 95aca3ca..6a49ab27 100644 --- a/src/app_context.rs +++ b/src/app_context.rs @@ -1,16 +1,17 @@ use crate::app::App; use crate::config::app_config::AppConfig; #[cfg(feature = "db-sql")] -use sea_orm::Database; -#[cfg(feature = "db-sql")] use sea_orm::DatabaseConnection; use std::sync::Arc; -#[cfg(feature = "sidekiq")] -use tracing::info; + +#[cfg(not(test))] +type Inner = AppContextInner; +#[cfg(test)] +type Inner = MockAppContextInner; #[derive(Clone)] pub struct AppContext { - inner: Arc, + inner: Arc, custom: Arc, } @@ -23,54 +24,84 @@ impl AppContext { where A: App, { - #[cfg(feature = "db-sql")] - let db = Database::connect(A::db_connection_options(&config)?).await?; + #[cfg(test)] + // The `config.clone()` here is technically not necessary. However, without it, RustRover + // is giving a "value used after move" error when creating an actual `AppContext` below. + let context = { Self::test(Some(config.clone()), None)? }; - #[cfg(feature = "sidekiq")] - let (redis_enqueue, redis_fetch) = { - let sidekiq_config = &config.service.sidekiq; - let redis_config = &sidekiq_config.custom.redis; - let redis = sidekiq::RedisConnectionManager::new(redis_config.uri.to_string())?; - let redis_enqueue = { - let pool = bb8::Pool::builder().min_idle(redis_config.enqueue_pool.min_idle); - let pool = redis_config - .enqueue_pool - .max_connections - .iter() - .fold(pool, |pool, max_conns| pool.max_size(*max_conns)); - pool.build(redis.clone()).await? - }; - let redis_fetch = if redis_config - .fetch_pool - .max_connections - .iter() - .any(|max_conns| *max_conns == 0) - { - info!( - "Redis fetch pool configured with size of zero, will not start the Sidekiq processor" - ); - None - } else { - let pool = bb8::Pool::builder().min_idle(redis_config.fetch_pool.min_idle); - let pool = redis_config + #[cfg(not(test))] + let context = { + #[cfg(feature = "db-sql")] + let db = sea_orm::Database::connect(A::db_connection_options(&config)?).await?; + + #[cfg(feature = "sidekiq")] + let (redis_enqueue, redis_fetch) = { + let sidekiq_config = &config.service.sidekiq; + let redis_config = &sidekiq_config.custom.redis; + let redis = sidekiq::RedisConnectionManager::new(redis_config.uri.to_string())?; + let redis_enqueue = { + let pool = bb8::Pool::builder().min_idle(redis_config.enqueue_pool.min_idle); + let pool = redis_config + .enqueue_pool + .max_connections + .iter() + .fold(pool, |pool, max_conns| pool.max_size(*max_conns)); + pool.build(redis.clone()).await? + }; + let redis_fetch = if redis_config .fetch_pool .max_connections .iter() - .fold(pool, |pool, max_conns| pool.max_size(*max_conns)); - Some(pool.build(redis.clone()).await?) + .any(|max_conns| *max_conns == 0) + { + tracing::info!("Redis fetch pool configured with size of zero, will not start the Sidekiq processor"); + None + } else { + let pool = bb8::Pool::builder().min_idle(redis_config.fetch_pool.min_idle); + let pool = redis_config + .fetch_pool + .max_connections + .iter() + .fold(pool, |pool, max_conns| pool.max_size(*max_conns)); + Some(pool.build(redis.clone()).await?) + }; + (redis_enqueue, redis_fetch) }; - (redis_enqueue, redis_fetch) + let inner = AppContextInner { + config, + #[cfg(feature = "db-sql")] + db, + #[cfg(feature = "sidekiq")] + redis_enqueue, + #[cfg(feature = "sidekiq")] + redis_fetch, + }; + AppContext { + inner: Arc::new(inner), + custom: Arc::new(()), + } }; - let inner = AppContextInner { - config, - #[cfg(feature = "db-sql")] - db, - #[cfg(feature = "sidekiq")] - redis_enqueue, - #[cfg(feature = "sidekiq")] - redis_fetch, - }; + Ok(context) + } + + #[cfg(test)] + pub(crate) fn test( + config: Option, + #[cfg(not(feature = "sidekiq"))] _redis: Option<()>, + #[cfg(feature = "sidekiq")] redis: Option, + ) -> anyhow::Result> { + let mut inner = MockAppContextInner::default(); + inner + .expect_config() + .return_const(config.unwrap_or(AppConfig::test(None)?)); + #[cfg(feature = "sidekiq")] + if let Some(redis) = redis { + inner.expect_redis_enqueue().return_const(redis.clone()); + inner.expect_redis_fetch().return_const(Some(redis)); + } else { + inner.expect_redis_fetch().return_const(None); + } Ok(AppContext { inner: Arc::new(inner), custom: Arc::new(()), @@ -85,22 +116,22 @@ impl AppContext { } pub fn config(&self) -> &AppConfig { - &self.inner.config + self.inner.config() } #[cfg(feature = "db-sql")] pub fn db(&self) -> &DatabaseConnection { - &self.inner.db + self.inner.db() } #[cfg(feature = "sidekiq")] pub fn redis_enqueue(&self) -> &sidekiq::RedisPool { - &self.inner.redis_enqueue + self.inner.redis_enqueue() } #[cfg(feature = "sidekiq")] pub fn redis_fetch(&self) -> &Option { - &self.inner.redis_fetch + self.inner.redis_fetch() } pub fn custom(&self) -> &T { @@ -108,7 +139,6 @@ impl AppContext { } } -#[derive(Debug)] struct AppContextInner { config: AppConfig, #[cfg(feature = "db-sql")] @@ -122,24 +152,25 @@ struct AppContextInner { redis_fetch: Option, } -#[cfg(test)] -mockall::mock! { - pub AppContext { - pub fn config(&self) -> &AppConfig; - - #[cfg(feature = "db-sql")] - pub fn db(&self) -> &DatabaseConnection; - - #[cfg(feature = "sidekiq")] - pub fn redis_enqueue(&self) -> &sidekiq::RedisPool; +#[cfg_attr(test, mockall::automock)] +#[cfg_attr(test, allow(dead_code))] +impl AppContextInner { + fn config(&self) -> &AppConfig { + &self.config + } - #[cfg(feature = "sidekiq")] - pub fn redis_fetch(&self) -> &Option; + #[cfg(feature = "db-sql")] + fn db(&self) -> &DatabaseConnection { + &self.db + } - pub fn with_custom(self, custom: NewT) -> MockAppContext; + #[cfg(feature = "sidekiq")] + fn redis_enqueue(&self) -> &sidekiq::RedisPool { + &self.redis_enqueue } - impl Clone for AppContext { - fn clone(&self) -> Self; + #[cfg(feature = "sidekiq")] + fn redis_fetch(&self) -> &Option { + &self.redis_fetch } } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index fe52d9e3..6e5616fb 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,7 +1,6 @@ use crate::app::App; #[cfg(test)] use crate::app::MockApp; -#[mockall_double::double] use crate::app_context::AppContext; use crate::cli::roadster::{RoadsterCli, RunRoadsterCommand}; use async_trait::async_trait; diff --git a/src/cli/roadster/migrate.rs b/src/cli/roadster/migrate.rs index bf9744fd..659a32b6 100644 --- a/src/cli/roadster/migrate.rs +++ b/src/cli/roadster/migrate.rs @@ -6,7 +6,6 @@ use serde_derive::Serialize; use tracing::warn; use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; use crate::cli::roadster::{RoadsterCli, RunRoadsterCommand}; diff --git a/src/cli/roadster/mod.rs b/src/cli/roadster/mod.rs index afeaf1fe..ea75720e 100644 --- a/src/cli/roadster/mod.rs +++ b/src/cli/roadster/mod.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "open-api")] use crate::cli::roadster::list_routes::ListRoutesArgs; diff --git a/src/cli/roadster/print_config.rs b/src/cli/roadster/print_config.rs index 9bf977ab..5fc5177e 100644 --- a/src/cli/roadster/print_config.rs +++ b/src/cli/roadster/print_config.rs @@ -5,7 +5,6 @@ use strum_macros::{EnumString, IntoStaticStr}; use tracing::info; use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; use crate::cli::roadster::{RoadsterCli, RunRoadsterCommand}; diff --git a/src/config/app_config.rs b/src/config/app_config.rs index e6c2e87d..b65e2747 100644 --- a/src/config/app_config.rs +++ b/src/config/app_config.rs @@ -93,7 +93,7 @@ impl AppConfig { } #[cfg(test)] - pub(crate) fn empty(config_str: Option<&str>) -> anyhow::Result { + pub(crate) fn test(config_str: Option<&str>) -> anyhow::Result { let config = config_str.unwrap_or( r#" environment = "test" @@ -242,6 +242,6 @@ mod tests { #[test] #[cfg_attr(coverage_nightly, coverage(off))] fn empty() { - AppConfig::empty(None).unwrap(); + AppConfig::test(None).unwrap(); } } diff --git a/src/config/service/http/initializer.rs b/src/config/service/http/initializer.rs index e1d47510..a900cecb 100644 --- a/src/config/service/http/initializer.rs +++ b/src/config/service/http/initializer.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::config::app_config::CustomConfig; use crate::service::http::initializer::normalize_path::NormalizePathConfig; diff --git a/src/config/service/http/middleware.rs b/src/config/service/http/middleware.rs index 7e1a6986..d721e127 100644 --- a/src/config/service/http/middleware.rs +++ b/src/config/service/http/middleware.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::config::app_config::CustomConfig; use crate::service::http::middleware::catch_panic::CatchPanicConfig; @@ -171,7 +170,6 @@ impl MiddlewareConfig { #[cfg(test)] mod tests { use super::*; - use crate::app_context::MockAppContext; use crate::config::app_config::AppConfig; use rstest::rstest; use serde_json::Value; @@ -190,11 +188,10 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let common_config = CommonConfig { enable, diff --git a/src/config/service/http/mod.rs b/src/config/service/http/mod.rs index d815e999..4fc52f42 100644 --- a/src/config/service/http/mod.rs +++ b/src/config/service/http/mod.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::config::service::http::initializer::Initializer; use crate::config::service::http::middleware::Middleware; diff --git a/src/config/service/mod.rs b/src/config/service/mod.rs index a104eca0..afcdd134 100644 --- a/src/config/service/mod.rs +++ b/src/config/service/mod.rs @@ -2,7 +2,6 @@ pub mod http; pub mod worker; -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "http")] use crate::config::service::http::HttpServiceConfig; diff --git a/src/controller/http/docs.rs b/src/controller/http/docs.rs index 4f4fc32f..de03a400 100644 --- a/src/controller/http/docs.rs +++ b/src/controller/http/docs.rs @@ -1,8 +1,4 @@ -#[mockall_double::double] use crate::app_context::AppContext; -use std::ops::Deref; -use std::sync::Arc; - use crate::config::app_config::AppConfig; use crate::controller::http::build_path; use aide::axum::routing::get_with; @@ -12,6 +8,8 @@ use aide::redoc::Redoc; use aide::scalar::Scalar; use axum::response::IntoResponse; use axum::{Extension, Json}; +use std::ops::Deref; +use std::sync::Arc; const BASE: &str = "_docs"; const TAG: &str = "Docs"; @@ -146,8 +144,6 @@ fn api_schema_route(context: &AppContext) -> String { #[cfg(test)] mod tests { use super::*; - use crate::app::MockApp; - use crate::app_context::MockAppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -165,7 +161,7 @@ mod tests { #[case] route: Option, #[case] enabled: bool, ) { - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.default_routes.default_enable = default_enable; config.service.http.custom.default_routes.scalar.enable = enable; config @@ -176,8 +172,7 @@ mod tests { .scalar .route .clone_from(&route); - let mut context = MockAppContext::::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); assert_eq!(scalar_enabled(&context), enabled); assert_eq!( @@ -198,7 +193,7 @@ mod tests { #[case] route: Option, #[case] enabled: bool, ) { - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.default_routes.default_enable = default_enable; config.service.http.custom.default_routes.redoc.enable = enable; config @@ -209,8 +204,7 @@ mod tests { .redoc .route .clone_from(&route); - let mut context = MockAppContext::::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); assert_eq!(redoc_enabled(&context), enabled); assert_eq!( @@ -231,7 +225,7 @@ mod tests { #[case] route: Option, #[case] enabled: bool, ) { - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.default_routes.default_enable = default_enable; config.service.http.custom.default_routes.api_schema.enable = enable; config @@ -242,8 +236,7 @@ mod tests { .api_schema .route .clone_from(&route); - let mut context = MockAppContext::::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); assert_eq!(api_schema_enabled(&context), enabled); assert_eq!( diff --git a/src/controller/http/health.rs b/src/controller/http/health.rs index 5c2029aa..9d497aa6 100644 --- a/src/controller/http/health.rs +++ b/src/controller/http/health.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use crate::controller::http::build_path; @@ -249,8 +248,7 @@ fn health_get_docs(op: TransformOperation) -> TransformOperation { #[cfg(test)] mod tests { - use crate::app::MockApp; - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -268,7 +266,7 @@ mod tests { #[case] route: Option, #[case] enabled: bool, ) { - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.default_routes.default_enable = default_enable; config.service.http.custom.default_routes.health.enable = enable; config @@ -279,8 +277,7 @@ mod tests { .health .route .clone_from(&route); - let mut context = MockAppContext::::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); assert_eq!(super::enabled(&context), enabled); assert_eq!( diff --git a/src/controller/http/mod.rs b/src/controller/http/mod.rs index b1ec4878..5cc76f85 100644 --- a/src/controller/http/mod.rs +++ b/src/controller/http/mod.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "open-api")] use aide::axum::ApiRouter; diff --git a/src/controller/http/ping.rs b/src/controller/http/ping.rs index d209f1c8..dc0b64fa 100644 --- a/src/controller/http/ping.rs +++ b/src/controller/http/ping.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use crate::controller::http::build_path; @@ -88,8 +87,7 @@ fn ping_get_docs(op: TransformOperation) -> TransformOperation { #[cfg(test)] mod tests { - use crate::app::MockApp; - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -107,7 +105,7 @@ mod tests { #[case] route: Option, #[case] enabled: bool, ) { - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.default_routes.default_enable = default_enable; config.service.http.custom.default_routes.ping.enable = enable; config @@ -118,8 +116,7 @@ mod tests { .ping .route .clone_from(&route); - let mut context = MockAppContext::::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); assert_eq!(super::enabled(&context), enabled); assert_eq!( diff --git a/src/middleware/http/auth/jwt/mod.rs b/src/middleware/http/auth/jwt/mod.rs index 44132fe8..cf28a650 100644 --- a/src/middleware/http/auth/jwt/mod.rs +++ b/src/middleware/http/auth/jwt/mod.rs @@ -3,7 +3,6 @@ pub mod ietf; #[cfg(feature = "jwt-openid")] pub mod openid; -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "jwt-ietf")] use crate::middleware::http::auth::jwt::ietf::Claims; diff --git a/src/service/http/builder.rs b/src/service/http/builder.rs index ccfd7f99..101bb81a 100644 --- a/src/service/http/builder.rs +++ b/src/service/http/builder.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "open-api")] use crate::controller::http::default_api_routes; @@ -213,7 +212,7 @@ impl AppServiceBuilder for HttpServiceBuilder { mod tests { use super::*; use crate::app::MockApp; - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::service::http::initializer::MockInitializer; use crate::service::http::middleware::MockMiddleware; @@ -221,10 +220,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn middleware() { // Arrange - let mut context = MockAppContext::<()>::default(); - context - .expect_clone() - .returning(MockAppContext::<()>::default); + let context = AppContext::<()>::test(None, None).unwrap(); let builder = HttpServiceBuilder::::empty(&context); let mut middleware = MockMiddleware::default(); @@ -243,10 +239,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn middleware_not_enabled() { // Arrange - let mut context = MockAppContext::<()>::default(); - context - .expect_clone() - .returning(MockAppContext::<()>::default); + let context = AppContext::<()>::test(None, None).unwrap(); let builder = HttpServiceBuilder::::empty(&context); let mut middleware = MockMiddleware::default(); @@ -264,10 +257,7 @@ mod tests { #[should_panic] fn middleware_already_registered() { // Arrange - let mut context = MockAppContext::<()>::default(); - context - .expect_clone() - .returning(MockAppContext::<()>::default); + let context = AppContext::<()>::test(None, None).unwrap(); let builder = HttpServiceBuilder::::empty(&context); let mut middleware = MockMiddleware::default(); @@ -285,10 +275,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn initializer() { // Arrange - let mut context = MockAppContext::<()>::default(); - context - .expect_clone() - .returning(MockAppContext::<()>::default); + let context = AppContext::<()>::test(None, None).unwrap(); let builder = HttpServiceBuilder::::empty(&context); let mut initializer = MockInitializer::default(); @@ -307,10 +294,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn initializer_not_enabled() { // Arrange - let mut context = MockAppContext::<()>::default(); - context - .expect_clone() - .returning(MockAppContext::<()>::default); + let context = AppContext::<()>::test(None, None).unwrap(); let builder = HttpServiceBuilder::::empty(&context); let mut initializer = MockInitializer::default(); @@ -328,10 +312,7 @@ mod tests { #[should_panic] fn initializer_already_registered() { // Arrange - let mut context = MockAppContext::<()>::default(); - context - .expect_clone() - .returning(MockAppContext::<()>::default); + let context = AppContext::<()>::test(None, None).unwrap(); let builder = HttpServiceBuilder::::empty(&context); let mut initializer = MockInitializer::default(); diff --git a/src/service/http/initializer/default.rs b/src/service/http/initializer/default.rs index 4a81b9cb..e5832663 100644 --- a/src/service/http/initializer/default.rs +++ b/src/service/http/initializer/default.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::initializer::normalize_path::NormalizePathInitializer; use crate::service::http::initializer::Initializer; @@ -17,7 +16,7 @@ pub fn default_initializers( #[cfg(test)] mod tests { - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -27,11 +26,10 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn default_initializers(#[case] default_enable: bool, #[case] expected_size: usize) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.initializer.default_enable = default_enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); // Act let middleware = super::default_initializers(&context); diff --git a/src/service/http/initializer/mod.rs b/src/service/http/initializer/mod.rs index e4db9a26..1ced71d9 100644 --- a/src/service/http/initializer/mod.rs +++ b/src/service/http/initializer/mod.rs @@ -1,7 +1,6 @@ pub mod default; pub mod normalize_path; -#[mockall_double::double] use crate::app_context::AppContext; use axum::Router; diff --git a/src/service/http/initializer/normalize_path.rs b/src/service/http/initializer/normalize_path.rs index 619ac8b9..77ce4bd7 100644 --- a/src/service/http/initializer/normalize_path.rs +++ b/src/service/http/initializer/normalize_path.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::initializer::Initializer; use axum::Router; diff --git a/src/service/http/middleware/catch_panic.rs b/src/service/http/middleware/catch_panic.rs index 67cdc0a6..6452d264 100644 --- a/src/service/http/middleware/catch_panic.rs +++ b/src/service/http/middleware/catch_panic.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::middleware::Middleware; use axum::Router; @@ -49,7 +48,6 @@ impl Middleware for CatchPanicMiddleware { #[cfg(test)] mod tests { use super::*; - use crate::app_context::MockAppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -63,7 +61,7 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config .service @@ -74,8 +72,7 @@ mod tests { .common .enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = CatchPanicMiddleware; @@ -89,7 +86,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn priority(#[case] override_priority: Option, #[case] expected_priority: i32) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -101,8 +98,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = CatchPanicMiddleware; diff --git a/src/service/http/middleware/compression.rs b/src/service/http/middleware/compression.rs index f2704fef..4a51a846 100644 --- a/src/service/http/middleware/compression.rs +++ b/src/service/http/middleware/compression.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::middleware::Middleware; use axum::Router; @@ -92,7 +91,7 @@ impl Middleware for RequestDecompressionMiddleware #[cfg(test)] mod tests { use super::*; - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -106,7 +105,7 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config .service @@ -117,8 +116,7 @@ mod tests { .common .enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = ResponseCompressionMiddleware; @@ -135,7 +133,7 @@ mod tests { #[case] expected_priority: i32, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -147,8 +145,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = ResponseCompressionMiddleware; @@ -166,7 +163,7 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config .service @@ -177,8 +174,7 @@ mod tests { .common .enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = RequestDecompressionMiddleware; @@ -195,7 +191,7 @@ mod tests { #[case] expected_priority: i32, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -207,8 +203,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = RequestDecompressionMiddleware; diff --git a/src/service/http/middleware/default.rs b/src/service/http/middleware/default.rs index 69a000c0..37c7364e 100644 --- a/src/service/http/middleware/default.rs +++ b/src/service/http/middleware/default.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::middleware::catch_panic::CatchPanicMiddleware; use crate::service::http::middleware::compression::RequestDecompressionMiddleware; @@ -37,7 +36,7 @@ pub fn default_middleware( #[cfg(test)] mod tests { - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -47,11 +46,10 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn default_middleware(#[case] default_enable: bool, #[case] expected_size: usize) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); // Act let middleware = super::default_middleware(&context); diff --git a/src/service/http/middleware/mod.rs b/src/service/http/middleware/mod.rs index e77c4b46..13ead900 100644 --- a/src/service/http/middleware/mod.rs +++ b/src/service/http/middleware/mod.rs @@ -7,7 +7,6 @@ pub mod size_limit; pub mod timeout; pub mod tracing; -#[mockall_double::double] use crate::app_context::AppContext; use axum::Router; diff --git a/src/service/http/middleware/request_id.rs b/src/service/http/middleware/request_id.rs index 3a157859..015ce44b 100644 --- a/src/service/http/middleware/request_id.rs +++ b/src/service/http/middleware/request_id.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::middleware::Middleware; use axum::http::HeaderName; @@ -141,7 +140,6 @@ impl Middleware for PropagateRequestIdMiddleware { #[cfg(test)] mod tests { use super::*; - use crate::app_context::MockAppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -155,7 +153,7 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config .service @@ -166,8 +164,7 @@ mod tests { .common .enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = SetRequestIdMiddleware; @@ -184,7 +181,7 @@ mod tests { #[case] expected_priority: i32, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -196,8 +193,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = SetRequestIdMiddleware; @@ -215,7 +211,7 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config .service @@ -226,8 +222,7 @@ mod tests { .common .enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = PropagateRequestIdMiddleware; @@ -244,7 +239,7 @@ mod tests { #[case] expected_priority: i32, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -256,8 +251,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = PropagateRequestIdMiddleware; diff --git a/src/service/http/middleware/sensitive_headers.rs b/src/service/http/middleware/sensitive_headers.rs index 33be492c..830b5184 100644 --- a/src/service/http/middleware/sensitive_headers.rs +++ b/src/service/http/middleware/sensitive_headers.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::middleware::Middleware; use axum::http::{header, HeaderName}; @@ -152,7 +151,7 @@ impl Middleware for SensitiveResponseHeadersMiddlew #[cfg(test)] mod tests { use super::*; - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -166,7 +165,7 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config .service @@ -177,8 +176,7 @@ mod tests { .common .enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = SensitiveRequestHeadersMiddleware; @@ -195,7 +193,7 @@ mod tests { #[case] expected_priority: i32, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -207,8 +205,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = SensitiveRequestHeadersMiddleware; @@ -226,7 +223,7 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config .service @@ -237,8 +234,7 @@ mod tests { .common .enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = SensitiveResponseHeadersMiddleware; @@ -255,7 +251,7 @@ mod tests { #[case] expected_priority: i32, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -267,8 +263,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = SensitiveResponseHeadersMiddleware; diff --git a/src/service/http/middleware/size_limit.rs b/src/service/http/middleware/size_limit.rs index ebba45e1..7f09ec9c 100644 --- a/src/service/http/middleware/size_limit.rs +++ b/src/service/http/middleware/size_limit.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::middleware::Middleware; use anyhow::bail; @@ -81,7 +80,6 @@ impl Middleware for RequestBodyLimitMiddleware { #[cfg(test)] mod tests { use super::*; - use crate::app_context::MockAppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -95,7 +93,7 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config .service @@ -106,8 +104,7 @@ mod tests { .common .enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = RequestBodyLimitMiddleware; @@ -121,7 +118,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn size_limit_priority(#[case] override_priority: Option, #[case] expected_priority: i32) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -133,8 +130,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = RequestBodyLimitMiddleware; diff --git a/src/service/http/middleware/timeout.rs b/src/service/http/middleware/timeout.rs index f7f8ac16..704078cc 100644 --- a/src/service/http/middleware/timeout.rs +++ b/src/service/http/middleware/timeout.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::middleware::Middleware; use axum::Router; @@ -73,7 +72,6 @@ impl Middleware for TimeoutMiddleware { #[cfg(test)] mod tests { use super::*; - use crate::app_context::MockAppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -87,12 +85,11 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config.service.http.custom.middleware.timeout.common.enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = TimeoutMiddleware; @@ -106,7 +103,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn timeout_priority(#[case] override_priority: Option, #[case] expected_priority: i32) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -118,8 +115,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = TimeoutMiddleware; diff --git a/src/service/http/middleware/tracing.rs b/src/service/http/middleware/tracing.rs index 6d2f2235..942498a3 100644 --- a/src/service/http/middleware/tracing.rs +++ b/src/service/http/middleware/tracing.rs @@ -1,4 +1,3 @@ -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::http::middleware::Middleware; use axum::extract::MatchedPath; @@ -170,7 +169,6 @@ impl OnResponse for CustomOnResponse { #[cfg(test)] mod tests { use super::*; - use crate::app_context::MockAppContext; use crate::config::app_config::AppConfig; use rstest::rstest; @@ -184,12 +182,11 @@ mod tests { #[case] expected_enabled: bool, ) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.http.custom.middleware.default_enable = default_enable; config.service.http.custom.middleware.tracing.common.enable = enable; - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = TracingMiddleware; @@ -203,7 +200,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn tracing_priority(#[case] override_priority: Option, #[case] expected_priority: i32) { // Arrange - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if let Some(priority) = override_priority { config .service @@ -215,8 +212,7 @@ mod tests { .priority = priority; } - let mut context = MockAppContext::<()>::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let middleware = TracingMiddleware; diff --git a/src/service/http/service.rs b/src/service/http/service.rs index 792f8575..4e5b44e9 100644 --- a/src/service/http/service.rs +++ b/src/service/http/service.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "cli")] use crate::cli::roadster::RoadsterCli; diff --git a/src/service/mod.rs b/src/service/mod.rs index 985d08cb..8e147b84 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "cli")] use crate::cli::roadster::RoadsterCli; @@ -80,7 +79,7 @@ where #[cfg(test)] mod tests { use crate::app::MockApp; - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::service::{AppServiceBuilder, MockAppService}; use async_trait::async_trait; use rstest::rstest; @@ -89,10 +88,7 @@ mod tests { #[async_trait] impl AppServiceBuilder> for TestAppServiceBuilder { #[cfg_attr(coverage_nightly, coverage(off))] - async fn build( - self, - _context: &MockAppContext<()>, - ) -> anyhow::Result> { + async fn build(self, _context: &AppContext<()>) -> anyhow::Result> { Ok(MockAppService::default()) } } @@ -103,8 +99,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn builder_enabled(#[case] service_enabled: bool) { // Arrange - let mut context = MockAppContext::default(); - context.expect_clone().returning(MockAppContext::default); + let context = AppContext::<()>::test(None, None).unwrap(); let enabled_ctx = MockAppService::::enabled_context(); enabled_ctx.expect().returning(move |_| service_enabled); diff --git a/src/service/registry.rs b/src/service/registry.rs index ae869171..0a45a65c 100644 --- a/src/service/registry.rs +++ b/src/service/registry.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::{AppService, AppServiceBuilder}; use anyhow::bail; @@ -71,7 +70,6 @@ impl ServiceRegistry { mod tests { use super::*; use crate::app::MockApp; - use crate::app_context::MockAppContext; use crate::service::{MockAppService, MockAppServiceBuilder}; use rstest::rstest; @@ -81,8 +79,7 @@ mod tests { #[cfg_attr(coverage_nightly, coverage(off))] fn register_service(#[case] service_enabled: bool, #[case] expected_count: usize) { // Arrange - let mut context = MockAppContext::default(); - context.expect_clone().returning(MockAppContext::default); + let context = AppContext::<()>::test(None, None).unwrap(); let service: MockAppService = MockAppService::default(); let enabled_ctx = MockAppService::::enabled_context(); @@ -112,8 +109,7 @@ mod tests { #[case] expected_count: usize, ) { // Arrange - let mut context = MockAppContext::default(); - context.expect_clone().returning(MockAppContext::default); + let context = AppContext::<()>::test(None, None).unwrap(); let enabled_ctx = MockAppService::::enabled_context(); enabled_ctx.expect().returning(move |_| service_enabled); diff --git a/src/service/runner.rs b/src/service/runner.rs index 5bd28ba4..91ff029a 100644 --- a/src/service/runner.rs +++ b/src/service/runner.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; #[cfg(feature = "cli")] use crate::cli::roadster::RoadsterCli; diff --git a/src/service/worker/sidekiq/app_worker.rs b/src/service/worker/sidekiq/app_worker.rs index 4ead688b..471b3db3 100644 --- a/src/service/worker/sidekiq/app_worker.rs +++ b/src/service/worker/sidekiq/app_worker.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; use async_trait::async_trait; use serde_derive::{Deserialize, Serialize}; diff --git a/src/service/worker/sidekiq/builder.rs b/src/service/worker/sidekiq/builder.rs index 25f77d05..cdcf27a8 100644 --- a/src/service/worker/sidekiq/builder.rs +++ b/src/service/worker/sidekiq/builder.rs @@ -1,11 +1,10 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; use crate::config::service::worker::sidekiq::StaleCleanUpBehavior; use crate::service::worker::sidekiq::app_worker::AppWorker; use crate::service::worker::sidekiq::roadster_worker::RoadsterWorker; use crate::service::worker::sidekiq::service::SidekiqWorkerService; -#[mockall_double::double] +#[cfg_attr(test, mockall_double::double)] use crate::service::worker::sidekiq::Processor; use crate::service::{AppService, AppServiceBuilder}; use anyhow::{anyhow, bail}; @@ -371,7 +370,7 @@ impl<'a> RedisCommands for PooledConnection<'a, RedisConnectionManager> { mod tests { use super::*; use crate::app::MockApp; - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use crate::service::worker::sidekiq::MockProcessor; use bb8::Pool; @@ -456,7 +455,7 @@ mod tests { #[async_trait] impl AppWorker for TestAppWorker { - fn build(context: &MockAppContext<()>) -> Self; + fn build(context: &AppContext<()>) -> Self; } } @@ -466,16 +465,14 @@ mod tests { register_count: usize, periodic_count: usize, ) -> SidekiqWorkerServiceBuilder { - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.default_enable = enabled; config.service.sidekiq.custom.num_workers = 1; config.service.sidekiq.custom.queues = vec!["foo".to_string()]; - let mut context = MockAppContext::default(); - context.expect_config().return_const(config); let redis_fetch = RedisConnectionManager::new("redis://invalid_host:1234").unwrap(); let pool = Pool::builder().build_unchecked(redis_fetch); - context.expect_redis_fetch().return_const(Some(pool)); + let context = AppContext::<()>::test(Some(config), Some(pool)).unwrap(); let mut processor = MockProcessor::::default(); processor @@ -587,7 +584,7 @@ mod tests { #[case] jobs_in_redis: Vec, #[case] expected_jobs_removed: Vec, ) { - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); if clean_stale { config.service.sidekiq.custom.periodic.stale_cleanup = StaleCleanUpBehavior::AutoCleanStale; @@ -595,8 +592,7 @@ mod tests { config.service.sidekiq.custom.periodic.stale_cleanup = StaleCleanUpBehavior::Manual; } - let mut context = MockAppContext::::default(); - context.expect_config().return_const(config); + let context = AppContext::<()>::test(Some(config), None).unwrap(); let mut redis = MockRedisCommands::default(); redis diff --git a/src/service/worker/sidekiq/roadster_worker.rs b/src/service/worker/sidekiq/roadster_worker.rs index 4f99530f..ee105869 100644 --- a/src/service/worker/sidekiq/roadster_worker.rs +++ b/src/service/worker/sidekiq/roadster_worker.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::worker::sidekiq::app_worker::AppWorker; use crate::service::worker::sidekiq::app_worker::AppWorkerConfig; diff --git a/src/service/worker/sidekiq/service.rs b/src/service/worker/sidekiq/service.rs index 5215c7f8..1e7053f3 100644 --- a/src/service/worker/sidekiq/service.rs +++ b/src/service/worker/sidekiq/service.rs @@ -1,5 +1,4 @@ use crate::app::App; -#[mockall_double::double] use crate::app_context::AppContext; use crate::service::worker::sidekiq::builder::SidekiqWorkerServiceBuilder; use crate::service::AppService; @@ -94,7 +93,7 @@ impl SidekiqWorkerService { mod tests { use super::*; use crate::app::MockApp; - use crate::app_context::MockAppContext; + use crate::app_context::AppContext; use crate::config::app_config::AppConfig; use bb8::Pool; use rstest::rstest; @@ -118,15 +117,12 @@ mod tests { #[case] has_redis_fetch: bool, #[case] expected_enabled: bool, ) { - let mut config = AppConfig::empty(None).unwrap(); + let mut config = AppConfig::test(None).unwrap(); config.service.default_enable = default_enabled; config.service.sidekiq.common.enable = sidekiq_enabled; config.service.sidekiq.custom.num_workers = num_workers; config.service.sidekiq.custom.queues = queues; - let mut context = MockAppContext::default(); - context.expect_config().return_const(config); - let pool = if has_redis_fetch { let redis_fetch = RedisConnectionManager::new("redis://invalid_host:1234").unwrap(); let pool = Pool::builder().build_unchecked(redis_fetch); @@ -134,7 +130,8 @@ mod tests { } else { None }; - context.expect_redis_fetch().return_const(pool); + + let context = AppContext::<()>::test(Some(config), pool).unwrap(); assert_eq!( >::enabled(&context),