Skip to content

Commit

Permalink
tests: add test for configuration with deprecated env var name
Browse files Browse the repository at this point in the history
Until it's updated in this repor and the Index repo you can overwrite
the admin token using the new env var name and the old one (deprecated):

- New: `TORRUST_TRACKER__HTTP_API__ACCESS_TOKENS__ADMIN`
- Old (deprecated): `TORRUST_TRACKER_API_ADMIN_TOKEN`

THe new one uses exactly the strcuture and atribute  names in the toml
file, using `__` as the separator for levels.

We can remove the test when we remove the deprecated name.
  • Loading branch information
josecelano committed May 9, 2024
1 parent b0c2f9f commit 43942ce
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/configuration/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ mod tests {
}

#[test]
fn configuration_should_allow_to_overwrite_the_default_tracker_api_token_for_admin() {
fn configuration_should_allow_to_overwrite_the_default_tracker_api_token_for_admin_with_env_var() {
figment::Jail::expect_with(|jail| {
jail.set_env("TORRUST_TRACKER__HTTP_API__ACCESS_TOKENS__ADMIN", "NewToken");

Expand All @@ -559,4 +559,23 @@ mod tests {
Ok(())
});
}

#[test]
fn configuration_should_allow_to_overwrite_the_default_tracker_api_token_for_admin_with_the_deprecated_env_var_name() {
figment::Jail::expect_with(|_jail| {
let info = Info {
tracker_toml: default_config_toml(),
api_admin_token: Some("NewToken".to_owned()),
};

let configuration = Configuration::load(&info).expect("Could not load configuration from file");

assert_eq!(
configuration.http_api.access_tokens.get("admin"),
Some("NewToken".to_owned()).as_ref()
);

Ok(())
});
}
}

0 comments on commit 43942ce

Please sign in to comment.