chore: add tests for init command
This commit is contained in:
parent
e32a93442f
commit
51f631d900
5 changed files with 57 additions and 6 deletions
|
@ -34,8 +34,8 @@ impl PathBuilder {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::path::Path;
|
use super::Path;
|
||||||
use crate::path::PathBuilder;
|
use super::PathBuilder;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_path_builder() {
|
fn create_path_builder() {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
pub use assert_cmd::prelude::*;
|
pub use assert_cmd::prelude::*;
|
||||||
pub use predicates::str::contains;
|
pub use predicates::str::contains;
|
||||||
pub use std::process::Command;
|
pub use std::process::Command;
|
||||||
|
|
53
migra-cli/tests/init.rs
Normal file
53
migra-cli/tests/init.rs
Normal file
|
@ -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(())
|
||||||
|
}
|
|
@ -1,3 +1 @@
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
pub use common::*;
|
|
|
@ -1,7 +1,6 @@
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_migration_list() -> TestResult {
|
fn empty_migration_list() -> TestResult {
|
||||||
|
|
Reference in a new issue