Skip to content

Commit

Permalink
test: add test to preserve API compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
cljoly committed Dec 10, 2023
1 parent 884cb8b commit d6a15b7
Show file tree
Hide file tree
Showing 43 changed files with 348 additions and 53 deletions.
14 changes: 14 additions & 0 deletions rusqlite_migration/src/tests/asynch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,17 @@ async fn test_from_iter() {
let migrations = AsyncMigrations::from_iter(vec![m_valid0(), m_valid10()]);
assert_eq!(Ok(()), migrations.validate().await);
}

#[tokio::test]
async fn test_tokio_rusqlite_conversion() {
use tokio_rusqlite::Error as TError;

insta::assert_debug_snapshot!(
"convert_connection_closed_error",
crate::Error::from(TError::ConnectionClosed)
);
insta::assert_debug_snapshot!(
"convert_rusqlite_error",
crate::Error::from(TError::Rusqlite(rusqlite::Error::InvalidQuery))
);
}
54 changes: 54 additions & 0 deletions rusqlite_migration/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,57 @@ pub fn m_invalid_fk() -> M<'static> {
)
.foreign_key_check()
}

pub fn all_errors() -> Vec<(&'static str, crate::Error)> {
use crate::Error::*;
use crate::ForeignKeyCheckError;
use crate::MigrationDefinitionError;
use crate::SchemaVersion;
use crate::SchemaVersionError;

vec![
(
"rusqlite_error",
RusqliteError {
query: "SELECT * FROM table42;".to_owned(),
err: rusqlite::Error::InvalidQuery,
},
),
(
"specified_schema_version",
SpecifiedSchemaVersion(SchemaVersionError::TargetVersionOutOfRange {
specified: SchemaVersion::NoneSet,
highest: SchemaVersion::NoneSet,
}),
),
(
"migration_definition",
MigrationDefinition(MigrationDefinitionError::NoMigrationsDefined),
),
(
"foreign_key_check",
ForeignKeyCheck(vec![
ForeignKeyCheckError {
table: "t1".to_owned(),
rowid: 1,
parent: "t2".to_owned(),
fkid: 2,
},
ForeignKeyCheckError {
table: "t3".to_owned(),
rowid: 2,
parent: "t4".to_owned(),
fkid: 3,
},
]),
),
("hook", Hook("in hook".to_owned())),
("file_load", FileLoad("file causing problem".to_owned())),
(
"unrecognized",
Unrecognized(Box::new(Hook("unknown".to_owned()))),
),
#[cfg(feature = "async-tokio-rusqlite")]
("connection_closed", ConnectionClosed),
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/asynch.rs
expression: "crate::Error::from(TError::ConnectionClosed)"
---
ConnectionClosed
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: rusqlite_migration/src/tests/asynch.rs
expression: "crate::Error::from(TError::Rusqlite(rusqlite::Error::InvalidQuery))"
---
RusqliteError {
query: "",
err: InvalidQuery,
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: ConnectionClosed
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: FileLoad("file causing problem")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: ForeignKeyCheck([ForeignKeyCheckError { table: "t1", rowid: 1, parent: "t2", fkid: 2 }, ForeignKeyCheckError { table: "t3", rowid: 2, parent: "t4", fkid: 3 }])
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: Hook("in hook")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: "Error::MigrationDefinition(MigrationDefinitionError::NoMigrationsDefined)"
expression: e
---
rusqlite_migrate error: MigrationDefinition(NoMigrationsDefined)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: RusqliteError { query: "SELECT * FROM table42;", err: InvalidQuery }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: SpecifiedSchemaVersion(TargetVersionOutOfRange { specified: NoneSet, highest: NoneSet })
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: Unrecognized(Hook("unknown"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: RusqliteError { query: "SELECT * FROM table42;", err: InvalidQuery }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: SpecifiedSchemaVersion(TargetVersionOutOfRange { specified: NoneSet, highest: NoneSet })
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: MigrationDefinition(NoMigrationsDefined)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: ForeignKeyCheck([ForeignKeyCheckError { table: "t1", rowid: 1, parent: "t2", fkid: 2 }, ForeignKeyCheckError { table: "t3", rowid: 2, parent: "t4", fkid: 3 }])
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: Hook("in hook")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: FileLoad("file causing problem")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: Unrecognized(Hook("unknown"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
rusqlite_migrate error: ConnectionClosed
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
InvalidQuery,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
TargetVersionOutOfRange {
specified: NoneSet,
highest: NoneSet,
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
NoMigrationsDefined,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
ForeignKeyCheckError {
table: "t1",
rowid: 1,
parent: "t2",
fkid: 2,
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
None
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
None
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
Hook(
"unknown",
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
None
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
None
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
None
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
ForeignKeyCheckError {
table: "t1",
rowid: 1,
parent: "t2",
fkid: 2,
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
None
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
NoMigrationsDefined,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
InvalidQuery,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
TargetVersionOutOfRange {
specified: NoneSet,
highest: NoneSet,
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e.source()
---
Some(
Hook(
"unknown",
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
Err(
RusqliteError {
query: "CREATE TABLE m1(a, b); CREATE TABLE m2(a, b, c);",
err: SqliteFailure(
Error {
code: ReadOnly,
extended_code: 8,
},
Some(
"attempt to write a readonly database",
),
),
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: rusqlite_migration/src/tests/synch.rs
expression: e
---
Err(
RusqliteError {
query: "PRAGMA user_version = 1; -- Approximate query",
err: SqliteFailure(
Error {
code: ReadOnly,
extended_code: 8,
},
Some(
"attempt to write a readonly database",
),
),
},
)
Loading

0 comments on commit d6a15b7

Please sign in to comment.