From e3c387937664f2d32393452a05b2c2982bbaaecd Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Mon, 22 Feb 2021 00:34:13 +0300 Subject: [PATCH] chore: add tests for upgrade command --- migra-cli/tests/commands.rs | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/migra-cli/tests/commands.rs b/migra-cli/tests/commands.rs index 6d143ce..6e6a1b1 100644 --- a/migra-cli/tests/commands.rs +++ b/migra-cli/tests/commands.rs @@ -337,3 +337,47 @@ mod make { Ok(()) } } + +mod upgrade { + use super::*; + + #[test] + fn applied_all_migrations() -> TestResult { + let env = Env::new(DATABASE_URL_DEFAULT_ENV_NAME, DATABASE_URL_ENV_VALUE); + + Command::cargo_bin("migra")? + .arg("-c") + .arg(path_to_file("Migra_env.toml")) + .arg("up") + .assert() + .success(); + + let mut conn = postgres::Client::connect(DATABASE_URL_ENV_VALUE, postgres::NoTls)?; + let res = conn.query("SELECT p.id, a.id FROM persons AS p, articles AS a", &[])?; + + assert_eq!( + res.into_iter() + .map(|row| (row.get(0), row.get(1))) + .collect::>(), + Vec::new() + ); + + Command::cargo_bin("migra")? + .arg("-c") + .arg(path_to_file("Migra_env.toml")) + .arg("down") + .assert() + .success(); + + Command::cargo_bin("migra")? + .arg("-c") + .arg(path_to_file("Migra_env.toml")) + .arg("down") + .assert() + .success(); + + drop(env); + + Ok(()) + } +}