test(unikernels): add unit tests for Hermit#638
Open
r0hansaxena wants to merge 1 commit into
Open
Conversation
Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
✅ Deploy Preview for urunc canceled.
|
cmainas
reviewed
May 14, 2026
Comment on lines
+26
to
+33
| func TestHermitSupports(t *testing.T) { | ||
| h := newHermit() | ||
| assert.False(t, h.SupportsBlock()) | ||
| assert.True(t, h.SupportsFS("initrd")) | ||
| assert.False(t, h.SupportsFS("ext4")) | ||
| assert.False(t, h.SupportsFS("9pfs")) | ||
| assert.False(t, h.SupportsFS("")) | ||
| } |
Contributor
There was a problem hiding this comment.
No reason test such straightforward and small functions.
Comment on lines
+35
to
+41
| func TestHermitMonitorCliAlwaysHasNoReboot(t *testing.T) { | ||
| h := &Hermit{Monitor: "qemu"} | ||
| assert.Equal(t, " -no-reboot", h.MonitorCli().OtherArgs) | ||
|
|
||
| h.Monitor = "spt" | ||
| assert.Equal(t, " -no-reboot", h.MonitorCli().OtherArgs) | ||
| } |
Contributor
There was a problem hiding this comment.
No reason test such straightforward and small function through unit testing
Comment on lines
+43
to
+46
| func TestHermitMonitorBlockCliIsNil(t *testing.T) { | ||
| assert.Nil(t, (&Hermit{Monitor: "qemu"}).MonitorBlockCli()) | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
No reason test such straightforward and small function through unit testing
| assert.Nil(t, (&Hermit{Monitor: "qemu"}).MonitorBlockCli()) | ||
| } | ||
|
|
||
| func TestHermitMonitorNetCli_NonQemuReturnsEmpty(t *testing.T) { |
Contributor
There was a problem hiding this comment.
Please merge this function with the below one.
Comment on lines
+127
to
+172
| func TestHermitInit_NoNetwork(t *testing.T) { | ||
| h := newHermit() | ||
| err := h.Init(types.UnikernelParams{ | ||
| CmdLine: []string{"/bin/run", "arg1", "arg2"}, | ||
| Monitor: "qemu", | ||
| }) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, "/bin/run arg1 arg2", h.Command) | ||
| assert.Equal(t, "qemu", h.Monitor) | ||
| assert.Equal(t, "", h.Net.Address) | ||
| assert.Equal(t, 0, h.Net.Mask) | ||
|
|
||
| cmdStr, _ := h.CommandString() | ||
| assert.Equal(t, "/bin/run arg1 arg2", cmdStr) | ||
| } | ||
|
|
||
| func TestHermitInit_WithMaskComputesCIDR(t *testing.T) { | ||
| h := newHermit() | ||
| err := h.Init(types.UnikernelParams{ | ||
| CmdLine: []string{"app"}, | ||
| Monitor: "qemu", | ||
| Net: types.NetDevParams{ | ||
| IP: "10.0.0.5", | ||
| Mask: "255.255.255.0", | ||
| Gateway: "10.0.0.1", | ||
| }, | ||
| }) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, "10.0.0.5", h.Net.Address) | ||
| assert.Equal(t, 24, h.Net.Mask) | ||
| assert.Equal(t, "10.0.0.1", h.Net.Gateway) | ||
|
|
||
| cs, _ := h.CommandString() | ||
| assert.Equal(t, "ip=10.0.0.5/24 gateway=10.0.0.1 -- app", cs) | ||
| } | ||
|
|
||
| func TestHermitInit_BadMaskBubblesError(t *testing.T) { | ||
| h := newHermit() | ||
| err := h.Init(types.UnikernelParams{ | ||
| Monitor: "qemu", | ||
| Net: types.NetDevParams{ | ||
| IP: "10.0.0.5", | ||
| Mask: "not-a-mask", | ||
| }, | ||
| }) | ||
| if assert.Error(t, err) { |
| cases := []struct { | ||
| name string | ||
| in Hermit | ||
| want string |
Contributor
There was a problem hiding this comment.
Replace want with expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds unit tests for the Hermit unikernel backend, covering CommandString, MonitorNetCli, MonitorBlockCli, MonitorCli, SupportsBlock, SupportsFS and Init. Tests verify the cmdline assembly with and without networking, the qemu-only netdev/device flags (with arch-aware virtio-net selection), the always-on -no-reboot monitor arg and the subnet-mask CIDR conversion path inside Init.
Related issues
How was this tested?
All 14 unit tests pass locally. Full package tests pass. Linter passes (make lint, 0 issues).
LLM usage
LLM assisted with locating coverage gaps only. All code was written manually and tested locally.
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).