moby/integration/container/pidmode_linux_test.go
Akihiro Suda 227687f2ef
rootless: support --pid=host
Fix #41457

related: https://github.com/containers/podman/blob/v3.0.0-rc1/pkg/specgen/generate/oci.go#L248-L257

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-02-01 14:55:18 +09:00

37 lines
1.1 KiB
Go

package container // import "github.com/docker/docker/integration/container"
import (
"context"
"os"
"testing"
"time"
"github.com/docker/docker/integration/internal/container"
"gotest.tools/v3/assert"
"gotest.tools/v3/poll"
"gotest.tools/v3/skip"
)
func TestPidHost(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, testEnv.IsRemoteDaemon())
hostPid, err := os.Readlink("/proc/1/ns/pid")
assert.NilError(t, err)
defer setupTest(t)()
client := testEnv.APIClient()
ctx := context.Background()
cID := container.Run(ctx, t, client, func(c *container.TestContainerConfig) {
c.HostConfig.PidMode = "host"
})
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
cPid := container.GetContainerNS(ctx, t, client, cID, "pid")
assert.Assert(t, hostPid == cPid)
cID = container.Run(ctx, t, client)
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
cPid = container.GetContainerNS(ctx, t, client, cID, "pid")
assert.Assert(t, hostPid != cPid)
}