diff --git a/src/tests/init.rs b/src/tests/init.rs new file mode 100644 index 0000000..ac1ff98 --- /dev/null +++ b/src/tests/init.rs @@ -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")); +} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 1ed14da..e0557e4 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -10,46 +10,7 @@ use crate::{ }; mod config; - -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 init; mod template { use super::*;