| 248 | |
| 249 | #[tokio::test] |
| 250 | async fn test_watch_directory() { |
| 251 | let temp_dir = TempDir::new().unwrap(); |
| 252 | let watcher = FileWatcher::new(WatcherConfig::default()).unwrap(); |
| 253 | |
| 254 | let mut rx = watcher.subscribe(); |
| 255 | |
| 256 | watcher.watch(temp_dir.path()).unwrap(); |
| 257 | |
| 258 | let test_file = temp_dir.path().join("test.txt"); |
| 259 | fs::write(&test_file, "hello").unwrap(); |
| 260 | |
| 261 | sleep(Duration::from_millis(200)).await; |
| 262 | |
| 263 | match rx.try_recv() { |
| 264 | Ok(event) => { |
| 265 | assert!(event.file.ends_with("test.txt")); |
| 266 | assert_eq!(event.event, FileEvent::Add); |
| 267 | } |
| 268 | Err(broadcast::error::TryRecvError::Empty) => {} |
| 269 | Err(e) => panic!("Unexpected error: {}", e), |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | #[test] |
| 274 | fn test_watch_nonexistent_path() { |