Browse code

force inspect test format

Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Victor Vieux authored on 2017/09/02 04:14:59
Showing 2 changed files
... ...
@@ -4,6 +4,7 @@ package main
4 4
 
5 5
 import (
6 6
 	"bufio"
7
+	"context"
7 8
 	"encoding/json"
8 9
 	"fmt"
9 10
 	"io/ioutil"
... ...
@@ -16,6 +17,7 @@ import (
16 16
 	"syscall"
17 17
 	"time"
18 18
 
19
+	"github.com/docker/docker/client"
19 20
 	"github.com/docker/docker/integration-cli/checker"
20 21
 	"github.com/docker/docker/integration-cli/cli"
21 22
 	"github.com/docker/docker/integration-cli/cli/build"
... ...
@@ -1563,14 +1565,18 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
1563 1563
 	out, _ := dockerCmd(c, "run", "--cpus", "0.5", "--name", "test", "busybox", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2))
1564 1564
 	c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000")
1565 1565
 
1566
-	out = inspectField(c, "test", "HostConfig.NanoCpus")
1567
-	c.Assert(out, checker.Equals, "5e+08", check.Commentf("setting the Nano CPUs failed"))
1566
+	clt, err := client.NewEnvClient()
1567
+	c.Assert(err, checker.IsNil)
1568
+	inspect, err := clt.ContainerInspect(context.Background(), "test")
1569
+	c.Assert(err, checker.IsNil)
1570
+	c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(500000000))
1571
+
1568 1572
 	out = inspectField(c, "test", "HostConfig.CpuQuota")
1569 1573
 	c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0"))
1570 1574
 	out = inspectField(c, "test", "HostConfig.CpuPeriod")
1571 1575
 	c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS period should be 0"))
1572 1576
 
1573
-	out, _, err := dockerCmdWithError("run", "--cpus", "0.5", "--cpu-quota", "50000", "--cpu-period", "100000", "busybox", "sh")
1577
+	out, _, err = dockerCmdWithError("run", "--cpus", "0.5", "--cpu-quota", "50000", "--cpu-period", "100000", "busybox", "sh")
1574 1578
 	c.Assert(err, check.NotNil)
1575 1579
 	c.Assert(out, checker.Contains, "Conflicting options: Nano CPUs and CPU Period cannot both be set")
1576 1580
 }
... ...
@@ -3,6 +3,7 @@
3 3
 package main
4 4
 
5 5
 import (
6
+	"context"
6 7
 	"encoding/json"
7 8
 	"fmt"
8 9
 	"os/exec"
... ...
@@ -10,6 +11,7 @@ import (
10 10
 	"time"
11 11
 
12 12
 	"github.com/docker/docker/api/types"
13
+	"github.com/docker/docker/client"
13 14
 	"github.com/docker/docker/integration-cli/checker"
14 15
 	"github.com/docker/docker/integration-cli/request"
15 16
 	"github.com/docker/docker/pkg/parsers/kernel"
... ...
@@ -295,20 +297,26 @@ func (s *DockerSuite) TestUpdateWithNanoCPUs(c *check.C) {
295 295
 	out, _ = dockerCmd(c, "exec", "top", "sh", "-c", fmt.Sprintf("cat %s && cat %s", file1, file2))
296 296
 	c.Assert(strings.TrimSpace(out), checker.Equals, "50000\n100000")
297 297
 
298
-	out = inspectField(c, "top", "HostConfig.NanoCpus")
299
-	c.Assert(out, checker.Equals, "5e+08", check.Commentf("setting the Nano CPUs failed"))
298
+	clt, err := client.NewEnvClient()
299
+	c.Assert(err, checker.IsNil)
300
+	inspect, err := clt.ContainerInspect(context.Background(), "top")
301
+	c.Assert(err, checker.IsNil)
302
+	c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(500000000))
303
+
300 304
 	out = inspectField(c, "top", "HostConfig.CpuQuota")
301 305
 	c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0"))
302 306
 	out = inspectField(c, "top", "HostConfig.CpuPeriod")
303 307
 	c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS period should be 0"))
304 308
 
305
-	out, _, err := dockerCmdWithError("update", "--cpu-quota", "80000", "top")
309
+	out, _, err = dockerCmdWithError("update", "--cpu-quota", "80000", "top")
306 310
 	c.Assert(err, checker.NotNil)
307 311
 	c.Assert(out, checker.Contains, "Conflicting options: CPU Quota cannot be updated as NanoCPUs has already been set")
308 312
 
309 313
 	out, _ = dockerCmd(c, "update", "--cpus", "0.8", "top")
310
-	out = inspectField(c, "top", "HostConfig.NanoCpus")
311
-	c.Assert(out, checker.Equals, "8e+08", check.Commentf("updating the Nano CPUs failed"))
314
+	inspect, err = clt.ContainerInspect(context.Background(), "top")
315
+	c.Assert(err, checker.IsNil)
316
+	c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(800000000))
317
+
312 318
 	out = inspectField(c, "top", "HostConfig.CpuQuota")
313 319
 	c.Assert(out, checker.Equals, "0", check.Commentf("CPU CFS quota should be 0"))
314 320
 	out = inspectField(c, "top", "HostConfig.CpuPeriod")