Browse code

fix some ineffectual assignments

to make goreportcard a bit happier
https://goreportcard.com/report/github.com/docker/docker

also found that `TestCpToErrDstParentNotExists()` was
partially broken, because a `runDockerCp()` was inadvertently
removed in f26a31e80cfcc77daba0872ddb14bf03f4398311

`TestDaemonRestartSaveContainerExitCode()` didn't verify
the actual _Error_ message, so added that to the test,
and updated the test to take into account that the
"experimental" CI enables `--init` on containers.

`TestVolumeCLICreateOptionConflict()` only checked
for an error to occur, but didn't validate if the
error was due to conflicting options.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2017/01/18 11:08:31
Showing 13 changed files
... ...
@@ -140,6 +140,8 @@ func (s *DockerSuite) TestBuildCancellationKillsSleep(c *check.C) {
140 140
 	buildCmd.Dir = ctx.Dir
141 141
 
142 142
 	stdoutBuild, err := buildCmd.StdoutPipe()
143
+	c.Assert(err, checker.IsNil)
144
+
143 145
 	if err := buildCmd.Start(); err != nil {
144 146
 		c.Fatalf("failed to run build: %s", err)
145 147
 	}
... ...
@@ -76,7 +76,7 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
76 76
 	imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
77 77
 	imageID = strings.TrimSpace(imageID)
78 78
 
79
-	secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
79
+	secondOutput, _ := dockerCmd(c, "run", "-t", imageID, "ls", "-di", "file1", "file2")
80 80
 
81 81
 	chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
82 82
 	inode = chunks[0]
... ...
@@ -90,7 +90,7 @@ func (s *DockerSuite) TestCommitTTY(c *check.C) {
90 90
 	imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
91 91
 	imageID = strings.TrimSpace(imageID)
92 92
 
93
-	dockerCmd(c, "run", "ttytest", "/bin/ls")
93
+	dockerCmd(c, "run", imageID, "/bin/ls")
94 94
 }
95 95
 
96 96
 func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
... ...
@@ -100,7 +100,7 @@ func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
100 100
 	imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest")
101 101
 	imageID = strings.TrimSpace(imageID)
102 102
 
103
-	dockerCmd(c, "run", "bindtest", "true")
103
+	dockerCmd(c, "run", imageID, "true")
104 104
 }
105 105
 
106 106
 func (s *DockerSuite) TestCommitChange(c *check.C) {
... ...
@@ -442,6 +442,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
442 442
 
443 443
 	expected, err = readContainerFile(containerID, "hostname")
444 444
 	actual, err = ioutil.ReadFile(outDir + "/hostname")
445
+	c.Assert(err, checker.IsNil)
445 446
 
446 447
 	// Expected copied file to be duplicate of the container resolvconf
447 448
 	c.Assert(bytes.Equal(actual, expected), checker.True)
... ...
@@ -534,6 +535,7 @@ func (s *DockerSuite) TestCpToDot(c *check.C) {
534 534
 	c.Assert(os.Chdir(tmpdir), checker.IsNil)
535 535
 	dockerCmd(c, "cp", containerID+":/test", ".")
536 536
 	content, err := ioutil.ReadFile("./test")
537
+	c.Assert(err, checker.IsNil)
537 538
 	c.Assert(string(content), checker.Equals, "lololol\n")
538 539
 }
539 540
 
... ...
@@ -572,6 +574,7 @@ func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
572 572
 	defer os.RemoveAll(tmpdir)
573 573
 	dockerCmd(c, "cp", containerID+":/te:s:t", tmpdir)
574 574
 	content, err := ioutil.ReadFile(tmpdir + "/te:s:t")
575
+	c.Assert(err, checker.IsNil)
575 576
 	c.Assert(string(content), checker.Equals, "lololol\n")
576 577
 }
577 578
 
