chore: add integration tests for list command
This commit is contained in:
parent
a5b3d33bef
commit
e32a93442f
7 changed files with 153 additions and 0 deletions
4
migra-cli/tests/data/Migra_env.toml
Normal file
4
migra-cli/tests/data/Migra_env.toml
Normal file
|
@ -0,0 +1,4 @@
|
|||
root = "./"
|
||||
|
||||
[database]
|
||||
connection = "$DATABASE_URL"
|
4
migra-cli/tests/data/Migra_url.toml
Normal file
4
migra-cli/tests/data/Migra_url.toml
Normal file
|
@ -0,0 +1,4 @@
|
|||
root = "./"
|
||||
|
||||
[database]
|
||||
connection = "postgres://postgres:postgres@localhost:6000/migra_tests"
|
|
@ -0,0 +1,3 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
|
||||
DROP TABLE articles;
|
|
@ -0,0 +1,8 @@
|
|||
-- Your SQL goes here
|
||||
|
||||
CREATE TABLE articles (
|
||||
id serial PRIMARY KEY,
|
||||
title text NOT NULL CHECK (length(title) > 0),
|
||||
content text NOT NULL,
|
||||
created_at timestamp NOT NULL DEFAULT current_timestamp
|
||||
);
|
|
@ -0,0 +1,6 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
|
||||
ALTER TABLE articles
|
||||
DROP COLUMN author_person_id;
|
||||
|
||||
DROP TABLE persons;
|
|
@ -0,0 +1,12 @@
|
|||
-- Your SQL goes here
|
||||
|
||||
CREATE TABLE persons (
|
||||
id SERIAL PRIMARY KEY,
|
||||
email text NOT NULL UNIQUE,
|
||||
display_name text NOT NULL,
|
||||
created_at timestamp NOT NULL DEFAULT current_timestamp
|
||||
);
|
||||
|
||||
ALTER TABLE articles
|
||||
ADD COLUMN author_person_id int NULL
|
||||
REFERENCES persons (id) ON UPDATE CASCADE ON DELETE CASCADE;
|
|
@ -81,3 +81,119 @@ Pending migrations:
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_applied_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("ls")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(contains(
|
||||
r#"Applied migrations:
|
||||
—
|
||||
|
||||
Pending migrations:
|
||||
210218232851_create_articles
|
||||
210218233414_create_persons
|
||||
"#,
|
||||
));
|
||||
|
||||
drop(env);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
||||
Command::cargo_bin("migra")?
|
||||
.arg("-c")
|
||||
.arg(path_to_file("Migra_env.toml"))
|
||||
.arg("ls")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(contains(
|
||||
r#"Applied migrations:
|
||||
210218232851_create_articles
|
||||
210218233414_create_persons
|
||||
|
||||
Pending migrations:
|
||||
—
|
||||
"#,
|
||||
));
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn applied_one_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();
|
||||
|
||||
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("ls")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(contains(
|
||||
r#"Applied migrations:
|
||||
210218232851_create_articles
|
||||
|
||||
Pending migrations:
|
||||
210218233414_create_persons
|
||||
"#,
|
||||
));
|
||||
|
||||
Command::cargo_bin("migra")?
|
||||
.arg("-c")
|
||||
.arg(path_to_file("Migra_env.toml"))
|
||||
.arg("down")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
drop(env);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Reference in a new issue