feature: add new mikan scrapers
This commit is contained in:
@@ -58,7 +58,7 @@ impl AppContextTrait for UnitTestAppContext {
|
||||
self.graphql.as_ref().expect("should set graphql")
|
||||
}
|
||||
|
||||
fn storage(&self) -> &crate::storage::StorageService {
|
||||
fn storage(&self) -> &dyn crate::storage::StorageServiceTrait {
|
||||
self.storage.as_ref().expect("should set storage")
|
||||
}
|
||||
|
||||
|
||||
59
apps/recorder/src/test_utils/database.rs
Normal file
59
apps/recorder/src/test_utils/database.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use crate::{
|
||||
database::{DatabaseConfig, DatabaseService},
|
||||
errors::RecorderResult,
|
||||
};
|
||||
|
||||
#[cfg(feature = "testcontainers")]
|
||||
pub async fn build_testing_database_service() -> RecorderResult<DatabaseService> {
|
||||
use testcontainers::runners::AsyncRunner;
|
||||
use testcontainers_ext::{ImageDefaultLogConsumerExt, ImagePruneExistedLabelExt};
|
||||
use testcontainers_modules::postgres::Postgres;
|
||||
|
||||
let container = Postgres::default()
|
||||
.with_db_name("konobangu")
|
||||
.with_user("konobangu")
|
||||
.with_password("konobangu")
|
||||
.with_default_log_consumer()
|
||||
.with_prune_existed_label(env!("CARGO_PKG_NAME"), "postgres", true, true)
|
||||
.await?;
|
||||
|
||||
let container = container.start().await?;
|
||||
|
||||
let host_ip = container.get_host().await?;
|
||||
let host_port = container.get_host_port_ipv4(5432).await?;
|
||||
|
||||
let connection_string =
|
||||
format!("postgres://konobangu:konobangu@{host_ip}:{host_port}/konobangu");
|
||||
|
||||
let mut db_service = DatabaseService::from_config(DatabaseConfig {
|
||||
uri: connection_string,
|
||||
enable_logging: true,
|
||||
min_connections: 1,
|
||||
max_connections: 1,
|
||||
connect_timeout: 5000,
|
||||
idle_timeout: 10000,
|
||||
acquire_timeout: None,
|
||||
auto_migrate: true,
|
||||
})
|
||||
.await?;
|
||||
db_service.container = Some(container);
|
||||
|
||||
Ok(db_service)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "testcontainers"))]
|
||||
pub async fn build_testing_database_service() -> RecorderResult<DatabaseService> {
|
||||
let db_service = DatabaseService::from_config(DatabaseConfig {
|
||||
uri: String::from("postgres://konobangu:konobangu@127.0.0.1:5432/konobangu"),
|
||||
enable_logging: true,
|
||||
min_connections: 1,
|
||||
max_connections: 1,
|
||||
connect_timeout: 5000,
|
||||
idle_timeout: 10000,
|
||||
acquire_timeout: None,
|
||||
auto_migrate: true,
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(db_service)
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
pub mod app;
|
||||
pub mod database;
|
||||
pub mod mikan;
|
||||
pub mod storage;
|
||||
pub mod tracing;
|
||||
|
||||
28
apps/recorder/src/test_utils/storage.rs
Normal file
28
apps/recorder/src/test_utils/storage.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use opendal::{Operator, layers::LoggingLayer};
|
||||
|
||||
use crate::{errors::RecorderResult, storage::StorageServiceTrait};
|
||||
|
||||
pub struct TestingStorageService {
|
||||
operator: Operator,
|
||||
}
|
||||
|
||||
impl TestingStorageService {
|
||||
pub fn new() -> RecorderResult<Self> {
|
||||
let op = Operator::new(opendal::services::Memory::default())?
|
||||
.layer(LoggingLayer::default())
|
||||
.finish();
|
||||
|
||||
Ok(Self { operator: op })
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl StorageServiceTrait for TestingStorageService {
|
||||
fn get_operator(&self) -> RecorderResult<Operator> {
|
||||
Ok(self.operator.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn build_testing_storage_service() -> RecorderResult<TestingStorageService> {
|
||||
TestingStorageService::new()
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use tracing_subscriber::EnvFilter;
|
||||
pub fn try_init_testing_tracing(level: Level) {
|
||||
let crate_name = env!("CARGO_PKG_NAME");
|
||||
let level = level.as_str().to_lowercase();
|
||||
let filter = EnvFilter::new(format!("{}[]={}", crate_name, level))
|
||||
.add_directive(format!("mockito[]={}", level).parse().unwrap());
|
||||
let filter = EnvFilter::new(format!("{crate_name}[]={level}"))
|
||||
.add_directive(format!("mockito[]={level}").parse().unwrap());
|
||||
let _ = tracing_subscriber::fmt().with_env_filter(filter).try_init();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user