... ...
@@ -653,6 +656,7 @@ func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *check.C) {
653 653
 	dockerCmd(c, "cp", "-L", cleanedContainerID+":"+"/dir_link", expectedPath)
654 654
 
655 655
 	actual, err = ioutil.ReadFile(expectedPath)
656
+	c.Assert(err, checker.IsNil)
656 657
 
657 658
 	if !bytes.Equal(actual, expected) {
658 659
 		c.Fatalf("Expected copied file to be duplicate of the container symbol link target")
... ...
@@ -57,7 +57,7 @@ func (s *DockerSuite) TestCpToErrSrcNotDir(c *check.C) {
57 57
 }
58 58
 
59 59
 // Test for error when SRC is a valid file or directory,
60
-// bu the DST parent directory does not exist.
60
+// but the DST parent directory does not exist.
61 61
 func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
62 62
 	testRequires(c, DaemonIsLinux)
63 63
 	containerID := makeTestContainer(c, testContainerOptions{addContent: true})
... ...
@@ -79,6 +79,7 @@ func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
79 79
 	// Try with a directory source.
80 80
 	srcPath = cpPath(tmpDir, "dir1")
81 81
 
82
+	err = runDockerCp(c, srcPath, dstPath)
82 83
 	c.Assert(err, checker.NotNil)
83 84
 
84 85
 	c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
... ...
@@ -2566,7 +2566,14 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
2566 2566
 
2567 2567
 	containerName := "error-values"
2568 2568
 	// Make a container with both a non 0 exit code and an error message
2569
-	out, err := s.d.Cmd("run", "--name", containerName, "busybox", "toto")
2569
+	// We explicitly disable `--init` for this test, because `--init` is enabled by default
2570
+	// on "experimental". Enabling `--init` results in a different behavior; because the "init"
2571
+	// process itself is PID1, the container does not fail on _startup_ (i.e., `docker-init` starting),
2572
+	// but directly after. The exit code of the container is still 127, but the Error Message is not
2573
+	// captured, so `.State.Error` is empty.
2574
+	// See the discussion on https://github.com/docker/docker/pull/30227#issuecomment-274161426,
2575
+	// and https://github.com/docker/docker/pull/26061#r78054578 for more information.
2576
+	out, err := s.d.Cmd("run", "--name", containerName, "--init=false", "busybox", "toto")
2570 2577
 	c.Assert(err, checker.NotNil)
2571 2578
 
2572 2579
 	// Check that those values were saved on disk
... ...
@@ -2575,9 +2582,10 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
2575 2575
 	c.Assert(err, checker.IsNil)
2576 2576
 	c.Assert(out, checker.Equals, "127")
2577 2577
 
2578
-	out, err = s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName)
2579
-	out = strings.TrimSpace(out)
2578
+	errMsg1, err := s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName)
2579
+	errMsg1 = strings.TrimSpace(errMsg1)
2580 2580
 	c.Assert(err, checker.IsNil)
2581
+	c.Assert(errMsg1, checker.Contains, "executable file not found")
2581 2582
 
2582 2583
 	// now restart daemon
2583 2584
 	s.d.Restart(c)
... ...
@@ -2591,6 +2599,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
2591 2591
 	out, err = s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName)
2592 2592
 	out = strings.TrimSpace(out)
2593 2593
 	c.Assert(err, checker.IsNil)
2594
+	c.Assert(out, checker.Equals, errMsg1)
2594 2595
 }
2595 2596
 
