1 use crate::*;
2 use nix::{
3 errno::Errno,
4 mount::{MntFlags, Nmount, unmount}
5 };
6 use std::{
7 ffi::CString,
8 fs::File,
9 path::Path
10 };
11 use tempfile::tempdir;
12
13 #[test]
ok()14 fn ok() {
15 require_mount!("nullfs");
16
17 let mountpoint = tempdir().unwrap();
18 let target = tempdir().unwrap();
19 let _sentry = File::create(target.path().join("sentry")).unwrap();
20
21 let fstype = CString::new("fstype").unwrap();
22 let nullfs = CString::new("nullfs").unwrap();
23 Nmount::new()
24 .str_opt(&fstype, &nullfs)
25 .str_opt_owned("fspath", mountpoint.path().to_str().unwrap())
26 .str_opt_owned("target", target.path().to_str().unwrap())
27 .nmount(MntFlags::empty()).unwrap();
28
29 // Now check that the sentry is visible through the mountpoint
30 let exists = Path::exists(&mountpoint.path().join("sentry"));
31
32 // Cleanup the mountpoint before asserting
33 unmount(mountpoint.path(), MntFlags::empty()).unwrap();
34
35 assert!(exists);
36 }
37
38 #[test]
bad_fstype()39 fn bad_fstype() {
40 let mountpoint = tempdir().unwrap();
41 let target = tempdir().unwrap();
42 let _sentry = File::create(target.path().join("sentry")).unwrap();
43
44 let e = Nmount::new()
45 .str_opt_owned("fspath", mountpoint.path().to_str().unwrap())
46 .str_opt_owned("target", target.path().to_str().unwrap())
47 .nmount(MntFlags::empty()).unwrap_err();
48
49 assert_eq!(e.error(), Errno::EINVAL);
50 assert_eq!(e.errmsg(), Some("Invalid fstype"));
51 }
52