in metalos/metalctl/src/mount.rs [310:391]
fn test_mount_cycle_all_fstypes_then_find_btrfs() -> Result<()> {
let log = slog::Logger::root(slog_glog_fmt::default_drain(), slog::o!());
let tmpdir = TempDir::new()?;
std::fs::create_dir_all(tmpdir.path().join("proc"))?;
let fake_proc_filesystems_path = tmpdir.path().join("proc/filesystems");
std::fs::write(
fake_proc_filesystems_path.clone(),
b"nodev sysfs
nodev rootfs
nodev ramfs
nodev bdev
nodev proc
nodev cpuset
nodev cgroup
nodev cgroup2
nodev tmpfs
nodev devtmpfs
nodev binfmt_misc
nodev configfs
nodev debugfs
nodev tracefs
nodev securityfs
nodev sockfs
nodev dax
nodev bpf
nodev pipefs
nodev hugetlbfs
nodev devpts
ext3
ext2
ext4
vfat
msdos
nodev overlay
xfs
nodev mqueue
btrfs
nodev pstore
nodev autofs
nodev efivarfs
fuseblk
nodev fuse
nodev fusectl
nodev rpc_pipefs\n",
)?;
let opts = Opts {
bind: false,
source: "fooSource".to_string(),
target: PathBuf::from("fooPath"),
fstype: None,
options: Vec::new(),
};
let fs_types = parse_proc_file_systems_file(fake_proc_filesystems_path)?;
let mut mock_mounter = MockMounter::new();
// return success only for btrfs
mock_mounter
.expect_mount()
.withf(
|source: &Path,
target: &Path,
fstype: &Option<&str>,
flags: &MsFlags,
_data: &Option<&str>| {
*source == *(Path::new("fooSource"))
&& target == Path::new("fooPath")
&& *fstype == Some("btrfs")
&& *flags == MsFlags::empty()
},
)
.return_once(|_, _, _, _, _| Ok(()));
// default behavior is to bail for any other filesystem
mock_mounter
.expect_mount()
.returning(|_, _, _, _, _| Err(anyhow!("boom")));
_mount(log, opts, &fs_types, mock_mounter)?;
std::fs::remove_dir_all(&tmpdir)?;
Ok(())
}