use crate::config::test_service::TestConfigService;
use crate::config::{Config, OverflowStrategy};
pub struct TestConfigBuilder {
config: Config,
}
impl TestConfigBuilder {
pub fn new() -> Self {
Self {
config: Config::default(),
}
}
pub fn with_ai_provider(mut self, provider: &str) -> Self {
self.config.ai.provider = provider.to_string();
self
}
pub fn with_ai_model(mut self, model: &str) -> Self {
self.config.ai.model = model.to_string();
self
}
pub fn with_ai_api_key(mut self, api_key: &str) -> Self {
self.config.ai.api_key = Some(api_key.to_string());
self
}
pub fn with_ai_base_url(mut self, base_url: &str) -> Self {
self.config.ai.base_url = base_url.to_string();
self
}
pub fn with_max_sample_length(mut self, length: usize) -> Self {
self.config.ai.max_sample_length = length;
self
}
pub fn with_ai_temperature(mut self, temperature: f32) -> Self {
self.config.ai.temperature = temperature;
self
}
pub fn with_ai_max_tokens(mut self, max_tokens: u32) -> Self {
self.config.ai.max_tokens = max_tokens;
self
}
pub fn with_ai_retry(mut self, attempts: u32, delay_ms: u64) -> Self {
self.config.ai.retry_attempts = attempts;
self.config.ai.retry_delay_ms = delay_ms;
self
}
pub fn with_ai_request_timeout(mut self, timeout_seconds: u64) -> Self {
self.config.ai.request_timeout_seconds = timeout_seconds;
self
}
pub fn with_sync_method(mut self, method: &str) -> Self {
self.config.sync.default_method = method.to_string();
self
}
pub fn with_vad_enabled(mut self, enabled: bool) -> Self {
self.config.sync.vad.enabled = enabled;
self
}
pub fn with_vad_sensitivity(mut self, sensitivity: f32) -> Self {
self.config.sync.vad.sensitivity = sensitivity;
self
}
pub fn with_default_output_format(mut self, format: &str) -> Self {
self.config.formats.default_output = format.to_string();
self
}
pub fn with_preserve_styling(mut self, preserve: bool) -> Self {
self.config.formats.preserve_styling = preserve;
self
}
pub fn with_default_encoding(mut self, encoding: &str) -> Self {
self.config.formats.default_encoding = encoding.to_string();
self
}
pub fn with_encoding_detection_confidence(mut self, confidence: f32) -> Self {
self.config.formats.encoding_detection_confidence = confidence;
self
}
pub fn with_backup_enabled(mut self, enabled: bool) -> Self {
self.config.general.backup_enabled = enabled;
self
}
pub fn with_max_concurrent_jobs(mut self, jobs: usize) -> Self {
self.config.general.max_concurrent_jobs = jobs;
self
}
pub fn with_task_timeout(mut self, timeout_seconds: u64) -> Self {
self.config.general.task_timeout_seconds = timeout_seconds;
self
}
pub fn with_progress_bar(mut self, enabled: bool) -> Self {
self.config.general.enable_progress_bar = enabled;
self
}
pub fn with_worker_idle_timeout(mut self, timeout_seconds: u64) -> Self {
self.config.general.worker_idle_timeout_seconds = timeout_seconds;
self
}
pub fn with_task_queue_size(mut self, size: usize) -> Self {
self.config.parallel.task_queue_size = size;
self
}
pub fn with_task_priorities(mut self, enabled: bool) -> Self {
self.config.parallel.enable_task_priorities = enabled;
self
}
pub fn with_auto_balance_workers(mut self, enabled: bool) -> Self {
self.config.parallel.auto_balance_workers = enabled;
self
}
pub fn with_queue_overflow_strategy(mut self, strategy: OverflowStrategy) -> Self {
self.config.parallel.overflow_strategy = strategy;
self
}
pub fn with_parallel_settings(mut self, max_workers: usize, queue_size: usize) -> Self {
self.config.general.max_concurrent_jobs = max_workers;
self.config.parallel.task_queue_size = queue_size;
self
}
pub fn build_service(self) -> TestConfigService {
TestConfigService::new(self.config)
}
pub fn build_config(self) -> Config {
self.config
}
pub fn config(&self) -> &Config {
&self.config
}
pub fn config_mut(&mut self) -> &mut Config {
&mut self.config
}
pub fn with_mock_ai_server(mut self, mock_url: &str) -> Self {
self.config.ai.base_url = mock_url.to_string();
self.config.ai.api_key = Some("mock-api-key".to_string());
self
}
}
impl Default for TestConfigBuilder {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::config::service::ConfigService;
#[test]
fn test_builder_default() {
let config = TestConfigBuilder::new().build_config();
let default_config = Config::default();
assert_eq!(config.ai.provider, default_config.ai.provider);
assert_eq!(config.ai.model, default_config.ai.model);
}
#[test]
fn test_builder_ai_configuration() {
let config = TestConfigBuilder::new()
.with_ai_provider("anthropic")
.with_ai_model("claude-3")
.with_ai_api_key("test-key")
.with_max_sample_length(5000)
.with_ai_temperature(0.7)
.build_config();
assert_eq!(config.ai.provider, "anthropic");
assert_eq!(config.ai.model, "claude-3");
assert_eq!(config.ai.api_key, Some("test-key".to_string()));
assert_eq!(config.ai.max_sample_length, 5000);
assert_eq!(config.ai.temperature, 0.7);
}
#[test]
fn test_builder_sync_configuration() {
let config = TestConfigBuilder::new()
.with_sync_method("vad")
.with_vad_enabled(true)
.with_vad_sensitivity(0.8)
.build_config();
assert_eq!(config.sync.default_method, "vad");
assert!(config.sync.vad.enabled);
assert_eq!(config.sync.vad.sensitivity, 0.8);
}
#[test]
fn test_builder_service_creation() {
let service = TestConfigBuilder::new()
.with_ai_provider("test-provider")
.build_service();
let config = service.get_config().unwrap();
assert_eq!(config.ai.provider, "test-provider");
}
#[test]
fn test_builder_chaining() {
let config = TestConfigBuilder::new()
.with_ai_provider("openai")
.with_ai_model("gpt-4.1")
.with_sync_method("vad")
.with_vad_sensitivity(0.5)
.with_max_concurrent_jobs(8)
.with_task_queue_size(200)
.build_config();
assert_eq!(config.ai.provider, "openai");
assert_eq!(config.ai.model, "gpt-4.1");
assert_eq!(config.sync.default_method, "vad");
assert_eq!(config.sync.vad.sensitivity, 0.5);
assert_eq!(config.general.max_concurrent_jobs, 8);
assert_eq!(config.parallel.task_queue_size, 200);
}
#[test]
fn test_builder_ai_configuration_openrouter() {
let config = TestConfigBuilder::new()
.with_ai_provider("openrouter")
.with_ai_model("deepseek/deepseek-r1-0528:free")
.with_ai_api_key("test-openrouter-key")
.build_config();
assert_eq!(config.ai.provider, "openrouter");
assert_eq!(config.ai.model, "deepseek/deepseek-r1-0528:free");
assert_eq!(config.ai.api_key, Some("test-openrouter-key".to_string()));
}
}