diff --git a/pkg/unikontainers/unikernels/mewz.go b/pkg/unikontainers/unikernels/mewz.go index 5286ee42..cd512de3 100644 --- a/pkg/unikontainers/unikernels/mewz.go +++ b/pkg/unikontainers/unikernels/mewz.go @@ -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 { diff --git a/pkg/unikontainers/unikernels/mewz_test.go b/pkg/unikontainers/unikernels/mewz_test.go new file mode 100644 index 00000000..c4ac12a0 --- /dev/null +++ b/pkg/unikontainers/unikernels/mewz_test.go @@ -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) + }) + } +}