use mockforge_core::sync_watcher::SyncWatcher;
use mockforge_core::workspace::{SyncConfig, SyncDirection, SyncDirectoryStructure, Workspace};
use std::fs;
use tempfile::TempDir;
#[cfg(test)]
mod sync_tests {
use super::*;
#[tokio::test]
async fn test_workspace_sync_configuration() {
let workspace = Workspace::new("Test Workspace".to_string());
let sync_config = SyncConfig {
enabled: true,
target_directory: Some("/tmp/test-sync".to_string()),
sync_direction: SyncDirection::Bidirectional,
realtime_monitoring: true,
directory_structure: SyncDirectoryStructure::Flat,
filename_pattern: "workspace.yaml".to_string(),
exclude_pattern: None,
include_metadata: true,
force_overwrite: false,
last_sync: None,
};
let mut workspace = workspace;
workspace.configure_sync(sync_config).unwrap();
assert!(workspace.is_sync_enabled());
assert_eq!(workspace.get_sync_directory(), Some("/tmp/test-sync"));
}
#[tokio::test]
async fn test_workspace_sync_filtering() {
let mut workspace = Workspace::new("Test Workspace".to_string());
workspace.enable_sync("/tmp/test".to_string()).unwrap();
let filtered = workspace.to_filtered_for_sync();
assert_eq!(filtered.name, workspace.name);
assert!(filtered.is_sync_enabled());
}
#[tokio::test]
async fn test_sync_watcher_creation() {
let temp_dir = TempDir::new().unwrap();
let watcher = SyncWatcher::new(temp_dir.path());
assert!(watcher.get_monitored_workspaces().is_empty());
}
#[tokio::test]
async fn test_file_change_detection() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.yaml");
fs::write(&test_file, "test: content").unwrap();
assert!(test_file.exists());
let content = fs::read_to_string(&test_file).unwrap();
assert_eq!(content, "test: content");
fs::remove_file(&test_file).unwrap();
}
#[tokio::test]
async fn test_workspace_sync_filename_generation() {
let workspace = Workspace::new("My Test Workspace".to_string());
let filename = workspace.get_sync_filename();
assert!(filename.ends_with(".yaml"));
assert!(filename.contains("my-test-workspace"));
}
#[tokio::test]
async fn test_realtime_monitoring_flag() {
let mut workspace = Workspace::new("Test".to_string());
workspace.enable_sync("/tmp/test".to_string()).unwrap();
assert!(workspace.is_realtime_monitoring_enabled());
workspace.set_realtime_monitoring(false).unwrap();
assert!(!workspace.is_realtime_monitoring_enabled());
}
}