Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .github/contributors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ users:
Inuth0603:
name: Divyam Agarwal
email: iitdivyamagarwal@gmail.com
martijnhoekstra:
name: Martijn
email: martijnhoekstra@gmail.com
10 changes: 6 additions & 4 deletions pkg/unikontainers/unikernels/hermit_rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ type HermitNet struct {
func (h *Hermit) CommandString() (string, error) {
var args []string

// Hermit takes the gateway as part of ip=<ip>/<prefix>:<gateway>.
if h.Net.Address != "" {
args = append(args, fmt.Sprintf("ip=%s/%d", h.Net.Address, h.Net.Mask))
}
if h.Net.Gateway != "" {
args = append(args, fmt.Sprintf("gateway=%s", h.Net.Gateway))
ip := fmt.Sprintf("%s/%d", h.Net.Address, h.Net.Mask)
if h.Net.Gateway != "" {
ip += ":" + h.Net.Gateway
}
args = append(args, "ip="+ip)
}

// Add separator ONLY if we have net args AND a command
Expand Down
87 changes: 87 additions & 0 deletions pkg/unikontainers/unikernels/hermit_rs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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 TestHermitCommandString(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
hermit *Hermit
expected string
}{
{
name: "no network configured",
hermit: &Hermit{},
expected: "",
},
{
name: "address and gateway",
hermit: &Hermit{
Net: HermitNet{
Address: "10.0.0.2",
Mask: 24,
Gateway: "10.0.0.1",
},
},
expected: "ip=10.0.0.2/24:10.0.0.1",
},
{
name: "address without gateway",
hermit: &Hermit{
Net: HermitNet{
Address: "10.0.0.2",
Mask: 24,
},
},
expected: "ip=10.0.0.2/24",
},
{
name: "network and application arguments",
hermit: &Hermit{
Command: "/app --port 8080",
Net: HermitNet{
Address: "10.0.0.2",
Mask: 24,
Gateway: "10.0.0.1",
},
},
expected: "ip=10.0.0.2/24:10.0.0.1 -- /app --port 8080",
},
{
name: "application arguments without network",
hermit: &Hermit{
Command: "/app --port 8080",
},
expected: "/app --port 8080",
},
}

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