|
@@ -10,6 +10,7 @@ import (
|
|
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/pkg/sysinfo"
|
|
"github.com/docker/docker/pkg/sysinfo"
|
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
)
|
|
)
|
|
|
|
|
|
// TODO Windows: This will need addressing for a Windows daemon.
|
|
// TODO Windows: This will need addressing for a Windows daemon.
|
|
@@ -61,43 +62,33 @@ func TestNetworkModeTest(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
func TestIpcModeTest(t *testing.T) {
|
|
func TestIpcModeTest(t *testing.T) {
|
|
- ipcModes := map[container.IpcMode][]bool{
|
|
|
|
- // private, host, container, valid
|
|
|
|
- "": {true, false, false, true},
|
|
|
|
- "something:weird": {true, false, false, false},
|
|
|
|
- ":weird": {true, false, false, true},
|
|
|
|
- "host": {false, true, false, true},
|
|
|
|
- "container:name": {false, false, true, true},
|
|
|
|
- "container:name:something": {false, false, true, false},
|
|
|
|
- "container:": {false, false, true, false},
|
|
|
|
|
|
+ ipcModes := map[container.IpcMode]struct {
|
|
|
|
+ private bool
|
|
|
|
+ host bool
|
|
|
|
+ container bool
|
|
|
|
+ shareable bool
|
|
|
|
+ valid bool
|
|
|
|
+ ctrName string
|
|
|
|
+ }{
|
|
|
|
+ "": {valid: true},
|
|
|
|
+ "private": {private: true, valid: true},
|
|
|
|
+ "something:weird": {},
|
|
|
|
+ ":weird": {},
|
|
|
|
+ "host": {host: true, valid: true},
|
|
|
|
+ "container": {},
|
|
|
|
+ "container:": {container: true, valid: true, ctrName: ""},
|
|
|
|
+ "container:name": {container: true, valid: true, ctrName: "name"},
|
|
|
|
+ "container:name1:name2": {container: true, valid: true, ctrName: "name1:name2"},
|
|
|
|
+ "shareable": {shareable: true, valid: true},
|
|
}
|
|
}
|
|
|
|
+
|
|
for ipcMode, state := range ipcModes {
|
|
for ipcMode, state := range ipcModes {
|
|
- if ipcMode.IsPrivate() != state[0] {
|
|
|
|
- t.Fatalf("IpcMode.IsPrivate for %v should have been %v but was %v", ipcMode, state[0], ipcMode.IsPrivate())
|
|
|
|
- }
|
|
|
|
- if ipcMode.IsHost() != state[1] {
|
|
|
|
- t.Fatalf("IpcMode.IsHost for %v should have been %v but was %v", ipcMode, state[1], ipcMode.IsHost())
|
|
|
|
- }
|
|
|
|
- if ipcMode.IsContainer() != state[2] {
|
|
|
|
- t.Fatalf("IpcMode.IsContainer for %v should have been %v but was %v", ipcMode, state[2], ipcMode.IsContainer())
|
|
|
|
- }
|
|
|
|
- if ipcMode.Valid() != state[3] {
|
|
|
|
- t.Fatalf("IpcMode.Valid for %v should have been %v but was %v", ipcMode, state[3], ipcMode.Valid())
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- containerIpcModes := map[container.IpcMode]string{
|
|
|
|
- "": "",
|
|
|
|
- "something": "",
|
|
|
|
- "something:weird": "weird",
|
|
|
|
- "container": "",
|
|
|
|
- "container:": "",
|
|
|
|
- "container:name": "name",
|
|
|
|
- "container:name1:name2": "name1:name2",
|
|
|
|
- }
|
|
|
|
- for ipcMode, container := range containerIpcModes {
|
|
|
|
- if ipcMode.Container() != container {
|
|
|
|
- t.Fatalf("Expected %v for %v but was %v", container, ipcMode, ipcMode.Container())
|
|
|
|
- }
|
|
|
|
|
|
+ assert.Equal(t, state.private, ipcMode.IsPrivate(), "IpcMode.IsPrivate() parsing failed for %q", ipcMode)
|
|
|
|
+ assert.Equal(t, state.host, ipcMode.IsHost(), "IpcMode.IsHost() parsing failed for %q", ipcMode)
|
|
|
|
+ assert.Equal(t, state.container, ipcMode.IsContainer(), "IpcMode.IsContainer() parsing failed for %q", ipcMode)
|
|
|
|
+ assert.Equal(t, state.shareable, ipcMode.IsShareable(), "IpcMode.IsShareable() parsing failed for %q", ipcMode)
|
|
|
|
+ assert.Equal(t, state.valid, ipcMode.Valid(), "IpcMode.Valid() parsing failed for %q", ipcMode)
|
|
|
|
+ assert.Equal(t, state.ctrName, ipcMode.Container(), "IpcMode.Container() parsing failed for %q", ipcMode)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|