diff --git a/rusqlite_migration/src/tests/helpers.rs b/rusqlite_migration/src/tests/helpers.rs index a5973fb..bfb69e5 100644 --- a/rusqlite_migration/src/tests/helpers.rs +++ b/rusqlite_migration/src/tests/helpers.rs @@ -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;") @@ -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() } diff --git a/rusqlite_migration/src/tests/snapshots/rusqlite_migration__tests__synch__all_valid_test.snap b/rusqlite_migration/src/tests/snapshots/rusqlite_migration__tests__synch__all_valid_test.snap new file mode 100644 index 0000000..fa49fe1 --- /dev/null +++ b/rusqlite_migration/src/tests/snapshots/rusqlite_migration__tests__synch__all_valid_test.snap @@ -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, + }, + ], +} diff --git a/rusqlite_migration/src/tests/synch.rs b/rusqlite_migration/src/tests/synch.rs index 99bcc09..efbb8b2 100644 --- a/rusqlite_migration/src/tests/synch.rs +++ b/rusqlite_migration/src/tests/synch.rs @@ -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,