feat(gpodder_sqlite): set up testing

This commit is contained in:
Jef Roosens 2025-03-19 10:47:07 +01:00
parent b44a47fefd
commit 705b347775
No known key found for this signature in database
GPG key ID: 21FD3D77D56BAF49
5 changed files with 90 additions and 1 deletions

View file

@ -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)
}

View file

@ -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 })
}
}