Skip to content

Commit 6f820fc

Browse files
committed
Copy windows network test from v4
1 parent c4f0925 commit 6f820fc

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ nix = "0.23.1"
5555
default = ["macos_fsevent"]
5656
timing_tests = []
5757
manual_tests = []
58+
network_tests = []
5859
macos_kqueue = ["kqueue", "mio"]
5960
macos_fsevent = ["fsevent-sys"]
6061

tests/windows_network.rs

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#![cfg(target_os = "windows")]
2+
#![cfg(feature = "network_tests")]
3+
4+
use notify::*;
5+
use std::{env, path::Path, sync::mpsc};
6+
use tempfile::TempDir;
7+
8+
use utils::*;
9+
mod utils;
10+
11+
const NETWORK_PATH: &str = ""; // eg.: \\\\MY-PC\\Users\\MyName
12+
13+
#[test]
14+
fn watch_relative_network_directory() {
15+
let tdir = TempDir::new_in(NETWORK_PATH).expect("failed to create temporary directory");
16+
tdir.create("dir1");
17+
18+
env::set_current_dir(tdir.path()).expect("failed to change working directory");
19+
20+
let (tx, _) = mpsc::channel();
21+
let mut watcher: RecommendedWatcher =
22+
Watcher::new(tx).expect("failed to create recommended watcher");
23+
watcher
24+
.watch(Path::new("dir1"), RecursiveMode::Recursive)
25+
.expect("failed to watch directory");
26+
27+
watcher
28+
.unwatch(Path::new("dir1"))
29+
.expect("failed to unwatch directory");
30+
31+
if cfg!(not(target_os = "windows")) {
32+
match watcher.unwatch(Path::new("dir1")) {
33+
Err(Error {
34+
kind: ErrorKind::WatchNotFound,
35+
..
36+
}) => (),
37+
Err(e) => panic!("{:?}", e),
38+
Ok(o) => panic!("{:?}", o),
39+
}
40+
}
41+
}
42+
43+
#[test]
44+
fn watch_relative_network_file() {
45+
let tdir = TempDir::new_in(NETWORK_PATH).expect("failed to create temporary directory");
46+
tdir.create("file1");
47+
48+
env::set_current_dir(tdir.path()).expect("failed to change working directory");
49+
50+
let (tx, _) = mpsc::channel();
51+
let mut watcher: RecommendedWatcher =
52+
Watcher::new(tx).expect("failed to create recommended watcher");
53+
watcher
54+
.watch(Path::new("file1"), RecursiveMode::Recursive)
55+
.expect("failed to watch file");
56+
57+
watcher
58+
.unwatch(Path::new("file1"))
59+
.expect("failed to unwatch file");
60+
61+
if cfg!(not(target_os = "windows")) {
62+
match watcher.unwatch(Path::new("file1")) {
63+
Err(Error {
64+
kind: ErrorKind::WatchNotFound,
65+
..
66+
}) => (),
67+
Err(e) => panic!("{:?}", e),
68+
Ok(o) => panic!("{:?}", o),
69+
}
70+
}
71+
}
72+
73+
#[test]
74+
fn watch_absolute_network_directory() {
75+
let tdir = TempDir::new_in(NETWORK_PATH).expect("failed to create temporary directory");
76+
tdir.create("dir1");
77+
78+
let (tx, _) = mpsc::channel();
79+
let mut watcher: RecommendedWatcher =
80+
Watcher::new(tx).expect("failed to create recommended watcher");
81+
watcher
82+
.watch(&tdir.mkpath("dir1"), RecursiveMode::Recursive)
83+
.expect("failed to watch directory");
84+
85+
watcher
86+
.unwatch(&tdir.mkpath("dir1"))
87+
.expect("failed to unwatch directory");
88+
89+
if cfg!(not(target_os = "windows")) {
90+
match watcher.unwatch(&tdir.mkpath("dir1")) {
91+
Err(Error {
92+
kind: ErrorKind::WatchNotFound,
93+
..
94+
}) => (),
95+
Err(e) => panic!("{:?}", e),
96+
Ok(o) => panic!("{:?}", o),
97+
}
98+
}
99+
}
100+
101+
#[test]
102+
fn watch_absolute_network_file() {
103+
let tdir = TempDir::new_in(NETWORK_PATH).expect("failed to create temporary directory");
104+
tdir.create("file1");
105+
106+
env::set_current_dir(tdir.path()).expect("failed to change working directory");
107+
108+
let (tx, _) = mpsc::channel();
109+
let mut watcher: RecommendedWatcher =
110+
Watcher::new(tx).expect("failed to create recommended watcher");
111+
watcher
112+
.watch(&tdir.mkpath("file1"), RecursiveMode::Recursive)
113+
.expect("failed to watch file");
114+
115+
watcher
116+
.unwatch(&tdir.mkpath("file1"))
117+
.expect("failed to unwatch file");
118+
119+
if cfg!(not(target_os = "windows")) {
120+
match watcher.unwatch(&tdir.mkpath("file1")) {
121+
Err(Error {
122+
kind: ErrorKind::WatchNotFound,
123+
..
124+
}) => (),
125+
Err(e) => panic!("{:?}", e),
126+
Ok(o) => panic!("{:?}", o),
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)