File tree Expand file tree Collapse file tree 5 files changed +88
-0
lines changed Expand file tree Collapse file tree 5 files changed +88
-0
lines changed Original file line number Diff line number Diff line change @@ -34,3 +34,4 @@ rstest.workspace = true
34
34
serde.workspace = true
35
35
deser-hjson.workspace = true
36
36
rand.workspace = true
37
+ tempfile.workspace = true
Original file line number Diff line number Diff line change @@ -752,6 +752,7 @@ mod tests {
752
752
753
753
use pretty_assertions:: assert_eq;
754
754
use rstest:: rstest;
755
+ use tempfile:: tempdir;
755
756
use testing:: TestCase ;
756
757
use time:: MockTime ;
757
758
@@ -886,4 +887,26 @@ mod tests {
886
887
) ;
887
888
}
888
889
}
890
+
891
+ #[ test]
892
+ fn integration ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
893
+ let dir = tempdir ( ) ?;
894
+
895
+ let ( tx, rx) = std:: sync:: mpsc:: channel ( ) ;
896
+
897
+ let mut debouncer = new_debouncer ( Duration :: from_millis ( 10 ) , None , tx) ?;
898
+
899
+ debouncer. watch ( dir. path ( ) , RecursiveMode :: Recursive ) ?;
900
+
901
+ fs:: write ( dir. path ( ) . join ( "file.txt" ) , b"Lorem ipsum" ) ?;
902
+
903
+ let events = rx
904
+ . recv_timeout ( Duration :: from_secs ( 10 ) )
905
+ . expect ( "no events received" )
906
+ . expect ( "received an error" ) ;
907
+
908
+ assert ! ( !events. is_empty( ) , "received empty event list" ) ;
909
+
910
+ Ok ( ( ) )
911
+ }
889
912
}
Original file line number Diff line number Diff line change @@ -25,3 +25,4 @@ notify.workspace = true
25
25
notify-types.workspace = true
26
26
crossbeam-channel = { workspace = true , optional = true }
27
27
log.workspace = true
28
+ tempfile.workspace = true
Original file line number Diff line number Diff line change @@ -396,3 +396,39 @@ pub fn new_debouncer<F: DebounceEventHandler>(
396
396
let config = Config :: default ( ) . with_timeout ( timeout) ;
397
397
new_debouncer_opt :: < F , RecommendedWatcher > ( config, event_handler)
398
398
}
399
+
400
+ #[ cfg( test) ]
401
+ mod tests {
402
+ use super :: * ;
403
+ use notify:: RecursiveMode ;
404
+ use std:: fs;
405
+ use tempfile:: tempdir;
406
+
407
+ #[ test]
408
+ fn integration ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
409
+ let dir = tempdir ( ) ?;
410
+
411
+ let ( tx, rx) = std:: sync:: mpsc:: channel ( ) ;
412
+
413
+ let mut debouncer = new_debouncer ( Duration :: from_secs ( 1 ) , tx) ?;
414
+
415
+ debouncer
416
+ . watcher ( )
417
+ . watch ( dir. path ( ) , RecursiveMode :: Recursive ) ?;
418
+
419
+ let file_path = dir. path ( ) . join ( "file.txt" ) ;
420
+ fs:: write ( & file_path, b"Lorem ipsum" ) ?;
421
+
422
+ let events = rx
423
+ . recv_timeout ( Duration :: from_secs ( 10 ) )
424
+ . expect ( "no events received" )
425
+ . expect ( "received an error" ) ;
426
+
427
+ assert_eq ! (
428
+ events,
429
+ vec![ DebouncedEvent :: new( file_path, DebouncedEventKind :: Any ) ]
430
+ ) ;
431
+
432
+ Ok ( ( ) )
433
+ }
434
+ }
Original file line number Diff line number Diff line change @@ -383,6 +383,10 @@ where
383
383
384
384
#[ cfg( test) ]
385
385
mod tests {
386
+ use std:: { fs, time:: Duration } ;
387
+
388
+ use tempfile:: tempdir;
389
+
386
390
use super :: * ;
387
391
388
392
#[ test]
@@ -408,4 +412,27 @@ mod tests {
408
412
assert_debug_impl ! ( RecursiveMode ) ;
409
413
assert_debug_impl ! ( WatcherKind ) ;
410
414
}
415
+
416
+ #[ test]
417
+ fn integration ( ) -> std:: result:: Result < ( ) , Box < dyn std:: error:: Error > > {
418
+ let dir = tempdir ( ) ?;
419
+
420
+ let ( tx, rx) = std:: sync:: mpsc:: channel ( ) ;
421
+
422
+ let mut watcher = RecommendedWatcher :: new ( tx, Config :: default ( ) ) ?;
423
+
424
+ watcher. watch ( dir. path ( ) , RecursiveMode :: Recursive ) ?;
425
+
426
+ let file_path = dir. path ( ) . join ( "file.txt" ) ;
427
+ fs:: write ( & file_path, b"Lorem ipsum" ) ?;
428
+
429
+ let event = rx
430
+ . recv_timeout ( Duration :: from_secs ( 10 ) )
431
+ . expect ( "no events received" )
432
+ . expect ( "received an error" ) ;
433
+
434
+ assert_eq ! ( event. paths, vec![ file_path] ) ;
435
+
436
+ Ok ( ( ) )
437
+ }
411
438
}
You can’t perform that action at this time.
0 commit comments