mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Assert error in body of function inspectField*
1. Replace raw `docker inspect -f xxx` with `inspectField`, to make code cleaner and more consistent 2. assert the error in function `inspectField*` so we don't need to assert the return value of it every time, this will make inspect easier. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
parent
725b5b595b
commit
62a856e912
34 changed files with 298 additions and 591 deletions
|
@ -20,8 +20,7 @@ func (s *DockerSuite) TestUpdateRunningContainer(c *check.C) {
|
|||
dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "top")
|
||||
dockerCmd(c, "update", "-m", "500M", name)
|
||||
|
||||
memory, err := inspectField(name, "HostConfig.Memory")
|
||||
c.Assert(err, check.IsNil)
|
||||
memory := inspectField(c, name, "HostConfig.Memory")
|
||||
if memory != "524288000" {
|
||||
c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory)
|
||||
}
|
||||
|
@ -40,8 +39,7 @@ func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *check.C) {
|
|||
dockerCmd(c, "update", "-m", "500M", name)
|
||||
dockerCmd(c, "restart", name)
|
||||
|
||||
memory, err := inspectField(name, "HostConfig.Memory")
|
||||
c.Assert(err, check.IsNil)
|
||||
memory := inspectField(c, name, "HostConfig.Memory")
|
||||
if memory != "524288000" {
|
||||
c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory)
|
||||
}
|
||||
|
@ -60,8 +58,7 @@ func (s *DockerSuite) TestUpdateStoppedContainer(c *check.C) {
|
|||
dockerCmd(c, "run", "--name", name, "-m", "300M", "busybox", "cat", file)
|
||||
dockerCmd(c, "update", "-m", "500M", name)
|
||||
|
||||
memory, err := inspectField(name, "HostConfig.Memory")
|
||||
c.Assert(err, check.IsNil)
|
||||
memory := inspectField(c, name, "HostConfig.Memory")
|
||||
if memory != "524288000" {
|
||||
c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory)
|
||||
}
|
||||
|
@ -79,8 +76,7 @@ func (s *DockerSuite) TestUpdatePausedContainer(c *check.C) {
|
|||
dockerCmd(c, "pause", name)
|
||||
dockerCmd(c, "update", "--cpu-shares", "500", name)
|
||||
|
||||
out, err := inspectField(name, "HostConfig.CPUShares")
|
||||
c.Assert(err, check.IsNil)
|
||||
out := inspectField(c, name, "HostConfig.CPUShares")
|
||||
if out != "500" {
|
||||
c.Fatalf("Got the wrong cpu shares value, we got %d, expected 500.", out)
|
||||
}
|
||||
|
@ -101,8 +97,7 @@ func (s *DockerSuite) TestUpdateWithUntouchedFields(c *check.C) {
|
|||
dockerCmd(c, "update", "-m", "500M", name)
|
||||
|
||||
// Update memory and not touch cpus, `cpuset.cpus` should still have the old value
|
||||
out, err := inspectField(name, "HostConfig.CPUShares")
|
||||
c.Assert(err, check.IsNil)
|
||||
out := inspectField(c, name, "HostConfig.CPUShares")
|
||||
c.Assert(out, check.Equals, "800")
|
||||
|
||||
file := "/sys/fs/cgroup/cpu/cpu.shares"
|
||||
|
@ -142,8 +137,7 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
|
|||
// Update kernel memory to a running container is not allowed.
|
||||
c.Assert(err, check.NotNil)
|
||||
|
||||
out, err := inspectField(name, "HostConfig.KernelMemory")
|
||||
c.Assert(err, check.IsNil)
|
||||
out := inspectField(c, name, "HostConfig.KernelMemory")
|
||||
// Update kernel memory to a running container with failure should not change HostConfig
|
||||
if out != "52428800" {
|
||||
c.Fatalf("Got the wrong memory value, we got %d, expected 52428800(50M).", out)
|
||||
|
@ -153,8 +147,7 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
|
|||
dockerCmd(c, "update", "--kernel-memory", "100M", name)
|
||||
dockerCmd(c, "start", name)
|
||||
|
||||
out, err = inspectField(name, "HostConfig.KernelMemory")
|
||||
c.Assert(err, check.IsNil)
|
||||
out = inspectField(c, name, "HostConfig.KernelMemory")
|
||||
if out != "104857600" {
|
||||
c.Fatalf("Got the wrong memory value, we got %d, expected 104857600(100M).", out)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue