cloud-disk-sync 0.1.0

a cloud disk sync tool
Documentation
/// 端到端测试:通过配置文件测试完整流程
/// 这个测试模拟用户使用配置文件的方式
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());

    // 实际使用时,ConfigManager 应该能检测到这个错误
    // 这里只是验证配置文件的结构

    // 清理
    fs::remove_file(&config_file).ok();
}