ipc_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package e2e
  14. import (
  15. "fmt"
  16. "strings"
  17. "testing"
  18. "gotest.tools/v3/icmd"
  19. )
  20. func TestIPC(t *testing.T) {
  21. c := NewParallelE2eCLI(t, binDir)
  22. const projectName = "ipc_e2e"
  23. var cid string
  24. t.Run("create ipc mode container", func(t *testing.T) {
  25. res := c.RunDockerCmd("run", "-d", "--rm", "--ipc=shareable", "--name", "ipc_mode_container", "alpine", "top")
  26. cid = strings.Trim(res.Stdout(), "\n")
  27. })
  28. t.Run("up", func(t *testing.T) {
  29. c.RunDockerCmd("compose", "-f", "./fixtures/ipc-test/compose.yaml", "--project-name", projectName, "up", "-d")
  30. })
  31. t.Run("check running project", func(t *testing.T) {
  32. res := c.RunDockerCmd("compose", "-p", projectName, "ps")
  33. res.Assert(t, icmd.Expected{Out: `shareable`})
  34. })
  35. t.Run("check ipcmode in container inspect", func(t *testing.T) {
  36. res := c.RunDockerCmd("inspect", projectName+"-shareable-1")
  37. res.Assert(t, icmd.Expected{Out: `"IpcMode": "shareable",`})
  38. res = c.RunDockerCmd("inspect", projectName+"-service-1")
  39. res.Assert(t, icmd.Expected{Out: `"IpcMode": "container:`})
  40. res = c.RunDockerCmd("inspect", projectName+"-container-1")
  41. res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`"IpcMode": "container:%s",`, cid)})
  42. })
  43. t.Run("down", func(t *testing.T) {
  44. _ = c.RunDockerCmd("compose", "--project-name", projectName, "down")
  45. })
  46. t.Run("remove ipc mode container", func(t *testing.T) {
  47. _ = c.RunDockerCmd("rm", "-f", "ipc_mode_container")
  48. })
  49. }