test(unikernels): add unit test coverage for linux backend#613
test(unikernels): add unit test coverage for linux backend#613theycallmeaabie wants to merge 1 commit into
Conversation
Signed-off-by: theycallmeaabie <theycallmeaabie@gmail.com>
✅ Deploy Preview for urunc canceled.
|
There was a problem hiding this comment.
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.
| 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", | ||
| }, | ||
| }) |
| 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) { |
cmainas
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
I am not sure if we need to test the constructor.
| 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) { |
| } | ||
| } | ||
|
|
||
| func TestLinuxMonitorNetCli(t *testing.T) { |
There was a problem hiding this comment.
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, | ||
| }, | ||
| { |
There was a problem hiding this comment.
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, | ||
| }, | ||
| { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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"} |
There was a problem hiding this comment.
Please use a different name than cloud-hypervisor.
Description
Adds
linux_test.gowith comprehensive unit tests forpkg/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/...
LLM usage
Gemini 3.1 was used for assistance, all the code is manually reviewed and edited.
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).