Skip to content

test(unikernels): add unit tests for Hermit#638

Open
r0hansaxena wants to merge 1 commit into
urunc-dev:mainfrom
r0hansaxena:test/hermit
Open

test(unikernels): add unit tests for Hermit#638
r0hansaxena wants to merge 1 commit into
urunc-dev:mainfrom
r0hansaxena:test/hermit

Conversation

@r0hansaxena
Copy link
Copy Markdown

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

  • 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.

Signed-off-by: r0hansaxena <rohansxn8772@gmail.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 7, 2026

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit 7d5ab64
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/69fc50a0aaec7f00087448da

Copy link
Copy Markdown
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @r0hansaxena ,

Thank you for the PR.

I have add ed some comments to your changes.

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(""))
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason test such straightforward and small function through unit testing

assert.Nil(t, (&Hermit{Monitor: "qemu"}).MonitorBlockCli())
}

func TestHermitMonitorNetCli_NonQemuReturnsEmpty(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge these tests.

cases := []struct {
name string
in Hermit
want string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace want with expected

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.

2 participants