Also use Asserts where it's possible.
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
... | ... |
@@ -136,7 +136,7 @@ func TestModifiedDiscoverySettings(t *testing.T) { |
136 | 136 |
for _, c := range cases { |
137 | 137 |
got := modifiedDiscoverySettings(c.current, c.modified.ClusterStore, c.modified.ClusterAdvertise, c.modified.ClusterOpts) |
138 | 138 |
if c.expected != got { |
139 |
- t.Fatalf("expected %v, got %v: current config %q, new config %q", c.expected, got, c.current, c.modified) |
|
139 |
+ t.Fatalf("expected %v, got %v: current config %v, new config %v", c.expected, got, c.current, c.modified) |
|
140 | 140 |
} |
141 | 141 |
} |
142 | 142 |
} |
... | ... |
@@ -23,18 +23,12 @@ func (s *DockerSuite) TestApiUpdateContainer(c *check.C) { |
23 | 23 |
_, _, err := sockRequest("POST", "/containers/"+name+"/update", hostConfig) |
24 | 24 |
c.Assert(err, check.IsNil) |
25 | 25 |
|
26 |
- memory := inspectField(c, name, "HostConfig.Memory") |
|
27 |
- if memory != "314572800" { |
|
28 |
- c.Fatalf("Got the wrong memory value, we got %d, expected 314572800(300M).", memory) |
|
29 |
- } |
|
26 |
+ c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "314572800") |
|
30 | 27 |
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" |
31 | 28 |
out, _ := dockerCmd(c, "exec", name, "cat", file) |
32 | 29 |
c.Assert(strings.TrimSpace(out), checker.Equals, "314572800") |
33 | 30 |
|
34 |
- memorySwap := inspectField(c, name, "HostConfig.MemorySwap") |
|
35 |
- if memorySwap != "524288000" { |
|
36 |
- c.Fatalf("Got the wrong memorySwap value, we got %d, expected 524288000(500M).", memorySwap) |
|
37 |
- } |
|
31 |
+ c.Assert(inspectField(c, name, "HostConfig.MemorySwap"), checker.Equals, "524288000") |
|
38 | 32 |
file = "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes" |
39 | 33 |
out, _ = dockerCmd(c, "exec", name, "cat", file) |
40 | 34 |
c.Assert(strings.TrimSpace(out), checker.Equals, "524288000") |
... | ... |
@@ -20,10 +20,7 @@ func (s *DockerSuite) TestUpdateRunningContainer(c *check.C) { |
20 | 20 |
dockerCmd(c, "run", "-d", "--name", name, "-m", "300M", "busybox", "top") |
21 | 21 |
dockerCmd(c, "update", "-m", "500M", name) |
22 | 22 |
|
23 |
- memory := inspectField(c, name, "HostConfig.Memory") |
|
24 |
- if memory != "524288000" { |
|
25 |
- c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory) |
|
26 |
- } |
|
23 |
+ c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "524288000") |
|
27 | 24 |
|
28 | 25 |
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" |
29 | 26 |
out, _ := dockerCmd(c, "exec", name, "cat", file) |
... | ... |
@@ -39,10 +36,7 @@ func (s *DockerSuite) TestUpdateRunningContainerWithRestart(c *check.C) { |
39 | 39 |
dockerCmd(c, "update", "-m", "500M", name) |
40 | 40 |
dockerCmd(c, "restart", name) |
41 | 41 |
|
42 |
- memory := inspectField(c, name, "HostConfig.Memory") |
|
43 |
- if memory != "524288000" { |
|
44 |
- c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory) |
|
45 |
- } |
|
42 |
+ c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "524288000") |
|
46 | 43 |
|
47 | 44 |
file := "/sys/fs/cgroup/memory/memory.limit_in_bytes" |
48 | 45 |
out, _ := dockerCmd(c, "exec", name, "cat", file) |
... | ... |
@@ -58,10 +52,7 @@ func (s *DockerSuite) TestUpdateStoppedContainer(c *check.C) { |
58 | 58 |
dockerCmd(c, "run", "--name", name, "-m", "300M", "busybox", "cat", file) |
59 | 59 |
dockerCmd(c, "update", "-m", "500M", name) |
60 | 60 |
|
61 |
- memory := inspectField(c, name, "HostConfig.Memory") |
|
62 |
- if memory != "524288000" { |
|
63 |
- c.Fatalf("Got the wrong memory value, we got %d, expected 524288000(500M).", memory) |
|
64 |
- } |
|
61 |
+ c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "524288000") |
|
65 | 62 |
|
66 | 63 |
out, _ := dockerCmd(c, "start", "-a", name) |
67 | 64 |
c.Assert(strings.TrimSpace(out), checker.Equals, "524288000") |
... | ... |
@@ -76,14 +67,11 @@ func (s *DockerSuite) TestUpdatePausedContainer(c *check.C) { |
76 | 76 |
dockerCmd(c, "pause", name) |
77 | 77 |
dockerCmd(c, "update", "--cpu-shares", "500", name) |
78 | 78 |
|
79 |
- out := inspectField(c, name, "HostConfig.CPUShares") |
|
80 |
- if out != "500" { |
|
81 |
- c.Fatalf("Got the wrong cpu shares value, we got %d, expected 500.", out) |
|
82 |
- } |
|
79 |
+ c.Assert(inspectField(c, name, "HostConfig.CPUShares"), checker.Equals, "500") |
|
83 | 80 |
|
84 | 81 |
dockerCmd(c, "unpause", name) |
85 | 82 |
file := "/sys/fs/cgroup/cpu/cpu.shares" |
86 |
- out, _ = dockerCmd(c, "exec", name, "cat", file) |
|
83 |
+ out, _ := dockerCmd(c, "exec", name, "cat", file) |
|
87 | 84 |
c.Assert(strings.TrimSpace(out), checker.Equals, "500") |
88 | 85 |
} |
89 | 86 |
|
... | ... |
@@ -137,23 +125,17 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) { |
137 | 137 |
// Update kernel memory to a running container is not allowed. |
138 | 138 |
c.Assert(err, check.NotNil) |
139 | 139 |
|
140 |
- out := inspectField(c, name, "HostConfig.KernelMemory") |
|
141 | 140 |
// Update kernel memory to a running container with failure should not change HostConfig |
142 |
- if out != "52428800" { |
|
143 |
- c.Fatalf("Got the wrong memory value, we got %d, expected 52428800(50M).", out) |
|
144 |
- } |
|
141 |
+ c.Assert(inspectField(c, name, "HostConfig.KernelMemory"), checker.Equals, "52428800") |
|
145 | 142 |
|
146 | 143 |
dockerCmd(c, "stop", name) |
147 | 144 |
dockerCmd(c, "update", "--kernel-memory", "100M", name) |
148 | 145 |
dockerCmd(c, "start", name) |
149 | 146 |
|
150 |
- out = inspectField(c, name, "HostConfig.KernelMemory") |
|
151 |
- if out != "104857600" { |
|
152 |
- c.Fatalf("Got the wrong memory value, we got %d, expected 104857600(100M).", out) |
|
153 |
- } |
|
147 |
+ c.Assert(inspectField(c, name, "HostConfig.KernelMemory"), checker.Equals, "104857600") |
|
154 | 148 |
|
155 | 149 |
file := "/sys/fs/cgroup/memory/memory.kmem.limit_in_bytes" |
156 |
- out, _ = dockerCmd(c, "exec", name, "cat", file) |
|
150 |
+ out, _ := dockerCmd(c, "exec", name, "cat", file) |
|
157 | 151 |
c.Assert(strings.TrimSpace(out), checker.Equals, "104857600") |
158 | 152 |
} |
159 | 153 |
|