Skip to content

Commit

Permalink
refactor!: remove unused method in Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed May 8, 2024
1 parent 632c8ba commit b3a1442
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions packages/configuration/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,21 +383,6 @@ impl Configuration {
}
}

/// Loads the configuration from the configuration file.
///
/// # Errors
///
/// Will return `Err` if `path` does not exist or has a bad configuration.
pub fn load_from_file(path: &str) -> Result<Configuration, Error> {
let figment = Figment::new()
.merge(Toml::file(path))
.merge(Env::prefixed("TORRUST_TRACKER_"));

let config: Configuration = figment.extract()?;

Ok(config)
}

/// Saves the default configuration at the given path.
///
/// # Errors
Expand Down Expand Up @@ -459,6 +444,7 @@ impl Configuration {
mod tests {

use crate::v1::Configuration;
use crate::Info;

#[cfg(test)]
fn default_config_toml() -> String {
Expand Down Expand Up @@ -550,10 +536,13 @@ mod tests {

#[test]
fn configuration_should_be_loaded_from_a_toml_config_file() {
figment::Jail::expect_with(|jail| {
jail.create_file("tracker.toml", &default_config_toml())?;
figment::Jail::expect_with(|_jail| {
let info = Info {
tracker_toml: default_config_toml(),
api_admin_token: None,
};

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

assert_eq!(configuration, Configuration::default());

Expand All @@ -564,11 +553,14 @@ mod tests {
#[test]
fn configuration_should_allow_to_overwrite_the_default_tracker_api_token_for_admin() {
figment::Jail::expect_with(|jail| {
jail.create_file("tracker.toml", &default_config_toml())?;

jail.set_env("TORRUST_TRACKER_HTTP_API.ACCESS_TOKENS.ADMIN", "NewToken");

let configuration = Configuration::load_from_file("tracker.toml").expect("Could not load configuration from file");
let info = Info {
tracker_toml: default_config_toml(),
api_admin_token: None,
};

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

assert_eq!(
configuration.http_api.access_tokens.get("admin"),
Expand Down

0 comments on commit b3a1442

Please sign in to comment.