refactor: extract inline module tests::config
Some checks failed
Test / build (map[name:stable]) (push) Successful in 1m55s
Test / build (map[name:nightly]) (push) Successful in 2m11s
Release Please / Release-plz (push) Failing after 19s

This commit is contained in:
Paul Campbell 2024-12-14 19:49:51 +00:00
parent ff04218172
commit 3ae594c567
2 changed files with 48 additions and 49 deletions

47
src/tests/config.rs Normal file
View file

@ -0,0 +1,47 @@
use super::*;
#[test]
fn load_config() {
//given
let fs = given::a_filesystem();
let file = fs.base().join(f!("{}.toml", NAME));
fs.file(&file)
.write(
[
"[trello]",
"api_key = \"trello-api-key\"",
"api_secret = \"trello-api-secret\"",
"board_name = \"trello-board-name\"",
"",
"[nextcloud]",
"hostname = \"nextcloud-hostname\"",
"username = \"nextcloud-username\"",
"password = \"nextcloud-password\"",
"board_id = 22",
]
.join("\n"),
)
.expect("write file");
let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer());
//when
let_assert!(Ok(config) = AppConfig::load(&ctx));
//then
assert_eq!(
config,
AppConfig {
trello: TrelloConfig {
api_key: s!("trello-api-key").into(),
api_secret: s!("trello-api-secret").into(),
board_name: s!("trello-board-name").into(),
},
nextcloud: NextcloudConfig {
hostname: s!("nextcloud-hostname").into(),
username: s!("nextcloud-username").into(),
password: s!("nextcloud-password").into(),
board_id: 22.into()
}
}
);
}

View file

@ -9,55 +9,7 @@ use crate::{
config::AppConfig, f, init::run, nextcloud::NextcloudConfig, s, trello::TrelloConfig, Ctx, NAME,
};
mod config {
use super::*;
#[test]
fn load_config() {
//given
let fs = given::a_filesystem();
let file = fs.base().join(f!("{}.toml", NAME));
fs.file(&file)
.write(
[
"[trello]",
"api_key = \"trello-api-key\"",
"api_secret = \"trello-api-secret\"",
"board_name = \"trello-board-name\"",
"",
"[nextcloud]",
"hostname = \"nextcloud-hostname\"",
"username = \"nextcloud-username\"",
"password = \"nextcloud-password\"",
"board_id = 22",
]
.join("\n"),
)
.expect("write file");
let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer());
//when
let_assert!(Ok(config) = AppConfig::load(&ctx));
//then
assert_eq!(
config,
AppConfig {
trello: TrelloConfig {
api_key: s!("trello-api-key").into(),
api_secret: s!("trello-api-secret").into(),
board_name: s!("trello-board-name").into(),
},
nextcloud: NextcloudConfig {
hostname: s!("nextcloud-hostname").into(),
username: s!("nextcloud-username").into(),
password: s!("nextcloud-password").into(),
board_id: 22.into()
}
}
);
}
}
mod config;
mod init {
use super::*;