Archived
1
0
Fork 0

chore: add tests for init command

This commit is contained in:
Dmitriy Pleshevskiy 2021-02-20 23:07:40 +03:00
parent e32a93442f
commit 51f631d900
5 changed files with 57 additions and 6 deletions

View file

@ -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() {

View file

@ -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
View 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(())
}

View file

@ -1,3 +1 @@
mod common; mod common;
pub use common::*;

View file

@ -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 {