Add unit test for server

This commit is contained in:
2022-09-23 04:29:05 +00:00
committed by GitHub
parent 2bd7bcef6f
commit 970a4ec731
10 changed files with 119 additions and 7 deletions

View File

@@ -16,7 +16,7 @@ pub use traits::PixivDownloaderDb;
pub use user::User;
pub type PixivDownloaderDbError = anyhow::Error;
use crate::{get_helper, gettext};
use crate::gettext;
#[cfg(feature = "db_sqlite")]
impl From<SqliteError> for PixivDownloaderDbError {
@@ -29,8 +29,9 @@ impl From<SqliteError> for PixivDownloaderDbError {
compile_error!("No database backend is enabled.");
/// Open the database
pub fn open_database() -> Result<Box<dyn PixivDownloaderDb + Send + Sync>, PixivDownloaderDbError> {
let cfg = get_helper().db();
pub fn open_database(
cfg: PixivDownloaderDbConfig,
) -> Result<Box<dyn PixivDownloaderDb + Send + Sync>, PixivDownloaderDbError> {
if cfg.is_none() {
return Err(PixivDownloaderDbError::msg(String::from(gettext(
"No database configuration provided.",
@@ -49,8 +50,9 @@ pub fn open_database() -> Result<Box<dyn PixivDownloaderDb + Send + Sync>, Pixiv
/// Open the database and initialize it
pub async fn open_and_init_database(
cfg: PixivDownloaderDbConfig,
) -> Result<Box<dyn PixivDownloaderDb + Send + Sync>, PixivDownloaderDbError> {
let db = open_database()?;
let db = open_database(cfg)?;
db.init().await?;
Ok(db)
}