Skip to content

Commit d6859f2

Browse files
committed
Test DB errors via uninitialised DB instead of read-only
Due to difficulties sharing in-memory databases between connections, especially when some are read-write and other are read-only, it is easier to cause SqliteErrors from the connection in another way, namely by not running the migrations so the tables are not present.
1 parent 5fc3c3e commit d6859f2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/db_service.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ impl SqliteScanPathService {
347347
.ok_or(ConfigurationError::MissingBeamline(beamline.into()))
348348
}
349349

350+
/// Create a db service from a new empty/schema-less DB
350351
#[cfg(test)]
351-
pub(crate) async fn ro_memory() -> Self {
352-
let db = Self::memory().await;
353-
db.pool
354-
.set_connect_options(SqliteConnectOptions::new().read_only(true));
355-
db
352+
pub(crate) async fn uninitialised() -> Self {
353+
Self {
354+
pool: SqlitePool::connect(":memory:").await.unwrap(),
355+
}
356356
}
357357

358358
#[cfg(test)]
@@ -524,11 +524,13 @@ mod db_tests {
524524
}
525525

526526
#[test]
527-
async fn read_only_db_propagates_errors() {
528-
let db = SqliteScanPathService::ro_memory().await;
527+
async fn uninitialised_db_propagates_errors() {
528+
let db = SqliteScanPathService::uninitialised().await;
529529
let e = err!(NewConfigurationError::Db, update("i22").insert_new(&db));
530530
let e = e.into_database_error().unwrap().downcast::<SqliteError>();
531531
assert_eq!(e.kind(), ErrorKind::Other);
532+
// "1" is the magic number for 'Generic Error'
533+
assert_eq!(e.code(), Some("1".into()));
532534
}
533535

534536
#[test]

0 commit comments

Comments
 (0)