test(gpodder_sqlite): start device tests

This commit is contained in:
Jef Roosens 2025-03-19 15:00:00 +01:00
parent 22016fe0e9
commit 73988d6264
No known key found for this signature in database
GPG key ID: 21FD3D77D56BAF49
6 changed files with 51 additions and 7 deletions

View file

@ -1,7 +1,7 @@
use std::collections::HashSet;
use chrono::{DateTime, Utc};
use diesel::{alias, dsl::not, prelude::*};
use diesel::{alias, dsl::not, prelude::*, sqlite::Sqlite};
use gpodder::AuthErr;
use super::SqliteRepository;
@ -70,6 +70,8 @@ impl gpodder::DeviceRepository for SqliteRepository {
patch: gpodder::DevicePatch,
) -> Result<(), gpodder::AuthErr> {
(|| {
let conn = &mut self.pool.get()?;
if let Some(mut device) = devices::table
.select(Device::as_select())
.filter(
@ -77,7 +79,7 @@ impl gpodder::DeviceRepository for SqliteRepository {
.eq(user.id)
.and(devices::device_id.eq(device_id)),
)
.get_result(&mut self.pool.get()?)
.get_result(conn)
.optional()?
{
if let Some(caption) = patch.caption {
@ -93,7 +95,7 @@ impl gpodder::DeviceRepository for SqliteRepository {
devices::caption.eq(&device.caption),
devices::type_.eq(&device.type_),
))
.execute(&mut self.pool.get()?)?;
.execute(conn)?;
} else {
let device = NewDevice {
device_id: device_id.to_string(),
@ -104,7 +106,7 @@ impl gpodder::DeviceRepository for SqliteRepository {
diesel::insert_into(devices::table)
.values(device)
.execute(&mut self.pool.get()?)?;
.execute(conn)?;
}
Ok::<_, DbError>(())