github.com/uriddle/docker@v0.0.0-20210926094723-4072e6aeb013/integration-cli/docker_api_update_unix_test.go (about)

     1  // +build !windows
     2  
     3  package main
     4  
     5  import (
     6  	"strings"
     7  
     8  	"github.com/docker/docker/pkg/integration/checker"
     9  	"github.com/go-check/check"
    10  )
    11  
    12  func (s *DockerSuite) TestApiUpdateContainer(c *check.C) {
    13  	testRequires(c, DaemonIsLinux)
    14  	testRequires(c, memoryLimitSupport)
    15  	testRequires(c, swapMemorySupport)
    16  
    17  	name := "apiUpdateContainer"
    18  	hostConfig := map[string]interface{}{
    19  		"Memory":     314572800,
    20  		"MemorySwap": 524288000,
    21  	}
    22  	dockerCmd(c, "run", "-d", "--name", name, "-m", "200M", "busybox", "top")
    23  	_, _, err := sockRequest("POST", "/containers/"+name+"/update", hostConfig)
    24  	c.Assert(err, check.IsNil)
    25  
    26  	memory, err := inspectField(name, "HostConfig.Memory")
    27  	c.Assert(err, check.IsNil)
    28  	if memory != "314572800" {
    29  		c.Fatalf("Got the wrong memory value, we got %d, expected 314572800(300M).", memory)
    30  	}
    31  	file := "/sys/fs/cgroup/memory/memory.limit_in_bytes"
    32  	out, _ := dockerCmd(c, "exec", name, "cat", file)
    33  	c.Assert(strings.TrimSpace(out), checker.Equals, "314572800")
    34  
    35  	memorySwap, err := inspectField(name, "HostConfig.MemorySwap")
    36  	c.Assert(err, check.IsNil)
    37  	if memorySwap != "524288000" {
    38  		c.Fatalf("Got the wrong memorySwap value, we got %d, expected 524288000(500M).", memorySwap)
    39  	}
    40  	file = "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes"
    41  	out, _ = dockerCmd(c, "exec", name, "cat", file)
    42  	c.Assert(strings.TrimSpace(out), checker.Equals, "524288000")
    43  }