1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 f26a31e80c

`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>
This commit is contained in:
Sebastiaan van Stijn 2017-01-18 03:08:31 +01:00
parent 8820266c17
commit ba0afd70e8
13 changed files with 38 additions and 19 deletions

View file

@ -140,6 +140,8 @@ func (s *DockerSuite) TestBuildCancellationKillsSleep(c *check.C) {
buildCmd.Dir = ctx.Dir
stdoutBuild, err := buildCmd.StdoutPipe()
c.Assert(err, checker.IsNil)
if err := buildCmd.Start(); err != nil {
c.Fatalf("failed to run build: %s", err)
}

View file

@ -76,7 +76,7 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
imageID = strings.TrimSpace(imageID)
secondOutput, _ := dockerCmd(c, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
secondOutput, _ := dockerCmd(c, "run", "-t", imageID, "ls", "-di", "file1", "file2")
chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
inode = chunks[0]
@ -90,7 +90,7 @@ func (s *DockerSuite) TestCommitTTY(c *check.C) {
imageID, _ := dockerCmd(c, "commit", "tty", "ttytest")
imageID = strings.TrimSpace(imageID)
dockerCmd(c, "run", "ttytest", "/bin/ls")
dockerCmd(c, "run", imageID, "/bin/ls")
}
func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
@ -100,7 +100,7 @@ func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
imageID, _ := dockerCmd(c, "commit", "bind-commit", "bindtest")
imageID = strings.TrimSpace(imageID)
dockerCmd(c, "run", "bindtest", "true")
dockerCmd(c, "run", imageID, "true")
}
func (s *DockerSuite) TestCommitChange(c *check.C) {

View file

@ -442,6 +442,7 @@ func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
expected, err = readContainerFile(containerID, "hostname")
actual, err = ioutil.ReadFile(outDir + "/hostname")
c.Assert(err, checker.IsNil)
// Expected copied file to be duplicate of the container resolvconf
c.Assert(bytes.Equal(actual, expected), checker.True)
@ -534,6 +535,7 @@ func (s *DockerSuite) TestCpToDot(c *check.C) {
c.Assert(os.Chdir(tmpdir), checker.IsNil)
dockerCmd(c, "cp", containerID+":/test", ".")
content, err := ioutil.ReadFile("./test")
c.Assert(err, checker.IsNil)
c.Assert(string(content), checker.Equals, "lololol\n")
}
@ -572,6 +574,7 @@ func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
defer os.RemoveAll(tmpdir)
dockerCmd(c, "cp", containerID+":/te:s:t", tmpdir)
content, err := ioutil.ReadFile(tmpdir + "/te:s:t")
c.Assert(err, checker.IsNil)
c.Assert(string(content), checker.Equals, "lololol\n")
}
@ -653,6 +656,7 @@ func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *check.C) {
dockerCmd(c, "cp", "-L", cleanedContainerID+":"+"/dir_link", expectedPath)
actual, err = ioutil.ReadFile(expectedPath)
c.Assert(err, checker.IsNil)
if !bytes.Equal(actual, expected) {
c.Fatalf("Expected copied file to be duplicate of the container symbol link target")

View file

@ -57,7 +57,7 @@ func (s *DockerSuite) TestCpToErrSrcNotDir(c *check.C) {
}
// Test for error when SRC is a valid file or directory,
// bu the DST parent directory does not exist.
// but the DST parent directory does not exist.
func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
testRequires(c, DaemonIsLinux)
containerID := makeTestContainer(c, testContainerOptions{addContent: true})
@ -79,6 +79,7 @@ func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
// Try with a directory source.
srcPath = cpPath(tmpDir, "dir1")
err = runDockerCp(c, srcPath, dstPath)
c.Assert(err, checker.NotNil)
c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))

View file

@ -2566,7 +2566,14 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
containerName := "error-values"
// Make a container with both a non 0 exit code and an error message
out, err := s.d.Cmd("run", "--name", containerName, "busybox", "toto")
// We explicitly disable `--init` for this test, because `--init` is enabled by default
// on "experimental". Enabling `--init` results in a different behavior; because the "init"
// process itself is PID1, the container does not fail on _startup_ (i.e., `docker-init` starting),
// but directly after. The exit code of the container is still 127, but the Error Message is not
// captured, so `.State.Error` is empty.
// See the discussion on https://github.com/docker/docker/pull/30227#issuecomment-274161426,
// and https://github.com/docker/docker/pull/26061#r78054578 for more information.
out, err := s.d.Cmd("run", "--name", containerName, "--init=false", "busybox", "toto")
c.Assert(err, checker.NotNil)
// Check that those values were saved on disk
@ -2575,9 +2582,10 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Equals, "127")
out, err = s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName)
out = strings.TrimSpace(out)
errMsg1, err := s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName)
errMsg1 = strings.TrimSpace(errMsg1)
c.Assert(err, checker.IsNil)
c.Assert(errMsg1, checker.Contains, "executable file not found")
// now restart daemon
s.d.Restart(c)
@ -2591,6 +2599,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
out, err = s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName)
out = strings.TrimSpace(out)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Equals, errMsg1)
}
func (s *DockerDaemonSuite) TestDaemonBackcompatPre17Volumes(c *check.C) {

View file

@ -363,7 +363,7 @@ func (s *DockerSuite) TestExecInspectID(c *check.C) {
// result in a 404 (not 'container not running')
out, ec := dockerCmd(c, "rm", "-f", id)
c.Assert(ec, checker.Equals, 0, check.Commentf("error removing container: %s", out))
sc, body, err = request.SockRequest("GET", "/exec/"+execID+"/json", nil, daemonHost())
sc, body, _ = request.SockRequest("GET", "/exec/"+execID+"/json", nil, daemonHost())
c.Assert(sc, checker.Equals, http.StatusNotFound, check.Commentf("received status != 404: %d\n%s", sc, body))
}

View file

@ -295,7 +295,8 @@ func (s *DockerExternalVolumeSuite) TestVolumeCLICreateOptionConflict(c *check.C
// make sure hidden --name option conflicts with positional arg name
out, _, err = dockerCmdWithError("volume", "create", "--name", "test2", "test2")
c.Assert(err, check.NotNil, check.Commentf("Conflicting options: either specify --name or provide positional arg, not both"))
c.Assert(err, check.NotNil)
c.Assert(strings.TrimSpace(out), checker.Equals, "Conflicting options: either specify --name or provide positional arg, not both")
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *check.C) {

View file

@ -497,6 +497,7 @@ func (s *DockerSuite) TestDockerInspectMultipleNetwork(c *check.C) {
networkResources = []types.NetworkResource{}
err = json.Unmarshal([]byte(result.Stdout()), &networkResources)
c.Assert(err, check.IsNil)
c.Assert(networkResources, checker.HasLen, 1)
// Should print an error and return an exitCode, nothing else

View file

@ -459,12 +459,11 @@ func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *check.C) {
dockerCmd(c, "rmi", repoTag1)
dockerCmd(c, "rmi", repoTag2)
out, _, err := dockerCmdWithError("run", repo)
c.Assert(err, check.IsNil)
out, _ := dockerCmd(c, "run", repo)
c.Assert(out, checker.Contains, fmt.Sprintf("Unable to find image '%s:latest' locally", repo))
// There should be only one line for repo, the one with repo:latest
outImageCmd, _, err := dockerCmdWithError("images", repo)
outImageCmd, _ := dockerCmd(c, "images", repo)
splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
c.Assert(splitOutImageCmd, checker.HasLen, 2)
}

View file

@ -1296,11 +1296,11 @@ func (s *DockerSuite) TestRunDNSOptions(c *check.C) {
c.Fatalf("expected 'search mydomain nameserver 127.0.0.1 options ndots:9', but says: %q", actual)
}
out, stderr, _ = dockerCmdWithStdoutStderr(c, "run", "--dns=127.0.0.1", "--dns-search=.", "--dns-opt=ndots:3", "busybox", "cat", "/etc/resolv.conf")
out, _ = dockerCmd(c, "run", "--dns=1.1.1.1", "--dns-search=.", "--dns-opt=ndots:3", "busybox", "cat", "/etc/resolv.conf")
actual = strings.Replace(strings.Trim(strings.Trim(out, "\r\n"), " "), "\n", " ", -1)
if actual != "nameserver 127.0.0.1 options ndots:3" {
c.Fatalf("expected 'nameserver 127.0.0.1 options ndots:3', but says: %q", actual)
if actual != "nameserver 1.1.1.1 options ndots:3" {
c.Fatalf("expected 'nameserver 1.1.1.1 options ndots:3', but says: %q", actual)
}
}
@ -1376,7 +1376,6 @@ func (s *DockerSuite) TestRunDNSOptionsBasedOnHostResolvConf(c *check.C) {
c.Fatalf("/etc/resolv.conf does not exist")
}
hostNameservers = resolvconf.GetNameservers(resolvConf, types.IP)
hostSearch = resolvconf.GetSearchDomains(resolvConf)
out, _ = dockerCmd(c, "run", "busybox", "cat", "/etc/resolv.conf")

View file

@ -122,10 +122,10 @@ func (s *DockerSuite) TestSearchWithLimit(c *check.C) {
c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return
limit = 0
out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
_, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
c.Assert(err, checker.Not(checker.IsNil))
limit = 200
out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
_, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
c.Assert(err, checker.Not(checker.IsNil))
}

View file

@ -324,7 +324,7 @@ func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *check.C) {
_, err = d.Cmd("rm", "-f", cID)
c.Assert(err, checker.IsNil)
out, err = d.Cmd("network", "rm", "testnet")
_, err = d.Cmd("network", "rm", "testnet")
c.Assert(err, checker.IsNil)
checkNetwork := func(*check.C) (interface{}, check.CommentInterface) {

View file

@ -21,6 +21,9 @@ func TestFixedBufferWrite(t *testing.T) {
}
n, err = buf.Write(bytes.Repeat([]byte{1}, 64))
if n != 59 {
t.Fatalf("expected 59 bytes written before buffer is full, got %d", n)
}
if err != errBufferFull {
t.Fatalf("expected errBufferFull, got %v - %v", err, buf.buf[:64])
}