refactor: extract inline module tests::config
This commit is contained in:
parent
ff04218172
commit
3ae594c567
2 changed files with 48 additions and 49 deletions
47
src/tests/config.rs
Normal file
47
src/tests/config.rs
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
|
@ -9,55 +9,7 @@ use crate::{
|
||||||
config::AppConfig, f, init::run, nextcloud::NextcloudConfig, s, trello::TrelloConfig, Ctx, NAME,
|
config::AppConfig, f, init::run, nextcloud::NextcloudConfig, s, trello::TrelloConfig, Ctx, NAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod config {
|
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 init {
|
mod init {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue