Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ test: unittest e2etest

## unittest Run all unit tests
.PHONY: unittest
unittest: test_unikontainers test_metrics test_network test_hypervisors
unittest: test_unikontainers test_metrics test_network test_hypervisors test_unikernels

## e2etest Run all end-to-end tests
.PHONY: e2etest
Expand Down Expand Up @@ -263,6 +263,12 @@ test_hypervisors:
@GOFLAGS=$(TEST_FLAGS) $(GO) test $(TEST_OPTS) ./pkg/unikontainers/hypervisors -v
@echo " "

## test_unikernels Run unit tests for unikernels package
test_unikernels:
@echo "Unit testing in unikernels"
@GOFLAGS=$(TEST_FLAGS) $(GO) test $(TEST_OPTS) ./pkg/unikontainers/unikernels -v
@echo " "

## test_nerdctl Run all end-to-end tests with nerdctl
.PHONY: test_nerdctl
test_nerdctl:
Expand Down
6 changes: 4 additions & 2 deletions pkg/unikontainers/unikernels/mewz.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ type MewzNet struct {
}

func (m *Mewz) CommandString() (string, error) {
return fmt.Sprintf("ip=%s/%d gateway=%s ", m.Net.Address, m.Net.Mask,
m.Net.Gateway), nil
if m.Net.Address != "" {
return fmt.Sprintf("ip=%s/%d gateway=%s", m.Net.Address, m.Net.Mask, m.Net.Gateway), nil
}
return "", nil
}

func (m *Mewz) SupportsBlock() bool {
Expand Down
58 changes: 58 additions & 0 deletions pkg/unikontainers/unikernels/mewz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2023-2026, Nubificus LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package unikernels

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

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

testCases := []struct {
name string
mewz *Mewz
expected string
}{
{
name: "no network configured",
mewz: &Mewz{},
expected: "",
},
{
name: "with network configured",
mewz: &Mewz{
Net: MewzNet{
Address: "10.0.0.2",
Mask: 24,
Gateway: "10.0.0.1",
},
},
expected: "ip=10.0.0.2/24 gateway=10.0.0.1",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
result, err := tc.mewz.CommandString()
require.NoError(t, err)
assert.Equal(t, tc.expected, result)
})
}
}