69 lines
2.2 KiB
Rust
69 lines
2.2 KiB
Rust
![]() |
use dir_odt_to_pdf::error::{LogError, ProcessError, Result};
|
||
|
use dir_odt_to_pdf::logging::{LogConfig, init_logging};
|
||
|
use log::{LevelFilter, debug, info};
|
||
|
use std::fs;
|
||
|
mod common;
|
||
|
|
||
|
#[test]
|
||
|
fn test_init_logging_append_mode() -> Result<()> {
|
||
|
// Create a temporary file for logging
|
||
|
let (_temp_dir, log_path) = common::setup_test_log_file();
|
||
|
debug!("Starting test_init_logging_append_mode test");
|
||
|
|
||
|
// First initialization
|
||
|
let config = LogConfig {
|
||
|
log_file: Some(log_path.clone()),
|
||
|
log_level: LevelFilter::Debug,
|
||
|
append_log: false,
|
||
|
};
|
||
|
|
||
|
debug!("About to initialize logging for the first time...");
|
||
|
init_logging(config)?;
|
||
|
|
||
|
// Write first message
|
||
|
info!("Testing append mode...");
|
||
|
info!("first message");
|
||
|
|
||
|
// Read first message
|
||
|
let content = fs::read_to_string(&log_path).map_err(ProcessError::Io)?;
|
||
|
println!("=== Initial Log Contents ===");
|
||
|
println!("{}", content);
|
||
|
println!("=======================");
|
||
|
assert!(content.contains("first message"));
|
||
|
|
||
|
// Try second initialization with append mode
|
||
|
debug!("Attempting second initialization with append mode...");
|
||
|
let config = LogConfig {
|
||
|
log_file: Some(log_path.clone()),
|
||
|
log_level: LevelFilter::Debug,
|
||
|
append_log: true,
|
||
|
};
|
||
|
|
||
|
// Try to initialize again - this should fail
|
||
|
match init_logging(config) {
|
||
|
Err(ProcessError::Log(LogError::AlreadyInitialized)) => {
|
||
|
debug!("Got expected AlreadyInitialized error");
|
||
|
info!("second message");
|
||
|
|
||
|
// Check final contents
|
||
|
let content = fs::read_to_string(&log_path).map_err(ProcessError::Io)?;
|
||
|
println!("\n=== Final Log Contents ===");
|
||
|
println!("{}", content);
|
||
|
println!("=======================");
|
||
|
|
||
|
assert!(content.contains("first message"));
|
||
|
assert!(content.contains("second message"));
|
||
|
debug!("Test completed successfully");
|
||
|
Ok(())
|
||
|
}
|
||
|
Ok(_) => {
|
||
|
info!("Unexpected success on second initialization");
|
||
|
panic!("Expected AlreadyInitialized error")
|
||
|
}
|
||
|
Err(e) => {
|
||
|
info!("Unexpected error: {:?}", e);
|
||
|
Err(e)
|
||
|
}
|
||
|
}
|
||
|
}
|