MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / test_watch_directory

Function test_watch_directory

crates/opencode-watcher/src/lib.rs:250–271  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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() {

Callers

nothing calls this directly

Calls 4

newFunction · 0.85
sleepFunction · 0.85
watchMethod · 0.80
subscribeMethod · 0.45

Tested by

no test coverage detected