Skip to content

Commit

Permalink
test: added config load unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
eko committed Feb 28, 2020
1 parent 5b23f23 commit 4f63a8d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/config/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,35 @@ pub fn load() -> Config {

return config;
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_config_load() {
// When
let config = load();

// Then we should load default values
assert_eq!(config.ticker, 10);
assert_eq!(config.username, "");
assert_eq!(config.password, "");
assert_eq!(config.client_secret, "wZaRN7rpjn3FoNyF5IFuxg9uMzYJcvOoQ8QWiIqS3hfk6gLhVlG57j5YNoZL2Rtc");

// Given the following environment variable values
env::set_var("EXPORTER_USERNAME", "test-user");
env::set_var("EXPORTER_PASSWORD", "123Password!");
env::set_var("EXPORTER_TICKER", "30");
env::set_var("EXPORTER_CLIENT_SECRET", "123-secret");

// When
let config = load();

// Then we should have these values set
assert_eq!(config.ticker, 30);
assert_eq!(config.username, "test-user");
assert_eq!(config.password, "123Password!");
assert_eq!(config.client_secret, "123-secret");
}
}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ fn run_ticker(config: config_loader::Config) {

let ticker = Ticker::new(0.., Duration::from_secs(config.ticker));
for _ in ticker {
let zones = tado_client.retrieve().await;

metrics::set(zones);
metrics::set(
tado_client.retrieve().await
);
}
});
}

0 comments on commit 4f63a8d

Please sign in to comment.