docker_api_update_unix_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // +build !windows
  2. package main
  3. import (
  4. "strings"
  5. "github.com/docker/docker/api/types/container"
  6. "github.com/docker/docker/client"
  7. "github.com/docker/docker/integration-cli/checker"
  8. "github.com/go-check/check"
  9. "golang.org/x/net/context"
  10. )
  11. func (s *DockerSuite) TestAPIUpdateContainer(c *check.C) {
  12. testRequires(c, DaemonIsLinux)
  13. testRequires(c, memoryLimitSupport)
  14. testRequires(c, swapMemorySupport)
  15. name := "apiUpdateContainer"
  16. updateConfig := container.UpdateConfig{
  17. Resources: container.Resources{
  18. Memory: 314572800,
  19. MemorySwap: 524288000,
  20. },
  21. }
  22. dockerCmd(c, "run", "-d", "--name", name, "-m", "200M", "busybox", "top")
  23. cli, err := client.NewEnvClient()
  24. c.Assert(err, check.IsNil)
  25. defer cli.Close()
  26. _, err = cli.ContainerUpdate(context.Background(), name, updateConfig)
  27. c.Assert(err, check.IsNil)
  28. c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "314572800")
  29. file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
  30. out, _ := dockerCmd(c, "exec", name, "cat", file)
  31. c.Assert(strings.TrimSpace(out), checker.Equals, "314572800")
  32. c.Assert(inspectField(c, name, "HostConfig.MemorySwap"), checker.Equals, "524288000")
  33. file = "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes"
  34. out, _ = dockerCmd(c, "exec", name, "cat", file)
  35. c.Assert(strings.TrimSpace(out), checker.Equals, "524288000")
  36. }