
This commit enhances the logging system with better thread safety and proper test configuration: - Replace RefCell with RwLock in SimpleLogger for thread-safe logging - Add proper feature flag configuration for test-sync - Organize logging modules with clear separation between prod and test - Update test files with proper feature flag annotations - Fix module structure in lib.rs to avoid duplicate definitions Technical changes: - Use RwLock for thread-safe log writer access - Add #![cfg(feature = "test-sync")] to all test files - Configure .cargo/config.toml for test-sync feature - Update Cargo.toml with proper test configurations - Clean up logging module exports This change ensures thread-safe logging in production while maintaining separate test-specific synchronization primitives, improving overall reliability and maintainability.
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
#![cfg(feature = "test-sync")]
|
|
use dir_odt_to_pdf::error::{ProcessError, Result};
|
|
use dir_odt_to_pdf::logging::{LogConfig, LogWriter};
|
|
use log::LevelFilter;
|
|
use std::fs;
|
|
use std::io;
|
|
use tempfile::NamedTempFile;
|
|
|
|
#[test]
|
|
fn test_log_writer_file_output() -> io::Result<()> {
|
|
let temp_file = NamedTempFile::new()?;
|
|
let mut writer = LogWriter::new(Some(temp_file.reopen()?));
|
|
writer.write_all(b"test message\n")?;
|
|
writer.flush()?;
|
|
let content = fs::read_to_string(temp_file.path())?;
|
|
assert_eq!(content, "test message\n");
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_log_writer_console_output() {
|
|
let mut writer = LogWriter::new(None);
|
|
assert!(writer.write_all(b"test message\n").is_ok());
|
|
assert!(writer.flush().is_ok());
|
|
}
|
|
|
|
#[test]
|
|
fn test_log_config_default() {
|
|
let config = LogConfig::default();
|
|
assert_eq!(config.log_level, LevelFilter::Info);
|
|
assert_eq!(config.log_file, None);
|
|
assert!(!config.append_log);
|
|
}
|
|
|
|
#[test]
|
|
fn test_log_writer() -> Result<()> {
|
|
let mut writer = LogWriter::new(None);
|
|
writer
|
|
.write_all(b"test message\n")
|
|
.map_err(ProcessError::Io)?;
|
|
writer.flush().map_err(ProcessError::Io)?;
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_log_writer_methods() -> Result<()> {
|
|
let mut writer = LogWriter::new(None);
|
|
assert!(writer.write_all(b"test message\n").is_ok());
|
|
assert!(writer.flush().is_ok());
|
|
Ok(())
|
|
}
|