use std::path::Path;
use std::time::Duration;
use notify::{Watcher, Event, RecursiveMode};
use mitoo::Exception;

// 请注意，不要在test中执行，需要在main中执行，test里面执行，在测试用例成功之前没有内容输出
#[test]
fn test_notify() -> std::result::Result<(), Exception>{
    let path = Path::new("d:/xxx/");
    // 创建监听器（使用默认配置）
    let (tx, rx) = std::sync::mpsc::channel::<notify::Result<Event>>();
    let config: notify::Config = notify::Config::default();
    config.with_poll_interval(Duration::from_secs(5));
    let mut watcher = notify::RecommendedWatcher::new(tx, config)?;

    // Add a path to be watched. All files and directories at that path and
    // below will be monitored for changes.
    watcher.watch(path, RecursiveMode::Recursive)?;

    // Block forever, printing out events as they come in
    for res in rx {
        match res {
            Ok(event) => println!("event: {:?}", event),
            Err(e) => println!("watch error: {:?}", e),
        }
    }
    Ok(())
}