Archived
1
0
Fork 0

chore: add integration tests for list command

This commit is contained in:
Dmitriy Pleshevskiy 2021-02-20 22:32:41 +03:00
parent a5b3d33bef
commit e32a93442f
7 changed files with 153 additions and 0 deletions

View file

@ -0,0 +1,4 @@
root = "./"
[database]
connection = "$DATABASE_URL"

View file

@ -0,0 +1,4 @@
root = "./"
[database]
connection = "postgres://postgres:postgres@localhost:6000/migra_tests"

View file

@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
DROP TABLE articles;

View file

@ -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
);

View file

@ -0,0 +1,6 @@
-- This file should undo anything in `up.sql`
ALTER TABLE articles
DROP COLUMN author_person_id;
DROP TABLE persons;

View file

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

View file

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