Skip to content

Commit

Permalink
adding test_bind_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tommady committed Oct 1, 2021
1 parent fb4c3b5 commit b8cac8b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/rootfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>,
);
let got = &rootfs
.command
.as_any()
.downcast_ref::<TestHelperSyscall>()
.unwrap()
.get_mount_args()[0];
assert_eq!(want, *got)
}
}
41 changes: 35 additions & 6 deletions src/syscall/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ pub struct TestHelperSyscall {
set_ns_args: RefCell<Vec<(i32, CloneFlags)>>,
unshare_args: RefCell<Vec<CloneFlags>>,
set_capability_args: RefCell<Vec<(CapSet, CapsHashSet)>>,
mount_args: RefCell<
Vec<(
Option<std::path::PathBuf>,
std::path::PathBuf,
Option<String>,
nix::mount::MsFlags,
Option<String>,
)>,
>,
symlink_args: RefCell<Vec<(PathBuf, PathBuf)>>,
}

Expand All @@ -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![]),
}
}
Expand Down Expand Up @@ -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<()> {
Expand All @@ -103,6 +120,18 @@ impl TestHelperSyscall {
self.set_capability_args.borrow_mut().clone()
}

pub fn get_mount_args(
&self,
) -> Vec<(
Option<std::path::PathBuf>,
std::path::PathBuf,
Option<String>,
nix::mount::MsFlags,
Option<String>,
)> {
self.mount_args.borrow_mut().clone()
}

pub fn get_symlink_args(&self) -> Vec<(PathBuf, PathBuf)> {
self.symlink_args.borrow_mut().clone()
}
Expand Down

0 comments on commit b8cac8b

Please sign in to comment.