forked from diesel-rs/diesel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration_redo.rs
More file actions
138 lines (113 loc) · 3.57 KB
/
Copy pathmigration_redo.rs
File metadata and controls
138 lines (113 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use support::project;
#[test]
fn migration_redo_runs_the_last_migration_down_and_up() {
let p = project("migration_redo").folder("migrations").build();
p.create_migration(
"12345_create_users_table",
"CREATE TABLE users (id INTEGER PRIMARY KEY);",
"DROP TABLE users;",
);
// Make sure the project is setup
p.command("setup").run();
let result = p.command("migration").arg("redo").run();
let expected_stdout = "\
Rolling back migration 12345_create_users_table
Running migration 12345_create_users_table
";
assert!(result.is_success(), "Result was unsuccessful {:?}", result);
assert!(
result.stdout().contains(expected_stdout),
"Unexpected stdout {}",
result.stdout()
);
}
#[test]
fn migration_redo_respects_migration_dir_var() {
let p = project("migration_redo_var").folder("foo").build();
p.create_migration_in_directory(
"foo",
"12345_create_users_table",
"CREATE TABLE users (id INTEGER PRIMARY KEY);",
"DROP TABLE users;",
);
// Make sure the project is setup
p.command("setup").arg("--migration-dir=foo").run();
let result = p
.command("migration")
.arg("redo")
.arg("--migration-dir=foo")
.run();
let expected_stdout = "\
Rolling back migration 12345_create_users_table
Running migration 12345_create_users_table
";
assert!(result.is_success(), "Result was unsuccessful {:?}", result);
assert!(
result.stdout().contains(expected_stdout),
"Unexpected stdout {}",
result.stdout()
);
}
#[test]
fn migration_redo_respects_migration_dir_env() {
let p = project("migration_redo_env").folder("bar").build();
p.create_migration_in_directory(
"bar",
"12345_create_users_table",
"CREATE TABLE users (id INTEGER PRIMARY KEY);",
"DROP TABLE users;",
);
// Make sure the project is setup
p.command("setup").arg("--migration-dir=bar").run();
let result = p
.command("migration")
.arg("redo")
.env("MIGRATION_DIRECTORY", "bar")
.run();
let expected_stdout = "\
Rolling back migration 12345_create_users_table
Running migration 12345_create_users_table
";
assert!(result.is_success(), "Result was unsuccessful {:?}", result);
assert!(
result.stdout().contains(expected_stdout),
"Unexpected stdout {}",
result.stdout()
);
}
#[test]
fn output_contains_path_to_migration_script() {
let p = project("output_contains_path_to_migration_script")
.folder("migrations")
.build();
p.create_migration(
"output_contains_path_to_migration_script",
"CREATE TABLE users (id INTEGER PRIMARY KEY);",
"DROP TABLE users};",
);
// Make sure the project is setup
p.command("setup").run();
let result = p.command("migration").arg("redo").run();
assert!(!result.is_success(), "Result was successful {:?}", result);
assert!(
result.stdout().contains("down.sql"),
"Unexpected stdout {}",
result.stdout()
);
}
#[test]
fn error_migrations_fails() {
let p = project("redo_error_migrations_fails")
.folder("migrations")
.build();
p.create_migration(
"redo_error_migrations_fails",
"CREATE TABLE users (id INTEGER PRIMARY KEY);",
"DROP TABLE users};",
);
// Make sure the project is setup
p.command("setup").run();
let result = p.command("migration").arg("redo").run();
assert!(!result.is_success());
assert!(result.stderr().contains("Failed with: "));
}