I wanna run the same Rust program (main.rs) multiple times, but with different values on the static variables. This is for integration testing. How do I do it?
My current (failed) attempt does something like this:
const VALUE1: [&str; 3] = ["1", "2", "3"];
const VALUE2: [&str; 3] = ["1", "2", "3"];
const VALUE3: [&str; 3] = ["1", "2", "3"];
#[tokio::test]
async fn integration_tester() {
helpers::set_init_vars();
let mut futures = Vec::new();
for index in 1..=2 {
let expected_static_values = EXPECTED_STATIC_VALUES[index];
let future = {
set_next_var(index);
mock_runtime(expected_static_values)
};
futures.push(future);
}
join_all(futures).await;
}
pub fn set_init_vars() {
env::set_var("ENV_VAR1", "VALUE1");
env::set_var("ENV_VAR2", "VALUE2");
[...]
env::set_var("ENV_VAR99", "VALUE99");
}
pub fn set_next_var(index: usize) {
let value1 = VALUE1[index];
let value2 = VALUE2[index];
let value3 = VALUE3[index];
env::set_var("ENV_VAR1", value1);
env::set_var("ENV_VAR2", value2);
env::set_var("ENV_VAR3", value3);
}
mock_runtime(..)
is basically a copy-paste of the main function of the program I'm trying to integration-test, with minor modifications. The static variables (global variables) in the program are different depending on the environment variables you insert into the program (and i wanna integration-test the program's behavior given a large variety of env combinations).