docker_api_stats_unix_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // +build !windows
  2. package main
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "net/http"
  7. "github.com/docker/docker/api/types"
  8. "github.com/docker/docker/integration-cli/checker"
  9. "github.com/docker/docker/integration-cli/request"
  10. "github.com/go-check/check"
  11. )
  12. func (s *DockerSuite) TestAPIStatsContainerGetMemoryLimit(c *check.C) {
  13. testRequires(c, DaemonIsLinux, memoryLimitSupport)
  14. resp, body, err := request.Get(daemonHost(), "/info", request.JSON)
  15. c.Assert(err, checker.IsNil)
  16. c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
  17. var info types.Info
  18. err = json.NewDecoder(body).Decode(&info)
  19. c.Assert(err, checker.IsNil)
  20. body.Close()
  21. // don't set a memory limit, the memory limit should be system memory
  22. conName := "foo"
  23. dockerCmd(c, "run", "-d", "--name", conName, "busybox", "top")
  24. c.Assert(waitRun(conName), checker.IsNil)
  25. resp, body, err = request.Get(daemonHost(), fmt.Sprintf("/containers/%s/stats?stream=false", conName))
  26. c.Assert(err, checker.IsNil)
  27. c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
  28. c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
  29. var v *types.Stats
  30. err = json.NewDecoder(body).Decode(&v)
  31. c.Assert(err, checker.IsNil)
  32. body.Close()
  33. c.Assert(fmt.Sprintf("%d", v.MemoryStats.Limit), checker.Equals, fmt.Sprintf("%d", info.MemTotal))
  34. }