2596 2597
 func (s *DockerDaemonSuite) TestDaemonBackcompatPre17Volumes(c *check.C) {
... ...
@@ -363,7 +363,7 @@ func (s *DockerSuite) TestExecInspectID(c *check.C) {
363 363
 	// result in a 404 (not 'container not running')
364 364
 	out, ec := dockerCmd(c, "rm", "-f", id)
365 365
 	c.Assert(ec, checker.Equals, 0, check.Commentf("error removing container: %s", out))
366
-	sc, body, err = request.SockRequest("GET", "/exec/"+execID+"/json", nil, daemonHost())
366
+	sc, body, _ = request.SockRequest("GET", "/exec/"+execID+"/json", nil, daemonHost())
367 367
 	c.Assert(sc, checker.Equals, http.StatusNotFound, check.Commentf("received status != 404: %d\n%s", sc, body))
368 368
 }
369 369
 
... ...
@@ -295,7 +295,8 @@ func (s *DockerExternalVolumeSuite) TestVolumeCLICreateOptionConflict(c *check.C
295 295
 
296 296
 	// make sure hidden --name option conflicts with positional arg name
297 297
 	out, _, err = dockerCmdWithError("volume", "create", "--name", "test2", "test2")
298
-	c.Assert(err, check.NotNil, check.Commentf("Conflicting options: either specify --name or provide positional arg, not both"))
298
+	c.Assert(err, check.NotNil)
299
+	c.Assert(strings.TrimSpace(out), checker.Equals, "Conflicting options: either specify --name or provide positional arg, not both")
299 300
 }
300 301
 
301 302
 func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *check.C) {
... ...
@@ -497,6 +497,7 @@ func (s *DockerSuite) TestDockerInspectMultipleNetwork(c *check.C) {
497 497
 
498 498
 	networkResources = []types.NetworkResource{}
499 499
 	err = json.Unmarshal([]byte(result.Stdout()), &networkResources)
500
+	c.Assert(err, check.IsNil)
500 501
 	c.Assert(networkResources, checker.HasLen, 1)
501 502
 
502 503
 	// Should print an error and return an exitCode, nothing else
... ...
@@ -459,12 +459,11 @@ func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *check.C) {
459 459
 	dockerCmd(c, "rmi", repoTag1)
460 460
 	dockerCmd(c, "rmi", repoTag2)
461 461
 
462
-	out, _, err := dockerCmdWithError("run", repo)
463
-	c.Assert(err, check.IsNil)
462
+	out, _ := dockerCmd(c, "run", repo)
464 463
 	c.Assert(out, checker.Contains, fmt.Sprintf("Unable to find image '%s:latest' locally", repo))
465 464
 
466 465
 	// There should be only one line for repo, the one with repo:latest
467
-	outImageCmd, _, err := dockerCmdWithError("images", repo)
466
+	outImageCmd, _ := dockerCmd(c, "images", repo)
468 467
 	splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
469 468
 	c.Assert(splitOutImageCmd, checker.HasLen, 2)
470 469
 }
... ...
@@ -1296,11 +1296,11 @@ func (s *DockerSuite) TestRunDNSOptions(c *check.C) {
1296 1296
 		c.Fatalf("expected 'search mydomain nameserver 127.0.0.1 options ndots:9', but says: %q", actual)
1297 1297
 	}
1298 1298
 
1299
-	out, stderr, _ = dockerCmdWithStdoutStderr(c, "run", "--dns=127.0.0.1", "--dns-search=.", "--dns-opt=ndots:3", "busybox", "cat", "/etc/resolv.conf")
1299
+	out, _ = dockerCmd(c, "run", "--dns=1.1.1.1", "--dns-search=.", "--dns-opt=ndots:3", "busybox", "cat", "/etc/resolv.conf")
1300 1300
 
1301 1301
 	actual = strings.Replace(strings.Trim(strings.Trim(out, "\r\n"), " "), "\n", " ", -1)
1302
-	if actual != "nameserver 127.0.0.1 options ndots:3" {
1303
-		c.Fatalf("expected 'nameserver 127.0.0.1 options ndots:3', but says: %q", actual)
1302
+	if actual != "nameserver 1.1.1.1 options ndots:3" {
1303
+		c.Fatalf("expected 'nameserver 1.1.1.1 options ndots:3', but says: %q", actual)
1304 1304
 	}
1305 1305
 }
1306 1306
 
... ...
@@ -1376,7 +1376,6 @@ func (s *DockerSuite) TestRunDNSOptionsBasedOnHostResolvConf(c *check.C) {
1376 1376
 		c.Fatalf("/etc/resolv.conf does not exist")
1377 1377
 	}
1378 1378
 
1379
-	hostNameservers = resolvconf.GetNameservers(resolvConf, types.IP)
1380 1379
 	hostSearch = resolvconf.GetSearchDomains(resolvConf)
1381 1380
 
1382 1381
 	out, _ = dockerCmd(c, "run", "busybox", "cat", "/etc/resolv.conf")
... ...
@@ -122,10 +122,10 @@ func (s *DockerSuite) TestSearchWithLimit(c *check.C) {
122 122
 	c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return
123 123
 
124 124
 	limit = 0
125
-	out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
125
+	_, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
126 126
 	c.Assert(err, checker.Not(checker.IsNil))
127 127
 
128 128
 	limit = 200
129
-	out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
129
+	_, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
130 130
 	c.Assert(err, checker.Not(checker.IsNil))
131 131
 }
... ...
@@ -324,7 +324,7 @@ func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *check.C) {
324 324
 	_, err = d.Cmd("rm", "-f", cID)
325 325
 	c.Assert(err, checker.IsNil)
326 326
 
327
-	out, err = d.Cmd("network", "rm", "testnet")
327
+	_, err = d.Cmd("network", "rm", "testnet")
328 328
 	c.Assert(err, checker.IsNil)
329 329
 
330 330
 	checkNetwork := func(*check.C) (interface{}, check.CommentInterface) {
... ...
@@ -21,6 +21,9 @@ func TestFixedBufferWrite(t *testing.T) {
21 21
 	}
22 22
 
23 23
 	n, err = buf.Write(bytes.Repeat([]byte{1}, 64))
24
+	if n != 59 {
25
+		t.Fatalf("expected 59 bytes written before buffer is full, got %d", n)
26
+	}
24 27
 	if err != errBufferFull {
25 28
 		t.Fatalf("expected errBufferFull, got %v - %v", err, buf.buf[:64])
26 29
 	}