Skip to content

test(unikontainers): add unit tests for mount and shared_fs utilities - #815

Draft
Nachiket-Roy wants to merge 2 commits into
urunc-dev:mainfrom
Nachiket-Roy:test/mount-sharedfs
Draft

test(unikontainers): add unit tests for mount and shared_fs utilities#815
Nachiket-Roy wants to merge 2 commits into
urunc-dev:mainfrom
Nachiket-Roy:test/mount-sharedfs

Conversation

@Nachiket-Roy

@Nachiket-Roy Nachiket-Roy commented Jul 10, 2026

Copy link
Copy Markdown

Description

This PR introduces unit tests to cover previously untested logic in the mount.go and shared_fs.go files of the unikontainers package.

To facilitate testing without requiring root privileges or mutating the host filesystem/processes:

  1. Mockable Hooks: Extracted system and package utility calls (Mount, Mknod, Stat, Chmod, Open, Close, os.Chmod, os.MkdirAll, os.Chown, RunningInUserNS, and spawnProcess) into package-level hook variables inside mount.go and shared_fs.go.
  2. Mount Unit Tests (mount_test.go): Added coverage for createTmpfs, setupDev (both namespace check and failure branches), fileFromHost (both bind mount/remount and copy branches), mapMountFlag, mapRootfsPropagationFlag, prepareRoot, and mountVolumes (asserting exact flag accumulation and propagation operations).
  3. Shared FS Unit Tests (shared_fs_test.go): Added coverage for path adjustment, memory-based tmpfs allocation size (confirming decimal MB divisor), preStart (directly validating construction of options and arguments), and postSetup (complete happy paths for VirtioFS/9pfs and error wrapping paths for all steps).

Note: Thread safety has been preserved. Tests that temporarily mutate package-level variables are serialized, while pure non-mutating tests continue to run in parallel (t.Parallel()).

Related issues

How was this tested?

Tested locally by verifying correct format, static analysis, and race-detector execution:

go fmt ./pkg/unikontainers/...
go vet ./...
go test -race ./pkg/unikontainers/...

Output:

ok      github.com/urunc-dev/urunc/pkg/unikontainers    1.029s
ok      github.com/urunc-dev/urunc/pkg/unikontainers/hypervisors        1.011s
?       github.com/urunc-dev/urunc/pkg/unikontainers/initrd     [no test files]
?       github.com/urunc-dev/urunc/pkg/unikontainers/types      [no test files]
ok      github.com/urunc-dev/urunc/pkg/unikontainers/unikernels 1.009s

LLM usage

Assisted by Claude sonnet 5 .

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

Extract OS and unix syscalls (Mount, Mknod, Stat, Chmod, Open, Close, Chown,
MkdirAll, and RunningInUserNS) to package-level hook variables. Add
mount_test.go to cover tmpfs creation, device node setup, bind-mounts,
parent private remounts, and flag accumulation.

Related-to: urunc-dev#96
Signed-off-by: Nachiket Roy <nachiket.roy.2@gmail.com>
Extract spawnProcess to a package-level spawnProcessHook. Add
shared_fs_test.go to cover memory size boundaries (with decimal MB divisor),
path adjustment, preStart process parameter validation, and postSetup
happy/failure paths.

Related-to: urunc-dev#96
Signed-off-by: Nachiket Roy <nachiket.roy.2@gmail.com>
@netlify

netlify Bot commented Jul 10, 2026

Copy link
Copy Markdown

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit e4a4ea0
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a50db4ccf36990008edadec

@Nachiket-Roy
Nachiket-Roy marked this pull request as draft July 31, 2026 13:17
@Nachiket-Roy

Nachiket-Roy commented Aug 3, 2026

Copy link
Copy Markdown
Author

PR #840 contains a major refactor of the mount/shared-fs layer. Because of that, the tests added in this PR need to be reworked to match the new implementation. Hence putting this PR on hold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant