feat(gpodder_sqlite): set up testing
This commit is contained in:
parent
b44a47fefd
commit
705b347775
5 changed files with 90 additions and 1 deletions
|
|
@ -94,3 +94,16 @@ pub fn initialize_db(path: impl AsRef<Path>, run_migrations: bool) -> Result<DbP
|
|||
|
||||
Ok(pool)
|
||||
}
|
||||
|
||||
pub fn initialize_db_in_memory(run_migrations: bool) -> Result<DbPool, DbError> {
|
||||
let manager = ConnectionManager::<SqliteConnection>::new(":memory:");
|
||||
let pool = Pool::builder()
|
||||
.connection_customizer(Box::new(AddQueryDebugLogs))
|
||||
.build(manager)?;
|
||||
|
||||
if run_migrations {
|
||||
pool.get()?.run_pending_migrations(MIGRATIONS).unwrap();
|
||||
}
|
||||
|
||||
Ok(pool)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,10 @@ impl SqliteRepository {
|
|||
|
||||
Ok(Self { pool })
|
||||
}
|
||||
|
||||
pub fn in_memory() -> Result<Self, gpodder::AuthErr> {
|
||||
let pool = super::initialize_db_in_memory(true)?;
|
||||
|
||||
Ok(Self { pool })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue