Skip to content

Commit

Permalink
test: fix formatting and add more snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
cljoly committed Dec 10, 2023
1 parent f4c1c50 commit c54951d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 25 deletions.
51 changes: 27 additions & 24 deletions rusqlite_migration/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@ pub fn m_valid21() -> M<'static> {

pub fn m_valid_fk() -> M<'static> {
M::up(
"CREATE TABLE fk1(a PRIMARY KEY); \
CREATE TABLE fk2( \
a, \
FOREIGN KEY(a) REFERENCES fk1(a) \
); \
INSERT INTO fk1 (a) VALUES ('foo'); \
INSERT INTO fk2 (a) VALUES ('foo'); \
",
r#"
CREATE TABLE fk1(a PRIMARY KEY);
CREATE TABLE fk2(
a,
FOREIGN KEY(a) REFERENCES fk1(a)
);
INSERT INTO fk1 (a) VALUES ('foo');
INSERT INTO fk2 (a) VALUES ('foo');
"#,
)
.foreign_key_check()
}

pub fn m_invalid_down_fk() -> M<'static> {
M::up(
"CREATE TABLE fk1(a PRIMARY KEY); \
CREATE TABLE fk2( \
a, \
FOREIGN KEY(a) REFERENCES fk1(a) \
); \
INSERT INTO fk1 (a) VALUES ('foo'); \
INSERT INTO fk2 (a) VALUES ('foo'); \
",
r#"
CREATE TABLE fk1(a PRIMARY KEY);
CREATE TABLE fk2(
a,
FOREIGN KEY(a) REFERENCES fk1(a)
);
INSERT INTO fk1 (a) VALUES ('foo');
INSERT INTO fk2 (a) VALUES ('foo');
"#,
)
.foreign_key_check()
.down("DROP TABLE fk1;")
Expand All @@ -66,14 +68,15 @@ pub fn m_invalid1() -> M<'static> {

pub fn m_invalid_fk() -> M<'static> {
M::up(
"CREATE TABLE fk1(a PRIMARY KEY); \
CREATE TABLE fk2( \
a, \
FOREIGN KEY(a) REFERENCES fk1(a) \
); \
INSERT INTO fk2 (a) VALUES ('foo'); \
INSERT INTO fk2 (a) VALUES ('bar'); \
",
r#"
CREATE TABLE fk1(a PRIMARY KEY);
CREATE TABLE fk2(
a,
FOREIGN KEY(a) REFERENCES fk1(a)
);
INSERT INTO fk2 (a) VALUES ('foo');
INSERT INTO fk2 (a) VALUES ('bar');
"#,
)
.foreign_key_check()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: migrations
---
Migrations {
ms: [
M {
up: "CREATE TABLE m1(a, b); CREATE TABLE m2(a, b, c);",
up_hook: None,
down: None,
down_hook: None,
foreign_key_check: false,
comment: None,
},
M {
up: "CREATE TABLE t1(a, b);",
up_hook: None,
down: None,
down_hook: None,
foreign_key_check: false,
comment: None,
},
M {
up: "ALTER TABLE t1 RENAME COLUMN b TO c;",
up_hook: None,
down: None,
down_hook: None,
foreign_key_check: false,
comment: None,
},
M {
up: "CREATE TABLE t2(b);",
up_hook: None,
down: None,
down_hook: None,
foreign_key_check: false,
comment: None,
},
M {
up: "ALTER TABLE t2 ADD COLUMN a;",
up_hook: None,
down: None,
down_hook: None,
foreign_key_check: false,
comment: None,
},
M {
up: "\n CREATE TABLE fk1(a PRIMARY KEY);\n CREATE TABLE fk2(\n a,\n FOREIGN KEY(a) REFERENCES fk1(a)\n );\n INSERT INTO fk1 (a) VALUES ('foo');\n INSERT INTO fk2 (a) VALUES ('foo');\n ",
up_hook: None,
down: None,
down_hook: None,
foreign_key_check: true,
comment: None,
},
],
}
4 changes: 3 additions & 1 deletion rusqlite_migration/src/tests/synch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ fn invalid_down_fk_check_test() {

#[test]
fn all_valid_test() {
assert_eq!(Ok(()), Migrations::new(all_valid()).validate());
let migrations = Migrations::new(all_valid());
assert_eq!(Ok(()), migrations.validate());
insta::assert_debug_snapshot!(migrations)
}

// If we encounter a database with a migration number higher than the number of defined migration,
Expand Down

0 comments on commit c54951d

Please sign in to comment.