summaryrefslogtreecommitdiff
path: root/libpod/container_internal_linux_test.go
diff options
context:
space:
mode:
authorParham Alvani <1995parham@tuta.io>2021-09-04 18:24:41 +0430
committerParham Alvani <1995parham@tuta.io>2021-09-04 18:24:41 +0430
commitce5baa125b2334195e995099fe6c8274a603efdf (patch)
treeff2775cff2b41db645029f68006eb5405056f0fe /libpod/container_internal_linux_test.go
parentaf58cb15d2aa46609fc7231647af09f808ba6c1c (diff)
downloadpodman-ce5baa125b2334195e995099fe6c8274a603efdf.tar.gz
podman-ce5baa125b2334195e995099fe6c8274a603efdf.tar.bz2
podman-ce5baa125b2334195e995099fe6c8274a603efdf.zip
feat: add localhost into hosts if the networking mode is not host
Signed-off-by: Parham Alvani <1995parham@tuta.io>
Diffstat (limited to 'libpod/container_internal_linux_test.go')
-rw-r--r--libpod/container_internal_linux_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/libpod/container_internal_linux_test.go b/libpod/container_internal_linux_test.go
index 1465ffbea..899f9bffd 100644
--- a/libpod/container_internal_linux_test.go
+++ b/libpod/container_internal_linux_test.go
@@ -1,3 +1,4 @@
+//go:build linux
// +build linux
package libpod
@@ -7,6 +8,7 @@ import (
"os"
"testing"
+ "github.com/containers/podman/v3/pkg/namespaces"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
)
@@ -68,3 +70,30 @@ func TestGenerateUserGroupEntry(t *testing.T) {
}
assert.Equal(t, group, "567:x:567:567\n")
}
+
+func TestAppendLocalhost(t *testing.T) {
+ {
+ c := Container{
+ config: &ContainerConfig{
+ ContainerNetworkConfig: ContainerNetworkConfig{
+ NetMode: namespaces.NetworkMode("slirp4netns"),
+ },
+ },
+ }
+
+ assert.Equal(t, "127.0.0.1\tlocalhost\n::1\tlocalhost\n", c.appendLocalhost(""))
+ assert.Equal(t, "127.0.0.1\tlocalhost", c.appendLocalhost("127.0.0.1\tlocalhost"))
+ }
+ {
+ c := Container{
+ config: &ContainerConfig{
+ ContainerNetworkConfig: ContainerNetworkConfig{
+ NetMode: namespaces.NetworkMode("host"),
+ },
+ },
+ }
+
+ assert.Equal(t, "", c.appendLocalhost(""))
+ assert.Equal(t, "127.0.0.1\tlocalhost", c.appendLocalhost("127.0.0.1\tlocalhost"))
+ }
+}