refactor: extract inline module tests::init
This commit is contained in:
parent
3ae594c567
commit
9db75b81c0
2 changed files with 38 additions and 40 deletions
37
src/tests/init.rs
Normal file
37
src/tests/init.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use test_log::test;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn when_file_does_not_exist_should_create() {
|
||||||
|
//given
|
||||||
|
let fs = given::a_filesystem();
|
||||||
|
let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer());
|
||||||
|
|
||||||
|
//when
|
||||||
|
let_assert!(Ok(_) = run(&ctx));
|
||||||
|
|
||||||
|
//then
|
||||||
|
let path = ctx.fs.base().join(f!("{NAME}.toml"));
|
||||||
|
let file = ctx.fs.file(&path);
|
||||||
|
let contents = file.reader().expect("read file").to_string();
|
||||||
|
assert_eq!(contents, include_str!("../default-config.toml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn when_file_exists_should_err() {
|
||||||
|
//given
|
||||||
|
let fs = given::a_filesystem();
|
||||||
|
let path = fs.base().join(f!("{NAME}.toml"));
|
||||||
|
let file = fs.file(&path);
|
||||||
|
file.write("").expect("create file");
|
||||||
|
|
||||||
|
let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer());
|
||||||
|
//when
|
||||||
|
let_assert!(Err(err) = run(&ctx));
|
||||||
|
|
||||||
|
//then
|
||||||
|
assert!(err
|
||||||
|
.to_string()
|
||||||
|
.contains("File already exists - not overwriting"));
|
||||||
|
}
|
|
@ -10,46 +10,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
|
mod init;
|
||||||
mod init {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use test_log::test;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn when_file_does_not_exist_should_create() {
|
|
||||||
//given
|
|
||||||
let fs = given::a_filesystem();
|
|
||||||
let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer());
|
|
||||||
|
|
||||||
//when
|
|
||||||
let_assert!(Ok(_) = run(&ctx));
|
|
||||||
|
|
||||||
//then
|
|
||||||
let path = ctx.fs.base().join(f!("{NAME}.toml"));
|
|
||||||
let file = ctx.fs.file(&path);
|
|
||||||
let contents = file.reader().expect("read file").to_string();
|
|
||||||
assert_eq!(contents, include_str!("../default-config.toml"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn when_file_exists_should_err() {
|
|
||||||
//given
|
|
||||||
let fs = given::a_filesystem();
|
|
||||||
let path = fs.base().join(f!("{NAME}.toml"));
|
|
||||||
let file = fs.file(&path);
|
|
||||||
file.write("").expect("create file");
|
|
||||||
|
|
||||||
let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer());
|
|
||||||
//when
|
|
||||||
let_assert!(Err(err) = run(&ctx));
|
|
||||||
|
|
||||||
//then
|
|
||||||
assert!(err
|
|
||||||
.to_string()
|
|
||||||
.contains("File already exists - not overwriting"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod template {
|
mod template {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue