diff --git a/packages/backend/Cargo.lock b/packages/backend/Cargo.lock index d372bac69f..26cc46f78e 100644 --- a/packages/backend/Cargo.lock +++ b/packages/backend/Cargo.lock @@ -307,6 +307,7 @@ dependencies = [ name = "macros" version = "0.1.0" dependencies = [ + "config", "lazy_static", ] diff --git a/packages/backend/crates/macros/Cargo.toml b/packages/backend/crates/macros/Cargo.toml index 791e48996c..f7faeb2313 100644 --- a/packages/backend/crates/macros/Cargo.toml +++ b/packages/backend/crates/macros/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" [dependencies] lazy_static = "1.4.0" +config = { path = "../config" } diff --git a/packages/backend/crates/macros/src/lib.rs b/packages/backend/crates/macros/src/lib.rs index 529a61f102..6dc6d68524 100644 --- a/packages/backend/crates/macros/src/lib.rs +++ b/packages/backend/crates/macros/src/lib.rs @@ -1,3 +1,4 @@ pub mod environment; +pub mod tests; //pub use environment::*; diff --git a/packages/backend/crates/macros/src/tests.rs b/packages/backend/crates/macros/src/tests.rs new file mode 100644 index 0000000000..021443eb7d --- /dev/null +++ b/packages/backend/crates/macros/src/tests.rs @@ -0,0 +1,11 @@ +#![macro_use] + +#[macro_export] +macro_rules! setup_test_config { + () => { + #[cfg(test)] + config::init_config(Path::new( + &env::var("CK_TEST_CONFIG").expect("CK_TEST_CONFIG environment variable not set"), + )).expect("Could not initialize test config"); + } +} diff --git a/packages/backend/crates/server/Cargo.toml b/packages/backend/crates/server/Cargo.toml index 62f8083fba..b8af2d44db 100644 --- a/packages/backend/crates/server/Cargo.toml +++ b/packages/backend/crates/server/Cargo.toml @@ -9,4 +9,5 @@ edition = "2021" axum = "0.6.18" tokio = { version = "1.28.1", features = ["full"] } config = { path = "../config" } +macros = { path = "../macros" } anyhow = "1.0.71" diff --git a/packages/backend/crates/server/src/lib.rs b/packages/backend/crates/server/src/lib.rs index 262dd6f5d3..6149c49894 100644 --- a/packages/backend/crates/server/src/lib.rs +++ b/packages/backend/crates/server/src/lib.rs @@ -36,3 +36,13 @@ pub fn init() -> anyhow::Result<()> { Ok(()) } + +#[cfg(test)] +mod tests { + use std::{env, path::Path}; + + #[test] + fn test() { + macros::test_setup_config!(); + } +} diff --git a/packages/backend/package.json b/packages/backend/package.json index 8db84c21e0..d32be74efc 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -10,6 +10,6 @@ "build": "cargo build --profile ${NODE_ENV:=development}", "revertmigration": "typeorm migration:revert -d ormconfig.js", "lint": "cargo check", - "test": "cargo test --workspace" + "test": "CK_TEST_CONFIG='../../.config/test.yml' cargo test --workspace" } }