Fix non-bundled tests against macOS system SQLite

This commit is contained in:
Thom Chiovoloni
2022-04-03 10:48:56 -07:00
parent f8b9ad8907
commit 9699b4a210
3 changed files with 35 additions and 21 deletions

View File

@@ -1515,15 +1515,28 @@ mod test {
#[test]
fn test_pragma_query_row() -> Result<()> {
let db = Connection::open_in_memory()?;
assert_eq!(
"memory",
db.query_row::<String, _, _>("PRAGMA journal_mode", [], |r| r.get(0))?
);
assert_eq!(
"off",
db.query_row::<String, _, _>("PRAGMA journal_mode=off", [], |r| r.get(0))?
);
let mode = db.query_row::<String, _, _>("PRAGMA journal_mode=off", [], |r| r.get(0))?;
if cfg!(features = "bundled") {
assert_eq!(mode, "off");
} else {
// Note: system SQLite on macOS defaults to "off" rather than
// "memory" for the journal mode (which cannot be changed for
// in-memory connections). This seems like it's *probably* legal
// according to the docs below, so we relax this test when not
// bundling:
//
// From https://www.sqlite.org/pragma.html#pragma_journal_mode
// > Note that the journal_mode for an in-memory database is either
// > MEMORY or OFF and can not be changed to a different value. An
// > attempt to change the journal_mode of an in-memory database to
// > any setting other than MEMORY or OFF is ignored.
assert!(mode == "memory" || mode == "off", "Got mode {:?}", mode);
}
Ok(())
}

View File

@@ -406,18 +406,20 @@ mod test {
let db = Connection::open_in_memory()?;
let journal_mode: String =
db.pragma_update_and_check(None, "journal_mode", "OFF", |row| row.get(0))?;
assert_eq!("off", &journal_mode);
assert!(
journal_mode == "off" || journal_mode == "memory",
"mode: {:?}",
journal_mode,
);
// Sanity checks to ensure the move to a generic `ToSql` wasn't breaking
assert_eq!(
"off",
db.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row
.get::<_, String>(0))?,
);
let mode = db
.pragma_update_and_check(None, "journal_mode", &"OFF", |row| row.get::<_, String>(0))?;
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
let param: &dyn crate::ToSql = &"OFF";
assert_eq!(
"off",
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?,
);
let mode =
db.pragma_update_and_check(None, "journal_mode", param, |row| row.get::<_, String>(0))?;
assert!(mode == "off" || mode == "memory", "mode: {:?}", mode);
Ok(())
}