Skip to content

test(unikernels): add unit test coverage for linux backend#613

Open
theycallmeaabie wants to merge 1 commit into
urunc-dev:mainfrom
theycallmeaabie:add-test-coverage-unikernels-linux
Open

test(unikernels): add unit test coverage for linux backend#613
theycallmeaabie wants to merge 1 commit into
urunc-dev:mainfrom
theycallmeaabie:add-test-coverage-unikernels-linux

Conversation

@theycallmeaabie
Copy link
Copy Markdown

Description

Adds linux_test.go with comprehensive unit tests for pkg/unikontainers/unikernels/linux.go.
These additions significantly improve test coverage for linux.go, bringing it to approximately 99%.

Related issues

#96

How was this tested?

Tests were executed using:

go test -cover ./pkg/unikontainers/unikernels/...

  • All 36 subtests passed successfully

LLM usage

Gemini 3.1 was used for assistance, all the code is manually reviewed and edited.

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: theycallmeaabie <theycallmeaabie@gmail.com>
Copilot AI review requested due to automatic review settings May 3, 2026 11:40
@netlify
Copy link
Copy Markdown

netlify Bot commented May 3, 2026

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit b6a1053
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/69f7341c2a1cf10007760134

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a dedicated unit test suite for the Linux unikernel backend in pkg/unikontainers/unikernels, aiming to improve confidence in linux.go behavior around boot parameter generation, monitor CLI wiring, urunit config generation, and initialization paths.

Changes:

  • Add unit tests for Linux backend helpers such as filesystem support, subnet checks, command-line parsing, and network configuration.
  • Add behavior-focused tests for monitor block/CLI argument generation and kernel command-line construction across rootfs and urunit modes.
  • Add initialization tests for urunit config creation and selected error propagation paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +513 to +520
err := l.Init(types.UnikernelParams{
CmdLine: []string{"/usr/bin/urunit"},
Rootfs: types.RootfsParams{
Type: "initrd",
MonRootfs: filepath.Join(tmp, "does-not-exist"),
Path: "initrd.cpio",
},
})
Comment on lines +47 to +60
fs string
want bool
}{
{"ext2", true},
{"ext3", true},
{"ext4", true},
{"9pfs", true},
{"virtiofs", true},
{"xfs", false},
{"btrfs", false},
{"", false},
}
for _, c := range cases {
t.Run(c.fs, func(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.

This is valid

Comment thread pkg/unikontainers/unikernels/linux_test.go
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 @theycallmeaabie ,

thank you for the PR. I have added some comments.

"github.com/urunc-dev/urunc/pkg/unikontainers/types"
)

func TestNewLinux(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.

I am not sure if we need to test the constructor.

Comment on lines +47 to +60
fs string
want bool
}{
{"ext2", true},
{"ext3", true},
{"ext4", true},
{"9pfs", true},
{"virtiofs", true},
{"xfs", false},
{"btrfs", false},
{"", false},
}
for _, c := range cases {
t.Run(c.fs, func(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.

This is valid

}
}

func TestLinuxMonitorNetCli(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.

Not sure if we should this test either.

net: LinuxNet{Address: "10.0.0.5", Gateway: "192.168.1.1", Mask: "255.255.255.0"},
want: false,
},
{
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.

Unnecessary test. It is the same test case as address inside /24 gateway subnet

net: LinuxNet{Address: "172.16.5.10", Gateway: "172.16.0.1", Mask: "255.255.0.0"},
want: true,
},
{
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.

Unnecessary test. It is the same test case as address outside /24 gateway subnet

}
out := l.buildUrunitConfig()
assert.NotContains(t, out, "ID:rootfs")
assert.Contains(t, out, "ID:data\nMP:/data\n")
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.

We should also include the markers.

assert.Contains(t, args[0].ExactArgs, "id=data,file=/d")
assert.Empty(t, args[0].ID)
assert.Empty(t, args[0].Path)
assert.Contains(t, args[1].ExactArgs, "serial=logs,drive=logs")
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.

We can also add the same checks as for the first args

t.Run("unknown monitor returns nil", func(t *testing.T) {
t.Parallel()
l := &Linux{
Monitor: "cloud-hypervisor",
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 use a different name, since this is is valid and we need to add that case for block handling.

func TestLinuxMonitorCli(t *testing.T) {
t.Parallel()

t.Run("qemu without urunit returns OtherArgs only", func(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.

There is no reference to urunit in MonitorCli. The name of the unit test should be related to the specific function and arguments.


t.Run("unknown monitor returns zero", func(t *testing.T) {
t.Parallel()
l := &Linux{Monitor: "cloud-hypervisor"}
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 use a different name than cloud-hypervisor.

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.

3 participants