Browse code

Update docker_cli_build_unix_test

Signed-off-by: Hu Keping <hukeping@huawei.com>

Hu Keping authored on 2015/10/26 22:00:16
Showing 1 changed files
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"encoding/json"
7 7
 	"strings"
8 8
 
9
+	"github.com/docker/docker/pkg/integration/checker"
9 10
 	"github.com/docker/docker/pkg/ulimit"
10 11
 	"github.com/go-check/check"
11 12
 )
... ...
@@ -18,14 +19,11 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
18 18
 	FROM hello-world:frozen
19 19
 	RUN ["/hello"]
20 20
 	`, map[string]string{})
21
-	if err != nil {
22
-		c.Fatal(err)
23
-	}
21
+	c.Assert(err, checker.IsNil)
24 22
 
25 23
 	dockerCmdInDir(c, ctx.Dir, "build", "--no-cache", "--rm=false", "--memory=64m", "--memory-swap=-1", "--cpuset-cpus=0", "--cpuset-mems=0", "--cpu-shares=100", "--cpu-quota=8000", "--ulimit", "nofile=42", "-t", name, ".")
26 24
 
27 25
 	out, _ := dockerCmd(c, "ps", "-lq")
28
-
29 26
 	cID := strings.TrimSpace(out)
30 27
 
31 28
 	type hostConfig struct {
... ...
@@ -39,34 +37,36 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
39 39
 	}
40 40
 
41 41
 	cfg, err := inspectFieldJSON(cID, "HostConfig")
42
-	if err != nil {
43
-		c.Fatal(err)
44
-	}
42
+	c.Assert(err, checker.IsNil)
45 43
 
46 44
 	var c1 hostConfig
47
-	if err := json.Unmarshal([]byte(cfg), &c1); err != nil {
48
-		c.Fatal(err, cfg)
49
-	}
50
-	if c1.Memory != 67108864 || c1.MemorySwap != -1 || c1.CpusetCpus != "0" || c1.CpusetMems != "0" || c1.CPUShares != 100 || c1.CPUQuota != 8000 || c1.Ulimits[0].Name != "nofile" || c1.Ulimits[0].Hard != 42 {
51
-		c.Fatalf("resource constraints not set properly:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CPUShares: %d, CPUQuota: %d, Ulimits: %s",
52
-			c1.Memory, c1.MemorySwap, c1.CpusetCpus, c1.CpusetMems, c1.CPUShares, c1.CPUQuota, c1.Ulimits[0])
53
-	}
45
+	err = json.Unmarshal([]byte(cfg), &c1)
46
+	c.Assert(err, checker.IsNil, check.Commentf(cfg))
47
+
48
+	c.Assert(c1.Memory, checker.Equals, int64(64*1024*1024), check.Commentf("resource constraints not set properly for Memory"))
49
+	c.Assert(c1.MemorySwap, checker.Equals, int64(-1), check.Commentf("resource constraints not set properly for MemorySwap"))
50
+	c.Assert(c1.CpusetCpus, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetCpus"))
51
+	c.Assert(c1.CpusetMems, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetMems"))
52
+	c.Assert(c1.CPUShares, checker.Equals, int64(100), check.Commentf("resource constraints not set properly for CPUShares"))
53
+	c.Assert(c1.CPUQuota, checker.Equals, int64(8000), check.Commentf("resource constraints not set properly for CPUQuota"))
54
+	c.Assert(c1.Ulimits[0].Name, checker.Equals, "nofile", check.Commentf("resource constraints not set properly for Ulimits"))
55
+	c.Assert(c1.Ulimits[0].Hard, checker.Equals, int64(42), check.Commentf("resource constraints not set properly for Ulimits"))
54 56
 
55 57
 	// Make sure constraints aren't saved to image
56 58
 	dockerCmd(c, "run", "--name=test", name)
57 59
 
58 60
 	cfg, err = inspectFieldJSON("test", "HostConfig")
59
-	if err != nil {
60
-		c.Fatal(err)
61
-	}
62
-	var c2 hostConfig
63
-	if err := json.Unmarshal([]byte(cfg), &c2); err != nil {
64
-		c.Fatal(err, cfg)
65
-	}
66
-	if c2.Memory == 67108864 || c2.MemorySwap == -1 || c2.CpusetCpus == "0" || c2.CpusetMems == "0" || c2.CPUShares == 100 || c2.CPUQuota == 8000 || c2.Ulimits != nil {
67
-		c.Fatalf("resource constraints leaked from build:\nMemory: %d, MemSwap: %d, CpusetCpus: %s, CpusetMems: %s, CPUShares: %d, CPUQuota: %d, Ulimits: %s",
68
-			c2.Memory, c2.MemorySwap, c2.CpusetCpus, c2.CpusetMems, c2.CPUShares, c2.CPUQuota, c2.Ulimits)
61
+	c.Assert(err, checker.IsNil)
69 62
 
70
-	}
63
+	var c2 hostConfig
64
+	err = json.Unmarshal([]byte(cfg), &c2)
65
+	c.Assert(err, checker.IsNil, check.Commentf(cfg))
71 66
 
67
+	c.Assert(c2.Memory, check.Not(checker.Equals), int64(64*1024*1024), check.Commentf("resource leaked from build for Memory"))
68
+	c.Assert(c2.MemorySwap, check.Not(checker.Equals), int64(-1), check.Commentf("resource leaked from build for MemorySwap"))
69
+	c.Assert(c2.CpusetCpus, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetCpus"))
70
+	c.Assert(c2.CpusetMems, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetMems"))
71
+	c.Assert(c2.CPUShares, check.Not(checker.Equals), int64(100), check.Commentf("resource leaked from build for CPUShares"))
72
+	c.Assert(c2.CPUQuota, check.Not(checker.Equals), int64(8000), check.Commentf("resource leaked from build for CPUQuota"))
73
+	c.Assert(c2.Ulimits, checker.IsNil, check.Commentf("resource leaked from build for Ulimits"))
72 74
 }