diff --git a/migra-cli/src/path.rs b/migra-cli/src/path.rs index c15e0c8..eb7ca42 100644 --- a/migra-cli/src/path.rs +++ b/migra-cli/src/path.rs @@ -34,8 +34,8 @@ impl PathBuilder { #[cfg(test)] mod tests { - use crate::path::Path; - use crate::path::PathBuilder; + use super::Path; + use super::PathBuilder; #[test] fn create_path_builder() { diff --git a/migra-cli/tests/common/mod.rs b/migra-cli/tests/common/mod.rs index 64b1bb5..b42834f 100644 --- a/migra-cli/tests/common/mod.rs +++ b/migra-cli/tests/common/mod.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] pub use assert_cmd::prelude::*; pub use predicates::str::contains; pub use std::process::Command; diff --git a/migra-cli/tests/init.rs b/migra-cli/tests/init.rs new file mode 100644 index 0000000..fce885e --- /dev/null +++ b/migra-cli/tests/init.rs @@ -0,0 +1,53 @@ +mod common; +use common::*; +use std::fs; + +#[test] +fn init_manifest_with_default_config() -> TestResult { + Command::cargo_bin("migra")? + .arg("init") + .assert() + .success() + .stdout(contains("Created Migra.toml")); + + let content = fs::read_to_string("Migra.toml")?; + + assert_eq!( + content, + r#"root = "database" + +[database] +connection = "$DATABASE_URL" +"#); + + fs::remove_file("Migra.toml")?; + + Ok(()) +} + +#[test] +fn init_manifest_in_custom_path() -> TestResult { + let manifest_path = path_to_file("Migra.toml"); + + Command::cargo_bin("migra")? + .arg("-c") + .arg(&manifest_path) + .arg("init") + .assert() + .success() + .stdout(contains(format!("Created {}", manifest_path.as_str()))); + + let content = fs::read_to_string(&manifest_path)?; + + assert_eq!( + content, + r#"root = "database" + +[database] +connection = "$DATABASE_URL" +"#); + + fs::remove_file(&manifest_path)?; + + Ok(()) +} \ No newline at end of file diff --git a/migra-cli/tests/lib.rs b/migra-cli/tests/lib.rs index 07441e6..cee91dc 100644 --- a/migra-cli/tests/lib.rs +++ b/migra-cli/tests/lib.rs @@ -1,3 +1 @@ -mod common; - -pub use common::*; +mod common; \ No newline at end of file diff --git a/migra-cli/tests/list.rs b/migra-cli/tests/list.rs index 7f2dbe5..fb92cc6 100644 --- a/migra-cli/tests/list.rs +++ b/migra-cli/tests/list.rs @@ -1,7 +1,6 @@ mod common; use common::*; -use std::io::Write; #[test] fn empty_migration_list() -> TestResult {