add ability to setup temp config before running a test
This commit is contained in:
parent
cbb4df843a
commit
9d90403ec7
7 changed files with 26 additions and 1 deletions
1
packages/backend/Cargo.lock
generated
1
packages/backend/Cargo.lock
generated
|
@ -307,6 +307,7 @@ dependencies = [
|
|||
name = "macros"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"config",
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
|
|
|
@ -7,3 +7,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
lazy_static = "1.4.0"
|
||||
config = { path = "../config" }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub mod environment;
|
||||
pub mod tests;
|
||||
|
||||
//pub use environment::*;
|
||||
|
|
11
packages/backend/crates/macros/src/tests.rs
Normal file
11
packages/backend/crates/macros/src/tests.rs
Normal file
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
|
|
|
@ -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!();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue