From 837525424734972462cdbd24f7e083c2b5136c9a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 14 Dec 2024 19:51:14 +0000 Subject: [PATCH] refactor: extract inline module tests::given --- src/tests/given.rs | 60 +++++++++++++++++++++++++++++++++++++++++++ src/tests/mod.rs | 63 +--------------------------------------------- 2 files changed, 61 insertions(+), 62 deletions(-) create mode 100644 src/tests/given.rs diff --git a/src/tests/given.rs b/src/tests/given.rs new file mode 100644 index 0000000..ada6e4e --- /dev/null +++ b/src/tests/given.rs @@ -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(), + }, + } +} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 8cb4175..8617abe 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -12,66 +12,5 @@ use crate::{ mod config; mod init; mod template; +pub(crate) mod given; -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(), - }, - } - } -}