Skip to content

Commit

Permalink
feat: Add Executor#mount_tmpfs, resolves #4
Browse files Browse the repository at this point in the history
  • Loading branch information
John Doe committed Jun 16, 2024
1 parent 2ae5ea0 commit 66830f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hakoniwa/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@ impl Executor {
self
}

/// Mount new tmpfs on `dest`.
pub fn mount_tmpfs<P1: AsRef<Path>>(
&mut self,
dest: P1,
) -> Result<&mut Self> {
self._bind("", dest, Some("tmpfs"), Some(true))
}


/// Bind mount the `src` on `dest` with **read-only** access in the container.
pub fn ro_bind<P1: AsRef<Path>, P2: AsRef<Path>>(
&mut self,
Expand Down
12 changes: 12 additions & 0 deletions hakoniwa/tests/executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ mounts = [
);
}

#[test]
fn test_mount_tmpfs() {
let mut executor = sandbox().command("findmnt", &["findmnt", "-T", "/mytmp"]);
let result = executor
.mount_tmpfs("/mytmp")
.unwrap()
.run();
assert_eq!(result.status, ExecutorResultStatus::Ok);
assert_eq!(result.exit_code, Some(0));
assert!(String::from_utf8_lossy(&result.stdout).contains("tmpfs"));
}

#[test]
fn test_ro_bind() {
let mut executor = sandbox().command("touch", &["touch", "Cargo.toml"]);
Expand Down

0 comments on commit 66830f1

Please sign in to comment.