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