From b8cac8b0f025b65e1f665a68fe5a7b47860f9f78 Mon Sep 17 00:00:00 2001 From: tommady Date: Fri, 1 Oct 2021 11:04:17 +0000 Subject: [PATCH] adding test_bind_dev --- src/rootfs.rs | 29 +++++++++++++++++++++++++++++ src/syscall/test.rs | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/rootfs.rs b/src/rootfs.rs index d512132d2..f23eefe4b 100644 --- a/src/rootfs.rs +++ b/src/rootfs.rs @@ -770,4 +770,33 @@ mod tests { .get_symlink_args(); assert_eq!(want, got) } + + #[test] + #[serial] + fn test_bind_dev() { + let rootfs = RootFS::new(); + assert!(rootfs + .bind_dev( + Path::new("/tmp"), + &LinuxDeviceBuilder::default() + .path(PathBuf::from("/null")) + .build() + .unwrap(), + ) + .is_ok()); + let want = ( + Some(PathBuf::from("/null")), + PathBuf::from("/tmp/null"), + Some("bind".to_string()), + MsFlags::MS_BIND, + None::, + ); + let got = &rootfs + .command + .as_any() + .downcast_ref::() + .unwrap() + .get_mount_args()[0]; + assert_eq!(want, *got) + } } diff --git a/src/syscall/test.rs b/src/syscall/test.rs index a8fe56df9..78574ba18 100644 --- a/src/syscall/test.rs +++ b/src/syscall/test.rs @@ -11,6 +11,15 @@ pub struct TestHelperSyscall { set_ns_args: RefCell>, unshare_args: RefCell>, set_capability_args: RefCell>, + mount_args: RefCell< + Vec<( + Option, + std::path::PathBuf, + Option, + nix::mount::MsFlags, + Option, + )>, + >, symlink_args: RefCell>, } @@ -20,6 +29,7 @@ impl Default for TestHelperSyscall { set_ns_args: RefCell::new(vec![]), unshare_args: RefCell::new(vec![]), set_capability_args: RefCell::new(vec![]), + mount_args: RefCell::new(vec![]), symlink_args: RefCell::new(vec![]), } } @@ -73,13 +83,20 @@ impl Syscall for TestHelperSyscall { fn mount( &self, - _source: Option<&std::path::Path>, - _target: &std::path::Path, - _fstype: Option<&str>, - _flags: nix::mount::MsFlags, - _data: Option<&str>, + source: Option<&std::path::Path>, + target: &std::path::Path, + fstype: Option<&str>, + flags: nix::mount::MsFlags, + data: Option<&str>, ) -> anyhow::Result<()> { - todo!() + self.mount_args.borrow_mut().push(( + source.map(|x| x.to_owned()), + target.to_owned(), + fstype.map(|x| x.to_owned()), + flags, + data.map(|x| x.to_owned()), + )); + Ok(()) } fn symlink(&self, original: &std::path::Path, link: &std::path::Path) -> anyhow::Result<()> { @@ -103,6 +120,18 @@ impl TestHelperSyscall { self.set_capability_args.borrow_mut().clone() } + pub fn get_mount_args( + &self, + ) -> Vec<( + Option, + std::path::PathBuf, + Option, + nix::mount::MsFlags, + Option, + )> { + self.mount_args.borrow_mut().clone() + } + pub fn get_symlink_args(&self) -> Vec<(PathBuf, PathBuf)> { self.symlink_args.borrow_mut().clone() }