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