add ability to setup temp config before running a test

This commit is contained in:
s1idewhist1e 2023-05-15 20:42:06 -07:00
parent cbb4df843a
commit 9d90403ec7
No known key found for this signature in database
GPG key ID: 9CC756BB9B325062
7 changed files with 26 additions and 1 deletions

View file

@ -307,6 +307,7 @@ dependencies = [
name = "macros" name = "macros"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"config",
"lazy_static", "lazy_static",
] ]

View file

@ -7,3 +7,4 @@ edition = "2021"
[dependencies] [dependencies]
lazy_static = "1.4.0" lazy_static = "1.4.0"
config = { path = "../config" }

View file

@ -1,3 +1,4 @@
pub mod environment; pub mod environment;
pub mod tests;
//pub use environment::*; //pub use environment::*;

View 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");
}
}

View file

@ -9,4 +9,5 @@ edition = "2021"
axum = "0.6.18" axum = "0.6.18"
tokio = { version = "1.28.1", features = ["full"] } tokio = { version = "1.28.1", features = ["full"] }
config = { path = "../config" } config = { path = "../config" }
macros = { path = "../macros" }
anyhow = "1.0.71" anyhow = "1.0.71"

View file

@ -36,3 +36,13 @@ pub fn init() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[cfg(test)]
mod tests {
use std::{env, path::Path};
#[test]
fn test() {
macros::test_setup_config!();
}
}

View file

@ -10,6 +10,6 @@
"build": "cargo build --profile ${NODE_ENV:=development}", "build": "cargo build --profile ${NODE_ENV:=development}",
"revertmigration": "typeorm migration:revert -d ormconfig.js", "revertmigration": "typeorm migration:revert -d ormconfig.js",
"lint": "cargo check", "lint": "cargo check",
"test": "cargo test --workspace" "test": "CK_TEST_CONFIG='../../.config/test.yml' cargo test --workspace"
} }
} }