refactor: extract inline module tests::given
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 1m58s
Test / build (map[name:stable]) (push) Successful in 4m12s
Release Please / Release-plz (push) Failing after 1m47s

This commit is contained in:
Paul Campbell 2024-12-14 19:51:14 +00:00
parent d48ba1c090
commit d45e7a8443
2 changed files with 61 additions and 63 deletions

60
src/tests/given.rs Normal file
View file

@ -0,0 +1,60 @@
use super::*;
use crate::nextcloud::NextcloudConfig;
use crate::trello::TrelloConfig;
use crate::{s, FullCtx};
use kxio::{
fs::{FileSystem, TempFileSystem},
net::{MockNet, Net},
print::Printer,
};
pub(crate) fn a_context(fs: FileSystem, net: Net, prt: Printer) -> Ctx {
Ctx { fs, net, prt }
}
pub(crate) fn a_filesystem() -> TempFileSystem {
kxio::fs::temp().expect("temp fs")
}
pub(crate) fn a_network() -> MockNet {
kxio::net::mock()
}
pub(crate) fn a_printer() -> Printer {
kxio::print::test()
}
pub(crate) fn a_trello_config() -> TrelloConfig {
TrelloConfig {
api_key: s!("trello-api-key").into(),
api_secret: s!("trello-api-secret").into(),
board_name: s!("trello-board-name").into(),
}
}
pub(crate) fn a_nextcloud_config() -> NextcloudConfig {
let hostname = s!("host-name").into();
let username = s!("username").into();
let password = s!("password").into();
let board_id = 2.into();
NextcloudConfig {
hostname,
username,
password,
board_id,
}
}
pub(crate) fn a_full_context(fs: TempFileSystem, mock_net: MockNet) -> FullCtx {
FullCtx {
fs: fs.as_real(),
net: mock_net.into(),
prt: a_printer(),
cfg: AppConfig {
trello: a_trello_config(),
nextcloud: a_nextcloud_config(),
},
}
}

View file

@ -10,68 +10,6 @@ use crate::{
}; };
mod config; mod config;
pub(crate) mod given;
mod init; mod init;
mod template; mod template;
pub(crate) mod given {
use super::*;
use crate::nextcloud::NextcloudConfig;
use crate::trello::TrelloConfig;
use crate::{s, FullCtx};
use kxio::{
fs::{FileSystem, TempFileSystem},
net::{MockNet, Net},
print::Printer,
};
pub(crate) fn a_context(fs: FileSystem, net: Net, prt: Printer) -> Ctx {
Ctx { fs, net, prt }
}
pub(crate) fn a_filesystem() -> TempFileSystem {
kxio::fs::temp().expect("temp fs")
}
pub(crate) fn a_network() -> MockNet {
kxio::net::mock()
}
pub(crate) fn a_printer() -> Printer {
kxio::print::test()
}
pub(crate) fn a_trello_config() -> TrelloConfig {
TrelloConfig {
api_key: s!("trello-api-key").into(),
api_secret: s!("trello-api-secret").into(),
board_name: s!("trello-board-name").into(),
}
}
pub(crate) fn a_nextcloud_config() -> NextcloudConfig {
let hostname = s!("host-name").into();
let username = s!("username").into();
let password = s!("password").into();
let board_id = 2.into();
NextcloudConfig {
hostname,
username,
password,
board_id,
}
}
pub(crate) fn a_full_context(fs: TempFileSystem, mock_net: MockNet) -> FullCtx {
FullCtx {
fs: fs.as_real(),
net: mock_net.into(),
prt: a_printer(),
cfg: AppConfig {
trello: a_trello_config(),
nextcloud: a_nextcloud_config(),
},
}
}
}