diff options
author | Chen Min <chenmin46@huawei.com> | 2017-08-02 03:04:37 +0800 |
---|---|---|
committer | Chen Min <chenmin46@huawei.com> | 2017-08-25 01:55:50 +0800 |
commit | b6e5ea8e5757fa89e03ed3e76f1d85c068b3522d (patch) | |
tree | efec0f6851b870746a87c801574dd45621ee213f /daemon/daemon_unix_test.go | |
parent | db73f3daee21a28edbf6991d24a4653adc85f1a2 (diff) | |
download | docker-b6e5ea8e5757fa89e03ed3e76f1d85c068b3522d.tar.gz |
Use ID rather than Name to identify a container when sharing namespace
Fix: https://github.com/moby/moby/issues/34307
Signed-off-by: Chen Min <chenmin46@huawei.com>
Diffstat (limited to 'daemon/daemon_unix_test.go')
-rw-r--r-- | daemon/daemon_unix_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/daemon/daemon_unix_test.go b/daemon/daemon_unix_test.go index c3aa443e45..f3a7ce4ae8 100644 --- a/daemon/daemon_unix_test.go +++ b/daemon/daemon_unix_test.go @@ -3,6 +3,7 @@ package daemon import ( + "errors" "io/ioutil" "os" "path/filepath" @@ -18,6 +19,44 @@ import ( "github.com/docker/docker/volume/store" ) +type fakeContainerGetter struct { + containers map[string]*container.Container +} + +func (f *fakeContainerGetter) GetContainer(cid string) (*container.Container, error) { + container, ok := f.containers[cid] + if !ok { + return nil, errors.New("container not found") + } + return container, nil +} + +// Unix test as uses settings which are not available on Windows +func TestAdjustSharedNamespaceContainerName(t *testing.T) { + fakeID := "abcdef1234567890" + hostConfig := &containertypes.HostConfig{ + IpcMode: containertypes.IpcMode("container:base"), + PidMode: containertypes.PidMode("container:base"), + NetworkMode: containertypes.NetworkMode("container:base"), + } + containerStore := &fakeContainerGetter{} + containerStore.containers = make(map[string]*container.Container) + containerStore.containers["base"] = &container.Container{ + ID: fakeID, + } + + adaptSharedNamespaceContainer(containerStore, hostConfig) + if hostConfig.IpcMode != containertypes.IpcMode("container:"+fakeID) { + t.Errorf("Expected IpcMode to be container:%s", fakeID) + } + if hostConfig.PidMode != containertypes.PidMode("container:"+fakeID) { + t.Errorf("Expected PidMode to be container:%s", fakeID) + } + if hostConfig.NetworkMode != containertypes.NetworkMode("container:"+fakeID) { + t.Errorf("Expected NetworkMode to be container:%s", fakeID) + } +} + // Unix test as uses settings which are not available on Windows func TestAdjustCPUShares(t *testing.T) { tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-") |