github.com/stuarqi/moby@v1.13.1/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/pkg/integration/checker" 12 "github.com/go-check/check" 13 ) 14 15 func (s *DockerSuite) TestAPIStatsContainerGetMemoryLimit(c *check.C) { 16 testRequires(c, DaemonIsLinux, memoryLimitSupport) 17 18 resp, body, err := sockRequestRaw("GET", "/info", nil, "application/json") 19 c.Assert(err, checker.IsNil) 20 c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) 21 var info types.Info 22 err = json.NewDecoder(body).Decode(&info) 23 c.Assert(err, checker.IsNil) 24 body.Close() 25 26 // don't set a memory limit, the memory limit should be system memory 27 conName := "foo" 28 dockerCmd(c, "run", "-d", "--name", conName, "busybox", "top") 29 c.Assert(waitRun(conName), checker.IsNil) 30 31 resp, body, err = sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", conName), nil, "") 32 c.Assert(err, checker.IsNil) 33 c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) 34 c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json") 35 36 var v *types.Stats 37 err = json.NewDecoder(body).Decode(&v) 38 c.Assert(err, checker.IsNil) 39 body.Close() 40 c.Assert(fmt.Sprintf("%d", v.MemoryStats.Limit), checker.Equals, fmt.Sprintf("%d", info.MemTotal)) 41 }