use std::fs;
use std::path::PathBuf;
#[test]
fn test_config_file_loading() {
let temp_dir = std::env::temp_dir();
let config_file = temp_dir.join("test_config.yaml");
let config_content = r#"
version: "1.0.0"
global_settings:
log_level: Info
max_concurrent_tasks: 5
accounts:
- id: test-webdav
provider: WebDAV
name: Test WebDAV Server
credentials:
url: "http://localhost:8080/dav"
username: "testuser"
password: "testpass"
tasks:
- id: test-task-1
name: Backup Documents
source_account: test-webdav
source_path: "/documents"
target_account: test-webdav
target_path: "/backup"
diff_mode: Smart
preserve_metadata: true
"#;
fs::write(&config_file, config_content).unwrap();
assert!(config_file.exists());
let content = fs::read_to_string(&config_file).unwrap();
assert!(content.contains("test-webdav"));
assert!(content.contains("WebDAV"));
fs::remove_file(&config_file).ok();
}
#[test]
fn test_invalid_config_detection() {
let temp_dir = std::env::temp_dir();
let config_file = temp_dir.join("invalid_config.yaml");
let invalid_config = r#"
version: "1.0.0"
accounts:
- id: incomplete-account
provider: WebDAV
# 缺少 name 和 credentials
"#;
fs::write(&config_file, invalid_config).unwrap();
assert!(config_file.exists());
fs::remove_file(&config_file).ok();
}