rm-gocheck: convert check.Commentf to string - with multiple args

sed -E -i 's#\bcheck.Commentf\(([^,]+),(.*)\)#fmt.Sprintf(\1,\2)#g' \
-- "integration-cli/daemon/daemon.go" "integration-cli/daemon/daemon_swarm.go" "integration-cli/docker_api_containers_test.go" "integration-cli/docker_api_exec_test.go" "integration-cli/docker_api_swarm_node_test.go" "integration-cli/docker_api_swarm_test.go" "integration-cli/docker_cli_attach_unix_test.go" "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_by_digest_test.go" "integration-cli/docker_cli_commit_test.go" "integration-cli/docker_cli_cp_from_container_test.go" "integration-cli/docker_cli_cp_to_container_test.go" "integration-cli/docker_cli_create_test.go" "integration-cli/docker_cli_daemon_test.go" "integration-cli/docker_cli_external_volume_driver_unix_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_images_test.go" "integration-cli/docker_cli_info_test.go" "integration-cli/docker_cli_inspect_test.go" "integration-cli/docker_cli_links_test.go" "integration-cli/docker_cli_netmode_test.go" "integration-cli/docker_cli_network_unix_test.go" "integration-cli/docker_cli_plugins_test.go" "integration-cli/docker_cli_port_test.go" "integration-cli/docker_cli_ps_test.go" "integration-cli/docker_cli_pull_local_test.go" "integration-cli/docker_cli_rmi_test.go" "integration-cli/docker_cli_run_test.go" "integration-cli/docker_cli_run_unix_test.go" "integration-cli/docker_cli_save_load_test.go" "integration-cli/docker_cli_service_create_test.go" "integration-cli/docker_cli_service_logs_test.go" "integration-cli/docker_cli_start_test.go" "integration-cli/docker_cli_swarm_test.go" "integration-cli/docker_cli_userns_test.go" "integration-cli/docker_cli_volume_test.go" "integration-cli/docker_hub_pull_suite_test.go" "integration-cli/docker_utils_test.go"

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2019-09-09 21:08:22 +00:00
parent 98f2638fe5
commit a2024a5470
38 changed files with 317 additions and 317 deletions

View File

@ -95,7 +95,7 @@ func (d *Daemon) CheckActiveContainerCount(c *testing.T) (interface{}, check.Com
if len(strings.TrimSpace(out)) == 0 {
return 0, nil
}
return len(strings.Split(strings.TrimSpace(out), "\n")), check.Commentf("output: %q", string(out))
return len(strings.Split(strings.TrimSpace(out), "\n")), fmt.Sprintf("output: %q", string(out))
}
// WaitRun waits for a container to be running for 10s

View File

@ -70,10 +70,10 @@ func (d *Daemon) CheckPluginRunning(plugin string) func(c *testing.T) (interface
apiclient := d.NewClientT(c)
resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin)
if client.IsErrNotFound(err) {
return false, check.Commentf("%v", err)
return false, fmt.Sprintf("%v", err)
}
assert.NilError(c, err)
return resp.Enabled, check.Commentf("%+v", resp)
return resp.Enabled, fmt.Sprintf("%+v", resp)
}
}
@ -83,10 +83,10 @@ func (d *Daemon) CheckPluginImage(plugin string) func(c *testing.T) (interface{}
apiclient := d.NewClientT(c)
resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin)
if client.IsErrNotFound(err) {
return false, check.Commentf("%v", err)
return false, fmt.Sprintf("%v", err)
}
assert.NilError(c, err)
return resp.PluginReference, check.Commentf("%+v", resp)
return resp.PluginReference, fmt.Sprintf("%+v", resp)
}
}

View File

@ -405,12 +405,12 @@ func (s *DockerSuite) TestContainerAPITop(c *testing.T) {
// sort by comm[andline] to make sure order stays the same in case of PID rollover
top, err := cli.ContainerTop(context.Background(), id, []string{"aux", "--sort=comm"})
assert.NilError(c, err)
assert.Equal(c, len(top.Titles), 11, check.Commentf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles))
assert.Equal(c, len(top.Titles), 11, fmt.Sprintf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles))
if top.Titles[0] != "USER" || top.Titles[10] != "COMMAND" {
c.Fatalf("expected `USER` at `Titles[0]` and `COMMAND` at Titles[10]: %v", top.Titles)
}
assert.Equal(c, len(top.Processes), 2, check.Commentf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
assert.Equal(c, len(top.Processes), 2, fmt.Sprintf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
assert.Equal(c, top.Processes[0][10], "/bin/sh -c top")
assert.Equal(c, top.Processes[1][10], "top")
}
@ -462,7 +462,7 @@ func (s *DockerSuite) TestContainerAPICommit(c *testing.T) {
assert.NilError(c, err)
cmd := inspectField(c, img.ID, "Config.Cmd")
assert.Equal(c, cmd, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd))
assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd))
// sanity check, make sure the image is what we think it is
dockerCmd(c, "run", img.ID, "ls", "/test")
@ -494,7 +494,7 @@ func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
assert.Equal(c, label2, "value2")
cmd := inspectField(c, img.ID, "Config.Cmd")
assert.Equal(c, cmd, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd))
assert.Equal(c, cmd, "[/bin/sh -c touch /test]", fmt.Sprintf("got wrong Cmd from commit: %q", cmd))
// sanity check, make sure the image is what we think it is
dockerCmd(c, "run", img.ID, "ls", "/test")
@ -903,7 +903,7 @@ func (s *DockerSuite) TestContainerAPIKill(c *testing.T) {
assert.NilError(c, err)
state := inspectField(c, name, "State.Running")
assert.Equal(c, state, "false", check.Commentf("got wrong State from container %s: %q", name, state))
assert.Equal(c, state, "false", fmt.Sprintf("got wrong State from container %s: %q", name, state))
}
func (s *DockerSuite) TestContainerAPIRestart(c *testing.T) {
@ -1231,7 +1231,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) {
assert.NilError(c, err)
_, err = os.Stat(source)
assert.Assert(c, os.IsNotExist(err), check.Commentf("expected to get ErrNotExist error, got %v", err))
assert.Assert(c, os.IsNotExist(err), fmt.Sprintf("expected to get ErrNotExist error, got %v", err))
}
// Regression test for https://github.com/docker/docker/issues/6231

View File

@ -124,7 +124,7 @@ func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *testing.T) {
assert.NilError(c, err)
b, err := request.ReadBody(body)
comment := check.Commentf("response body: %s", b)
comment := fmt.Sprintf("response body: %s", b)
assert.NilError(c, err, comment)
assert.Equal(c, resp.StatusCode, http.StatusOK, comment)
}
@ -160,7 +160,7 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *testing.T) {
assert.NilError(c, err)
b, err := request.ReadBody(body)
comment := check.Commentf("response body: %s", b)
comment := fmt.Sprintf("response body: %s", b)
assert.NilError(c, err, comment)
resp, _, err := request.Get("/_ping")

View File

@ -19,7 +19,7 @@ func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *testing.T) {
d3 := s.AddDaemon(c, true, false)
nodes := d1.ListNodes(c)
assert.Equal(c, len(nodes), 3, check.Commentf("nodes: %#v", nodes))
assert.Equal(c, len(nodes), 3, fmt.Sprintf("nodes: %#v", nodes))
loop0:
for _, n := range nodes {
@ -52,7 +52,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *testing.T) {
_ = s.AddDaemon(c, true, false)
nodes := d1.ListNodes(c)
assert.Equal(c, len(nodes), 3, check.Commentf("nodes: %#v", nodes))
assert.Equal(c, len(nodes), 3, fmt.Sprintf("nodes: %#v", nodes))
// Getting the info so we can take the NodeID
d2Info := d2.SwarmInfo(c)
@ -61,7 +61,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *testing.T) {
d1.RemoveNode(c, d2Info.NodeID, true)
nodes = d1.ListNodes(c)
assert.Equal(c, len(nodes), 2, check.Commentf("nodes: %#v", nodes))
assert.Equal(c, len(nodes), 2, fmt.Sprintf("nodes: %#v", nodes))
// Restart the node that was removed
d2.RestartNode(c)
@ -71,7 +71,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *testing.T) {
// Make sure the node didn't rejoin
nodes = d1.ListNodes(c)
assert.Equal(c, len(nodes), 2, check.Commentf("nodes: %#v", nodes))
assert.Equal(c, len(nodes), 2, fmt.Sprintf("nodes: %#v", nodes))
}
func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *testing.T) {

View File

@ -226,7 +226,7 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) {
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
certBytes, err := ioutil.ReadFile(filepath.Join(d2.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
if err != nil {
return "", check.Commentf("error: %v", err)
return "", fmt.Sprintf("error: %v", err)
}
certs, err := helpers.ParseCertificatesPEM(certBytes)
if err == nil && len(certs) > 0 && len(certs[0].Subject.OrganizationalUnit) > 0 {
@ -330,7 +330,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
return false
})
if n == nil {
return false, check.Commentf("failed to get node: %v", lastErr)
return false, fmt.Sprintf("failed to get node: %v", lastErr)
}
if n.ManagerStatus.Leader {
leader = d
@ -343,7 +343,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
return false, check.Commentf("no leader elected")
}
return true, check.Commentf("elected %v", leader.ID())
return true, fmt.Sprintf("elected %v", leader.ID())
}
}
@ -761,7 +761,7 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC
}
nn := d.GetNode(c, n.ID)
n = *nn
return n.Status.State == swarm.NodeStateReady, check.Commentf("state of node %s, reported by %s", n.ID, d.NodeID())
return n.Status.State == swarm.NodeStateReady, fmt.Sprintf("state of node %s, reported by %s", n.ID, d.NodeID())
}
waitAndAssert(c, defaultReconciliationTimeout, waitReady, checker.True)
@ -771,7 +771,7 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC
}
nn := d.GetNode(c, n.ID)
n = *nn
return n.Spec.Availability == swarm.NodeAvailabilityActive, check.Commentf("availability of node %s, reported by %s", n.ID, d.NodeID())
return n.Spec.Availability == swarm.NodeAvailabilityActive, fmt.Sprintf("availability of node %s, reported by %s", n.ID, d.NodeID())
}
waitAndAssert(c, defaultReconciliationTimeout, waitActive, checker.True)

View File

@ -52,7 +52,7 @@ func (s *DockerSuite) TestAttachClosedOnContainerStop(c *testing.T) {
case err := <-errChan:
tty.Close()
out, _ := ioutil.ReadAll(pty)
assert.Assert(c, err == nil, check.Commentf("out: %v", string(out)))
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", string(out)))
case <-time.After(attachWait):
c.Fatal("timed out without attach returning")
}

View File

@ -4739,7 +4739,7 @@ func (s *DockerSuite) TestBuildTagEvent(c *testing.T) {
}
}
assert.Assert(c, foundTag, check.Commentf("No tag event found:\n%s", out))
assert.Assert(c, foundTag, fmt.Sprintf("No tag event found:\n%s", out))
}
// #15780

View File

@ -151,8 +151,8 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *testing.T) {
foundRegex := regexp.MustCompile("found=([^\n]+)")
matches := foundRegex.FindStringSubmatch(out)
assert.Equal(c, len(matches), 2, check.Commentf("unable to parse digest from pull output: %s", out))
assert.Equal(c, matches[1], "1", check.Commentf("Expected %q, got %q", "1", matches[1]))
assert.Equal(c, len(matches), 2, fmt.Sprintf("unable to parse digest from pull output: %s", out))
assert.Equal(c, matches[1], "1", fmt.Sprintf("Expected %q, got %q", "1", matches[1]))
res := inspectField(c, containerName, "Config.Image")
assert.Equal(c, res, imageReference)
@ -253,7 +253,7 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
// make sure repo shown, tag=<none>, digest = $digest1
re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`)
assert.Assert(c, re1.MatchString(out), check.Commentf("expected %q: %s", re1.String(), out))
assert.Assert(c, re1.MatchString(out), fmt.Sprintf("expected %q: %s", re1.String(), out))
// setup image2
digest2, err := setupImageWithTag(c, "tag2")
//error setting up image
@ -271,11 +271,11 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
out, _ = dockerCmd(c, "images", "--digests")
// make sure repo shown, tag=<none>, digest = $digest1
assert.Assert(c, re1.MatchString(out), check.Commentf("expected %q: %s", re1.String(), out))
assert.Assert(c, re1.MatchString(out), fmt.Sprintf("expected %q: %s", re1.String(), out))
// make sure repo shown, tag=<none>, digest = $digest2
re2 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest2.String() + `\s`)
assert.Assert(c, re2.MatchString(out), check.Commentf("expected %q: %s", re2.String(), out))
assert.Assert(c, re2.MatchString(out), fmt.Sprintf("expected %q: %s", re2.String(), out))
// pull tag1
dockerCmd(c, "pull", repoName+":tag1")
@ -285,9 +285,9 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*` + digest1.String() + `\s`)
assert.Assert(c, reWithDigest1.MatchString(out), check.Commentf("expected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, <none>, digest
assert.Assert(c, re2.MatchString(out), check.Commentf("expected %q: %s", re2.String(), out))
assert.Assert(c, re2.MatchString(out), fmt.Sprintf("expected %q: %s", re2.String(), out))
// pull tag 2
dockerCmd(c, "pull", repoName+":tag2")
@ -296,22 +296,22 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) {
out, _ = dockerCmd(c, "images", "--digests")
// make sure image 1 has repo, tag, digest
assert.Assert(c, reWithDigest1.MatchString(out), check.Commentf("expected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, tag, digest
reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*tag2\s*` + digest2.String() + `\s`)
assert.Assert(c, reWithDigest2.MatchString(out), check.Commentf("expected %q: %s", reWithDigest2.String(), out))
assert.Assert(c, reWithDigest2.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest2.String(), out))
// list images
out, _ = dockerCmd(c, "images", "--digests")
// make sure image 1 has repo, tag, digest
assert.Assert(c, reWithDigest1.MatchString(out), check.Commentf("expected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, tag, digest
assert.Assert(c, reWithDigest2.MatchString(out), check.Commentf("expected %q: %s", reWithDigest2.String(), out))
assert.Assert(c, reWithDigest2.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest2.String(), out))
// make sure busybox has tag, but not digest
busyboxRe := regexp.MustCompile(`\s*busybox\s*latest\s*<none>\s`)
assert.Assert(c, busyboxRe.MatchString(out), check.Commentf("expected %q: %s", busyboxRe.String(), out))
assert.Assert(c, busyboxRe.MatchString(out), fmt.Sprintf("expected %q: %s", busyboxRe.String(), out))
}
func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
@ -329,7 +329,7 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
// make sure repo shown, tag=<none>, digest = $digest1
re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`)
assert.Assert(c, re1.MatchString(out), check.Commentf("expected %q: %s", re1.String(), out))
assert.Assert(c, re1.MatchString(out), fmt.Sprintf("expected %q: %s", re1.String(), out))
// setup image2
digest2, err := setupImageWithTag(c, "dangle2")
//error setting up image
@ -347,11 +347,11 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true")
// make sure repo shown, tag=<none>, digest = $digest1
assert.Assert(c, re1.MatchString(out), check.Commentf("expected %q: %s", re1.String(), out))
assert.Assert(c, re1.MatchString(out), fmt.Sprintf("expected %q: %s", re1.String(), out))
// make sure repo shown, tag=<none>, digest = $digest2
re2 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest2.String() + `\s`)
assert.Assert(c, re2.MatchString(out), check.Commentf("expected %q: %s", re2.String(), out))
assert.Assert(c, re2.MatchString(out), fmt.Sprintf("expected %q: %s", re2.String(), out))
// pull dangle1 tag
dockerCmd(c, "pull", repoName+":dangle1")
@ -361,9 +361,9 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*dangle1\s*` + digest1.String() + `\s`)
assert.Assert(c, !reWithDigest1.MatchString(out), check.Commentf("unexpected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, !reWithDigest1.MatchString(out), fmt.Sprintf("unexpected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, <none>, digest
assert.Assert(c, re2.MatchString(out), check.Commentf("expected %q: %s", re2.String(), out))
assert.Assert(c, re2.MatchString(out), fmt.Sprintf("expected %q: %s", re2.String(), out))
// pull dangle2 tag
dockerCmd(c, "pull", repoName+":dangle2")
@ -372,19 +372,19 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) {
out, _ = dockerCmd(c, "images", "--digests")
// make sure image 1 has repo, tag, digest
assert.Assert(c, reWithDigest1.MatchString(out), check.Commentf("expected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, tag, digest
reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*dangle2\s*` + digest2.String() + `\s`)
assert.Assert(c, reWithDigest2.MatchString(out), check.Commentf("expected %q: %s", reWithDigest2.String(), out))
assert.Assert(c, reWithDigest2.MatchString(out), fmt.Sprintf("expected %q: %s", reWithDigest2.String(), out))
// list images, no longer dangling, should not match
out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true")
// make sure image 1 has repo, tag, digest
assert.Assert(c, !reWithDigest1.MatchString(out), check.Commentf("unexpected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, !reWithDigest1.MatchString(out), fmt.Sprintf("unexpected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, tag, digest
assert.Assert(c, !reWithDigest2.MatchString(out), check.Commentf("unexpected %q: %s", reWithDigest2.String(), out))
assert.Assert(c, !reWithDigest2.MatchString(out), fmt.Sprintf("unexpected %q: %s", reWithDigest2.String(), out))
}
func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *testing.T) {
@ -644,7 +644,7 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *testing.T) {
assert.Assert(c, exitStatus != 0, check.Commentf("expected a non-zero exit status"))
expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest)
assert.Assert(c, strings.Contains(out, expectedErrorMsg), check.Commentf("expected error message in output: %s", out))
assert.Assert(c, strings.Contains(out, expectedErrorMsg), fmt.Sprintf("expected error message in output: %s", out))
}
// TestPullFailsWithAlteredLayer tests that a `docker pull` fails when
@ -687,5 +687,5 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *testing.T)
assert.Assert(c, exitStatus != 0, check.Commentf("expected a non-zero exit status"))
expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest)
assert.Assert(c, strings.Contains(out, expectedErrorMsg), check.Commentf("expected error message in output: %s", out))
assert.Assert(c, strings.Contains(out, expectedErrorMsg), fmt.Sprintf("expected error message in output: %s", out))
}

View File

@ -72,7 +72,7 @@ func (s *DockerSuite) TestCommitHardlink(c *testing.T) {
chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
inode := chunks[0]
chunks = strings.SplitAfterN(strings.TrimSpace(firstOutput), " ", 2)
assert.Assert(c, strings.Contains(chunks[1], chunks[0]), check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
assert.Assert(c, strings.Contains(chunks[1], chunks[0]), fmt.Sprintf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
imageID, _ := dockerCmd(c, "commit", "hardlinks", "hardlinks")
imageID = strings.TrimSpace(imageID)
@ -81,7 +81,7 @@ func (s *DockerSuite) TestCommitHardlink(c *testing.T) {
chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
inode = chunks[0]
chunks = strings.SplitAfterN(strings.TrimSpace(secondOutput), " ", 2)
assert.Assert(c, strings.Contains(chunks[1], chunks[0]), check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
assert.Assert(c, strings.Contains(chunks[1], chunks[0]), fmt.Sprintf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
}
func (s *DockerSuite) TestCommitTTY(c *testing.T) {

View File

@ -150,7 +150,7 @@ func (s *DockerSuite) TestCpFromCaseB(c *testing.T) {
err := runDockerCp(c, srcPath, dstDir, nil)
assert.ErrorContains(c, err, "")
assert.Assert(c, isCpDirNotExist(err), check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
assert.Assert(c, isCpDirNotExist(err), fmt.Sprintf("expected DirNotExists error, but got %T: %s", err, err))
}
// C. SRC specifies a file and DST exists as a file. This should overwrite
@ -195,7 +195,7 @@ func (s *DockerSuite) TestCpFromCaseD(c *testing.T) {
// Ensure that dstPath doesn't exist.
_, err := os.Stat(dstPath)
assert.Assert(c, os.IsNotExist(err), check.Commentf("did not expect dstPath %q to exist", dstPath))
assert.Assert(c, os.IsNotExist(err), fmt.Sprintf("did not expect dstPath %q to exist", dstPath))
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil) == nil)
@ -266,7 +266,7 @@ func (s *DockerSuite) TestCpFromCaseF(c *testing.T) {
err := runDockerCp(c, srcDir, dstFile, nil)
assert.ErrorContains(c, err, "")
assert.Assert(c, isCpCannotCopyDir(err), check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyDir(err), fmt.Sprintf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
}
// G. SRC specifies a directory and DST exists as a directory. This should copy
@ -358,7 +358,7 @@ func (s *DockerSuite) TestCpFromCaseI(c *testing.T) {
err := runDockerCp(c, srcDir, dstFile, nil)
assert.ErrorContains(c, err, "")
assert.Assert(c, isCpCannotCopyDir(err), check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyDir(err), fmt.Sprintf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
}
// J. SRC specifies a directory's contents only and DST exists as a directory.

View File

@ -158,7 +158,7 @@ func (s *DockerSuite) TestCpToCaseB(c *testing.T) {
err := runDockerCp(c, srcPath, dstDir, nil)
assert.ErrorContains(c, err, "")
assert.Assert(c, isCpDirNotExist(err), check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
assert.Assert(c, isCpDirNotExist(err), fmt.Sprintf("expected DirNotExists error, but got %T: %s", err, err))
}
// C. SRC specifies a file and DST exists as a file. This should overwrite
@ -288,7 +288,7 @@ func (s *DockerSuite) TestCpToCaseF(c *testing.T) {
err := runDockerCp(c, srcDir, dstFile, nil)
assert.ErrorContains(c, err, "")
assert.Assert(c, isCpCannotCopyDir(err), check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyDir(err), fmt.Sprintf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
}
// G. SRC specifies a directory and DST exists as a directory. This should copy
@ -393,7 +393,7 @@ func (s *DockerSuite) TestCpToCaseI(c *testing.T) {
err := runDockerCp(c, srcDir, dstFile, nil)
assert.ErrorContains(c, err, "")
assert.Assert(c, isCpCannotCopyDir(err), check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyDir(err), fmt.Sprintf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
}
// J. SRC specifies a directory's contents only and DST exists as a directory.
@ -462,7 +462,7 @@ func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *testing.T) {
err := runDockerCp(c, srcPath, dstPath, nil)
assert.ErrorContains(c, err, "")
assert.Assert(c, isCpCannotCopyReadOnly(err), check.Commentf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyReadOnly(err), fmt.Sprintf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err))
// Ensure that dstPath doesn't exist.
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)
@ -489,7 +489,7 @@ func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *testing.T) {
err := runDockerCp(c, srcPath, dstPath, nil)
assert.ErrorContains(c, err, "")
assert.Assert(c, isCpCannotCopyReadOnly(err), check.Commentf("expected ErrVolumeReadonly error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyReadOnly(err), fmt.Sprintf("expected ErrVolumeReadonly error, but got %T: %s", err, err))
// Ensure that dstPath doesn't exist.
assert.Assert(c, containerStartOutputEquals(c, containerID, "") == nil)

View File

@ -37,11 +37,11 @@ func (s *DockerSuite) TestCreateArgs(c *testing.T) {
}
err := json.Unmarshal([]byte(out), &containers)
assert.Assert(c, err == nil, check.Commentf("Error inspecting the container: %s", err))
assert.Assert(c, err == nil, fmt.Sprintf("Error inspecting the container: %s", err))
assert.Equal(c, len(containers), 1)
cont := containers[0]
assert.Equal(c, string(cont.Path), "command", check.Commentf("Unexpected container path. Expected command, received: %s", cont.Path))
assert.Equal(c, string(cont.Path), "command", fmt.Sprintf("Unexpected container path. Expected command, received: %s", cont.Path))
b := false
expected := []string{"arg1", "arg2", "arg with space", "-c", "flags"}
@ -96,12 +96,12 @@ func (s *DockerSuite) TestCreateHostConfig(c *testing.T) {
}
err := json.Unmarshal([]byte(out), &containers)
assert.Assert(c, err == nil, check.Commentf("Error inspecting the container: %s", err))
assert.Assert(c, err == nil, fmt.Sprintf("Error inspecting the container: %s", err))
assert.Equal(c, len(containers), 1)
cont := containers[0]
assert.Assert(c, cont.HostConfig != nil, check.Commentf("Expected HostConfig, got none"))
assert.Assert(c, cont.HostConfig.PublishAllPorts, check.Commentf("Expected PublishAllPorts, got false"))
assert.Assert(c, cont.HostConfig != nil, fmt.Sprintf("Expected HostConfig, got none"))
assert.Assert(c, cont.HostConfig.PublishAllPorts, fmt.Sprintf("Expected PublishAllPorts, got false"))
}
func (s *DockerSuite) TestCreateWithPortRange(c *testing.T) {
@ -117,17 +117,17 @@ func (s *DockerSuite) TestCreateWithPortRange(c *testing.T) {
}
}
err := json.Unmarshal([]byte(out), &containers)
assert.Assert(c, err == nil, check.Commentf("Error inspecting the container: %s", err))
assert.Assert(c, err == nil, fmt.Sprintf("Error inspecting the container: %s", err))
assert.Equal(c, len(containers), 1)
cont := containers[0]
assert.Assert(c, cont.HostConfig != nil, check.Commentf("Expected HostConfig, got none"))
assert.Equal(c, len(cont.HostConfig.PortBindings), 4, check.Commentf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
assert.Assert(c, cont.HostConfig != nil, fmt.Sprintf("Expected HostConfig, got none"))
assert.Equal(c, len(cont.HostConfig.PortBindings), 4, fmt.Sprintf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
for k, v := range cont.HostConfig.PortBindings {
assert.Equal(c, len(v), 1, check.Commentf("Expected 1 ports binding, for the port %s but found %s", k, v))
assert.Equal(c, k.Port(), v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
assert.Equal(c, len(v), 1, fmt.Sprintf("Expected 1 ports binding, for the port %s but found %s", k, v))
assert.Equal(c, k.Port(), v[0].HostPort, fmt.Sprintf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
}
@ -147,16 +147,16 @@ func (s *DockerSuite) TestCreateWithLargePortRange(c *testing.T) {
}
err := json.Unmarshal([]byte(out), &containers)
assert.Assert(c, err == nil, check.Commentf("Error inspecting the container: %s", err))
assert.Assert(c, err == nil, fmt.Sprintf("Error inspecting the container: %s", err))
assert.Equal(c, len(containers), 1)
cont := containers[0]
assert.Assert(c, cont.HostConfig != nil, check.Commentf("Expected HostConfig, got none"))
assert.Assert(c, cont.HostConfig != nil, fmt.Sprintf("Expected HostConfig, got none"))
assert.Equal(c, len(cont.HostConfig.PortBindings), 65535)
for k, v := range cont.HostConfig.PortBindings {
assert.Equal(c, len(v), 1)
assert.Equal(c, k.Port(), v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
assert.Equal(c, k.Port(), v[0].HostPort, fmt.Sprintf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
}
}
@ -179,7 +179,7 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *testing.T) {
dockerCmd(c, "create", "--name", name, "-v", prefix+slash+"foo", "busybox")
dir, err := inspectMountSourceField(name, prefix+slash+"foo")
assert.Assert(c, err == nil, check.Commentf("Error getting volume host path: %q", err))
assert.Assert(c, err == nil, fmt.Sprintf("Error getting volume host path: %q", err))
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
c.Fatalf("Volume was not created")

View File

@ -131,13 +131,13 @@ func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *testing.T) {
var format string
for name, shouldRun := range m {
out, err := s.d.Cmd("ps")
assert.Assert(c, err == nil, check.Commentf("run ps: %v", out))
assert.Assert(c, err == nil, fmt.Sprintf("run ps: %v", out))
if shouldRun {
format = "%scontainer %q is not running"
} else {
format = "%scontainer %q is running"
}
assert.Equal(c, strings.Contains(out, name), shouldRun, check.Commentf(format, prefix, name))
assert.Equal(c, strings.Contains(out, name), shouldRun, fmt.Sprintf(format, prefix, name))
}
}
@ -217,7 +217,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithInvalidBasesize(c *testing.T) {
if newBasesizeBytes < oldBasesizeBytes {
err := s.d.RestartWithError("--storage-opt", fmt.Sprintf("dm.basesize=%d", newBasesizeBytes))
assert.Assert(c, err != nil, check.Commentf("daemon should not have started as new base device size is less than existing base device size: %v", err))
assert.Assert(c, err != nil, fmt.Sprintf("daemon should not have started as new base device size is less than existing base device size: %v", err))
// 'err != nil' is expected behaviour, no new daemon started,
// so no need to stop daemon.
if err != nil {
@ -241,11 +241,11 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithIncreasedBasesize(c *testing.T)
}
err := s.d.RestartWithError("--storage-opt", fmt.Sprintf("dm.basesize=%d", newBasesizeBytes))
assert.Assert(c, err == nil, check.Commentf("we should have been able to start the daemon with increased base device size: %v", err))
assert.Assert(c, err == nil, fmt.Sprintf("we should have been able to start the daemon with increased base device size: %v", err))
basesizeAfterRestart := getBaseDeviceSize(c, s.d)
newBasesize, err := convertBasesize(newBasesizeBytes)
assert.Assert(c, err == nil, check.Commentf("Error in converting base device size: %v", err))
assert.Assert(c, err == nil, fmt.Sprintf("Error in converting base device size: %v", err))
assert.Equal(c, newBasesize, basesizeAfterRestart, check.Commentf("Basesize passed is not equal to Basesize set"))
s.d.Stop(c)
}
@ -680,7 +680,7 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *testing.T) {
containerIP := d.FindContainerIP(c, "test")
ip = net.ParseIP(containerIP)
assert.Equal(c, bridgeIPNet.Contains(ip), true, check.Commentf("Container IP-Address must be in the same subnet range : %s", containerIP))
assert.Equal(c, bridgeIPNet.Contains(ip), true, fmt.Sprintf("Container IP-Address must be in the same subnet range : %s", containerIP))
deleteInterface(c, defaultNetworkBridge)
}
@ -784,7 +784,7 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Implicit(c *testing.T) {
expectedMessage := fmt.Sprintf("default via %s dev", bridgeIP)
out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0")
assert.NilError(c, err, out)
assert.Equal(c, strings.Contains(out, expectedMessage), true, check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'", bridgeIP, strings.TrimSpace(out)))
assert.Equal(c, strings.Contains(out, expectedMessage), true, fmt.Sprintf("Implicit default gateway should be bridge IP %s, but default route was '%s'", bridgeIP, strings.TrimSpace(out)))
deleteInterface(c, defaultNetworkBridge)
}
@ -804,7 +804,7 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Explicit(c *testing.T) {
expectedMessage := fmt.Sprintf("default via %s dev", gatewayIP)
out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0")
assert.NilError(c, err, out)
assert.Equal(c, strings.Contains(out, expectedMessage), true, check.Commentf("Explicit default gateway should be %s, but default route was '%s'", gatewayIP, strings.TrimSpace(out)))
assert.Equal(c, strings.Contains(out, expectedMessage), true, fmt.Sprintf("Explicit default gateway should be %s, but default route was '%s'", gatewayIP, strings.TrimSpace(out)))
deleteInterface(c, defaultNetworkBridge)
}
@ -859,7 +859,7 @@ func (s *DockerDaemonSuite) TestDaemonIP(c *testing.T) {
result.Assert(c, icmd.Success)
regex := fmt.Sprintf("DNAT.*%s.*dpt:8000", ip.String())
matched, _ := regexp.MatchString(regex, result.Combined())
assert.Equal(c, matched, true, check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
assert.Equal(c, matched, true, fmt.Sprintf("iptables output should have contained %q, but was %q", regex, result.Combined()))
}
func (s *DockerDaemonSuite) TestDaemonICCPing(c *testing.T) {
@ -879,7 +879,7 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *testing.T) {
result.Assert(c, icmd.Success)
regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
matched, _ := regexp.MatchString(regex, result.Combined())
assert.Equal(c, matched, true, check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
assert.Equal(c, matched, true, fmt.Sprintf("iptables output should have contained %q, but was %q", regex, result.Combined()))
// Pinging another container must fail with --icc=false
pingContainers(c, d, true)
@ -912,7 +912,7 @@ func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *testing.T) {
result.Assert(c, icmd.Success)
regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
matched, _ := regexp.MatchString(regex, result.Combined())
assert.Equal(c, matched, true, check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
assert.Equal(c, matched, true, fmt.Sprintf("iptables output should have contained %q, but was %q", regex, result.Combined()))
out, err := d.Cmd("run", "-d", "--expose", "4567", "--name", "icc1", "busybox", "nc", "-l", "-p", "4567")
assert.NilError(c, err, out)
@ -1151,7 +1151,7 @@ func (s *DockerDaemonSuite) TestDaemonLoggingDriverShouldBeIgnoredForBuild(c *te
RUN echo foo`),
build.WithoutCache,
)
comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", result.Combined(), result.ExitCode, result.Error)
comment := fmt.Sprintf("Failed to build image. output %s, exitCode %d, err %v", result.Combined(), result.ExitCode, result.Error)
assert.Assert(c, result.Error == nil, comment)
assert.Equal(c, result.ExitCode, 0, comment)
assert.Assert(c, strings.Contains(result.Combined(), "foo"), comment)
@ -1750,7 +1750,7 @@ func (s *DockerDaemonSuite) TestBridgeIPIsExcludedFromAllocatorPool(c *testing.T
break
}
ip, err := s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.IPAddress}}'", contName)
assert.Assert(c, err == nil, check.Commentf("%s", ip))
assert.Assert(c, err == nil, fmt.Sprintf("%s", ip))
assert.Assert(c, ip != bridgeIP)
cont++
@ -1780,7 +1780,7 @@ func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *testing.T) {
// pull a repository large enough to overfill the mounted filesystem
pullOut, err := s.d.Cmd("pull", "debian:stretch")
assert.Assert(c, err != nil, check.Commentf("%s", pullOut))
assert.Assert(c, err != nil, fmt.Sprintf("%s", pullOut))
assert.Assert(c, strings.Contains(pullOut, "no space left on device"))
}
@ -1855,7 +1855,7 @@ func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *testing.T) {
out, err := s.d.Cmd("run", "--name", name, "busybox", "cat", "/proc/self/cgroup")
assert.NilError(c, err)
cgroupPaths := ParseCgroupPaths(string(out))
assert.Assert(c, len(cgroupPaths) != 0, check.Commentf("unexpected output - %q", string(out)))
assert.Assert(c, len(cgroupPaths) != 0, fmt.Sprintf("unexpected output - %q", string(out)))
out, err = s.d.Cmd("inspect", "-f", "{{.Id}}", name)
assert.NilError(c, err)
id := strings.TrimSpace(string(out))
@ -1867,7 +1867,7 @@ func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *testing.T) {
break
}
}
assert.Assert(c, found, check.Commentf("Cgroup path for container (%s) doesn't found in cgroups file: %s", expectedCgroup, cgroupPaths))
assert.Assert(c, found, fmt.Sprintf("Cgroup path for container (%s) doesn't found in cgroups file: %s", expectedCgroup, cgroupPaths))
}
func (s *DockerDaemonSuite) TestDaemonRestartWithLinks(c *testing.T) {
@ -1890,7 +1890,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithLinks(c *testing.T) {
assert.NilError(c, err, out)
out, err = s.d.Cmd("start", "-a", "test2")
assert.NilError(c, err, out)
assert.Equal(c, strings.Contains(out, "1 packets transmitted, 1 packets received"), true, check.Commentf("%s", out))
assert.Equal(c, strings.Contains(out, "1 packets transmitted, 1 packets received"), true, fmt.Sprintf("%s", out))
}
func (s *DockerDaemonSuite) TestDaemonRestartWithNames(c *testing.T) {
@ -2007,7 +2007,7 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *testing.T) {
// the following check for mounts being cleared is pointless.
skipMountCheck := false
mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
assert.Assert(c, err == nil, check.Commentf("Output: %s", mountOut))
assert.Assert(c, err == nil, fmt.Sprintf("Output: %s", mountOut))
if !strings.Contains(string(mountOut), id) {
skipMountCheck = true
}
@ -2032,8 +2032,8 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *testing.T) {
}
// Now, container mounts should be gone.
mountOut, err = ioutil.ReadFile("/proc/self/mountinfo")
assert.Assert(c, err == nil, check.Commentf("Output: %s", mountOut))
comment := check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.Root, mountOut)
assert.Assert(c, err == nil, fmt.Sprintf("Output: %s", mountOut))
comment := fmt.Sprintf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.Root, mountOut)
assert.Equal(c, strings.Contains(string(mountOut), id), false, comment)
}
@ -2363,7 +2363,7 @@ func (s *DockerDaemonSuite) TestBuildOnDisabledBridgeNetworkDaemon(c *testing.T)
RUN cat /etc/hosts`),
build.WithoutCache,
)
comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", result.Combined(), result.ExitCode, result.Error)
comment := fmt.Sprintf("Failed to build image. output %s, exitCode %d, err %v", result.Combined(), result.ExitCode, result.Error)
assert.Assert(c, result.Error == nil, comment)
assert.Equal(c, result.ExitCode, 0, comment)
}
@ -2376,11 +2376,11 @@ func (s *DockerDaemonSuite) TestDaemonDNSFlagsInHostMode(c *testing.T) {
expectedOutput := "nameserver 1.2.3.4"
out, _ := s.d.Cmd("run", "--net=host", "busybox", "cat", "/etc/resolv.conf")
assert.Assert(c, strings.Contains(out, expectedOutput), check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
expectedOutput = "search example.com"
assert.Assert(c, strings.Contains(out, expectedOutput), check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
expectedOutput = "options timeout:3"
assert.Assert(c, strings.Contains(out, expectedOutput), check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
}
func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *testing.T) {
@ -2555,10 +2555,10 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithAutoRemoveContainer(c *testing.
// top1 will exist after daemon restarts
out, err := s.d.Cmd("run", "-d", "--name", "top1", "busybox:latest", "top")
assert.Assert(c, err == nil, check.Commentf("run top1: %v", out))
assert.Assert(c, err == nil, fmt.Sprintf("run top1: %v", out))
// top2 will be removed after daemon restarts
out, err = s.d.Cmd("run", "-d", "--rm", "--name", "top2", "busybox:latest", "top")
assert.Assert(c, err == nil, check.Commentf("run top2: %v", out))
assert.Assert(c, err == nil, fmt.Sprintf("run top2: %v", out))
out, err = s.d.Cmd("ps")
assert.NilError(c, err)
@ -2714,14 +2714,14 @@ func (s *DockerDaemonSuite) TestExecWithUserAfterLiveRestore(c *testing.T) {
out1, err := s.d.Cmd("exec", "-u", "test", "top", "id")
// uid=100(test) gid=101(test) groups=101(test)
assert.Assert(c, err == nil, check.Commentf("Output: %s", out1))
assert.Assert(c, err == nil, fmt.Sprintf("Output: %s", out1))
// restart daemon.
s.d.Restart(c, "--live-restore")
out2, err := s.d.Cmd("exec", "-u", "test", "top", "id")
assert.Assert(c, err == nil, check.Commentf("Output: %s", out2))
assert.Equal(c, out2, out1, check.Commentf("Output: before restart '%s', after restart '%s'", out1, out2))
assert.Assert(c, err == nil, fmt.Sprintf("Output: %s", out2))
assert.Equal(c, out2, out1, fmt.Sprintf("Output: before restart '%s', after restart '%s'", out1, out2))
out, err = s.d.Cmd("stop", "top")
assert.NilError(c, err, "Output: %s", out)
@ -2773,7 +2773,7 @@ func (s *DockerDaemonSuite) TestRestartPolicyWithLiveRestore(c *testing.T) {
StartedAt time.Time
}
out, err = s.d.Cmd("inspect", "-f", "{{json .State}}", id)
assert.Assert(c, err == nil, check.Commentf("output: %s", out))
assert.Assert(c, err == nil, fmt.Sprintf("output: %s", out))
var origState state
err = json.Unmarshal([]byte(strings.TrimSpace(out)), &origState)
@ -2799,7 +2799,7 @@ func (s *DockerDaemonSuite) TestRestartPolicyWithLiveRestore(c *testing.T) {
}
out, err := s.d.Cmd("inspect", "-f", "{{json .State}}", id)
assert.Assert(c, err == nil, check.Commentf("output: %s", out))
assert.Assert(c, err == nil, fmt.Sprintf("output: %s", out))
var newState state
err = json.Unmarshal([]byte(strings.TrimSpace(out)), &newState)

View File

@ -304,7 +304,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *testing.T)
p := hostVolumePath("external-volume-test")
_, err = os.Lstat(p)
assert.ErrorContains(c, err, "")
assert.Assert(c, os.IsNotExist(err), check.Commentf("Expected volume path in host to not exist: %s, %v\n", p, err))
assert.Assert(c, os.IsNotExist(err), fmt.Sprintf("Expected volume path in host to not exist: %s, %v\n", p, err))
assert.Equal(c, s.ec.activations, 1)
assert.Equal(c, s.ec.creations, 1)
@ -449,7 +449,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c
}
out := inspectFieldJSON(c, "testing", "Mounts")
assert.Assert(c, json.NewDecoder(strings.NewReader(out)).Decode(&mounts) == nil)
assert.Equal(c, len(mounts), 1, check.Commentf("%s", out))
assert.Equal(c, len(mounts), 1, fmt.Sprintf("%s", out))
assert.Equal(c, mounts[0].Name, "foo")
assert.Equal(c, mounts[0].Driver, volumePluginName)
}
@ -458,10 +458,10 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverList(c *testing.T) {
dockerCmd(c, "volume", "create", "-d", volumePluginName, "abc3")
out, _ := dockerCmd(c, "volume", "ls")
ls := strings.Split(strings.TrimSpace(out), "\n")
assert.Equal(c, len(ls), 2, check.Commentf("\n%s", out))
assert.Equal(c, len(ls), 2, fmt.Sprintf("\n%s", out))
vol := strings.Fields(ls[len(ls)-1])
assert.Equal(c, len(vol), 2, check.Commentf("%v", vol))
assert.Equal(c, len(vol), 2, fmt.Sprintf("%v", vol))
assert.Equal(c, vol[0], volumePluginName)
assert.Equal(c, vol[1], "abc3")
@ -484,8 +484,8 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *testing.T) {
assert.Assert(c, json.Unmarshal([]byte(out), &st) == nil)
assert.Equal(c, len(st), 1)
assert.Equal(c, len(st[0].Status), 1, check.Commentf("%v", st[0]))
assert.Equal(c, st[0].Status["Hello"], "world", check.Commentf("%v", st[0].Status))
assert.Equal(c, len(st[0].Status), 1, fmt.Sprintf("%v", st[0]))
assert.Equal(c, st[0].Status["Hello"], "world", fmt.Sprintf("%v", st[0].Status))
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c *testing.T) {
@ -605,9 +605,9 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnMountFail(c
s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--opt=invalidOption=1", "--name=testumount")
out, _ := s.d.Cmd("run", "-v", "testumount:/foo", "busybox", "true")
assert.Equal(c, s.ec.unmounts, 0, check.Commentf("%s", out))
assert.Equal(c, s.ec.unmounts, 0, fmt.Sprintf("%s", out))
out, _ = s.d.Cmd("run", "-w", "/foo", "-v", "testumount:/foo", "busybox", "true")
assert.Equal(c, s.ec.unmounts, 0, check.Commentf("%s", out))
assert.Equal(c, s.ec.unmounts, 0, fmt.Sprintf("%s", out))
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnCp(c *testing.T) {
@ -615,12 +615,12 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnCp(c *testi
s.d.Cmd("volume", "create", "-d", "test-external-volume-driver", "--name=test")
out, _ := s.d.Cmd("run", "-d", "--name=test", "-v", "test:/foo", "busybox", "/bin/sh", "-c", "touch /test && top")
assert.Equal(c, s.ec.mounts, 1, check.Commentf("%s", out))
assert.Equal(c, s.ec.mounts, 1, fmt.Sprintf("%s", out))
out, _ = s.d.Cmd("cp", "test:/test", "/tmp/test")
assert.Equal(c, s.ec.mounts, 2, check.Commentf("%s", out))
assert.Equal(c, s.ec.unmounts, 1, check.Commentf("%s", out))
assert.Equal(c, s.ec.mounts, 2, fmt.Sprintf("%s", out))
assert.Equal(c, s.ec.unmounts, 1, fmt.Sprintf("%s", out))
out, _ = s.d.Cmd("kill", "test")
assert.Equal(c, s.ec.unmounts, 2, check.Commentf("%s", out))
assert.Equal(c, s.ec.unmounts, 2, fmt.Sprintf("%s", out))
}

View File

@ -99,7 +99,7 @@ func (s *DockerSuite) TestHistoryHumanOptionFalse(c *testing.T) {
sizeString := lines[i][startIndex:endIndex]
_, err := strconv.Atoi(strings.TrimSpace(sizeString))
assert.Assert(c, err == nil, check.Commentf("The size '%s' was not an Integer", sizeString))
assert.Assert(c, err == nil, fmt.Sprintf("The size '%s' was not an Integer", sizeString))
}
}
@ -121,6 +121,6 @@ func (s *DockerSuite) TestHistoryHumanOptionTrue(c *testing.T) {
humanSizeRegexRaw+
"$",
strings.TrimSpace(sizeString)), check.Commentf("The size '%s' was not in human format", sizeString))
strings.TrimSpace(sizeString)), fmt.Sprintf("The size '%s' was not in human format", sizeString))
}
}

View File

@ -62,9 +62,9 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *testing.T) {
out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
imgs := strings.Split(out, "\n")
assert.Equal(c, imgs[0], id3, check.Commentf("First image must be %s, got %s", id3, imgs[0]))
assert.Equal(c, imgs[1], id2, check.Commentf("First image must be %s, got %s", id2, imgs[1]))
assert.Equal(c, imgs[2], id1, check.Commentf("First image must be %s, got %s", id1, imgs[2]))
assert.Equal(c, imgs[0], id3, fmt.Sprintf("First image must be %s, got %s", id3, imgs[0]))
assert.Equal(c, imgs[1], id2, fmt.Sprintf("First image must be %s, got %s", id2, imgs[1]))
assert.Equal(c, imgs[2], id1, fmt.Sprintf("First image must be %s, got %s", id1, imgs[2]))
}
func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *testing.T) {
@ -139,34 +139,34 @@ LABEL number=3`))
expected := []string{imageID3, imageID2}
out, _ := dockerCmd(c, "images", "-f", "since=image:1", "image")
assert.Equal(c, assertImageList(out, expected), true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "since="+imageID1, "image")
assert.Equal(c, assertImageList(out, expected), true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
expected = []string{imageID3}
out, _ = dockerCmd(c, "images", "-f", "since=image:2", "image")
assert.Equal(c, assertImageList(out, expected), true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "since="+imageID2, "image")
assert.Equal(c, assertImageList(out, expected), true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
expected = []string{imageID2, imageID1}
out, _ = dockerCmd(c, "images", "-f", "before=image:3", "image")
assert.Equal(c, assertImageList(out, expected), true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "before="+imageID3, "image")
assert.Equal(c, assertImageList(out, expected), true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
expected = []string{imageID1}
out, _ = dockerCmd(c, "images", "-f", "before=image:2", "image")
assert.Equal(c, assertImageList(out, expected), true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "before="+imageID2, "image")
assert.Equal(c, assertImageList(out, expected), true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
}
func assertImageList(out string, expected []string) bool {

View File

@ -53,7 +53,7 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *testing.T) {
}
for _, linePrefix := range stringsToCheck {
assert.Assert(c, strings.Contains(out, linePrefix), check.Commentf("couldn't find string %v in output", linePrefix))
assert.Assert(c, strings.Contains(out, linePrefix), fmt.Sprintf("couldn't find string %v in output", linePrefix))
}
}

View File

@ -119,8 +119,8 @@ func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T) {
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
assert.Assert(c, err != nil, check.Commentf("%d", exitCode))
assert.Equal(c, exitCode, 1, check.Commentf("%s", err))
assert.Assert(c, err != nil, fmt.Sprintf("%d", exitCode))
assert.Equal(c, exitCode, 1, fmt.Sprintf("%s", err))
assert.Assert(c, strings.Contains(out, "not a valid value for --type"))
}
@ -130,7 +130,7 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *testing.T) {
out := inspectField(c, imageTest, "Size")
size, err := strconv.Atoi(out)
assert.Assert(c, err == nil, check.Commentf("failed to inspect size of the image: %s, %v", out, err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect size of the image: %s, %v", out, err))
//now see if the size turns out to be the same
formatStr := fmt.Sprintf("--format={{eq .Size %d}}", size)
@ -152,7 +152,7 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *testing.T) {
out = inspectField(c, id, "State.ExitCode")
exitCode, err := strconv.Atoi(out)
assert.Assert(c, err == nil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect exitcode of the container: %s, %v", out, err))
//now get the exit code to verify
formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode)
@ -172,12 +172,12 @@ func (s *DockerSuite) TestInspectImageGraphDriver(c *testing.T) {
deviceID := inspectField(c, imageTest, "GraphDriver.Data.DeviceId")
_, err := strconv.Atoi(deviceID)
assert.Assert(c, err == nil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
deviceSize := inspectField(c, imageTest, "GraphDriver.Data.DeviceSize")
_, err = strconv.ParseUint(deviceSize, 10, 64)
assert.Assert(c, err == nil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
}
func (s *DockerSuite) TestInspectContainerGraphDriver(c *testing.T) {
@ -197,12 +197,12 @@ func (s *DockerSuite) TestInspectContainerGraphDriver(c *testing.T) {
assert.Assert(c, imageDeviceID != deviceID)
_, err := strconv.Atoi(deviceID)
assert.Assert(c, err == nil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
deviceSize := inspectField(c, out, "GraphDriver.Data.DeviceSize")
_, err = strconv.ParseUint(deviceSize, 10, 64)
assert.Assert(c, err == nil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
}
func (s *DockerSuite) TestInspectBindMountPoint(c *testing.T) {
@ -289,10 +289,10 @@ func (s *DockerSuite) TestInspectLogConfigNoType(c *testing.T) {
out := inspectFieldJSON(c, "test", "HostConfig.LogConfig")
err := json.NewDecoder(strings.NewReader(out)).Decode(&logConfig)
assert.Assert(c, err == nil, check.Commentf("%v", out))
assert.Assert(c, err == nil, fmt.Sprintf("%v", out))
assert.Equal(c, logConfig.Type, "json-file")
assert.Equal(c, logConfig.Config["max-file"], "42", check.Commentf("%v", logConfig))
assert.Equal(c, logConfig.Config["max-file"], "42", fmt.Sprintf("%v", logConfig))
}
func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *testing.T) {
@ -304,7 +304,7 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *testing.T) {
formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}"
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
assert.Equal(c, strings.TrimSpace(out), "<nil>,<nil>", check.Commentf("Expected not to display size info: %s", out))
assert.Equal(c, strings.TrimSpace(out), "<nil>,<nil>", fmt.Sprintf("Expected not to display size info: %s", out))
}
func (s *DockerSuite) TestInspectSizeFlagContainer(c *testing.T) {

View File

@ -19,7 +19,7 @@ func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *testing.T) {
_, exitCode, err := dockerCmdWithError("run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
// run ping failed with error
assert.Equal(c, exitCode, 1, check.Commentf("error: %v", err))
assert.Equal(c, exitCode, 1, fmt.Sprintf("error: %v", err))
}
// Test for appropriate error when calling --link with an invalid target container
@ -28,7 +28,7 @@ func (s *DockerSuite) TestLinksInvalidContainerTarget(c *testing.T) {
out, _, err := dockerCmdWithError("run", "--link", "bogus:alias", "busybox", "true")
// an invalid container target should produce an error
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
// an invalid container target should produce an error
// note: convert the output to lowercase first as the error string
// capitalization was changed after API version 1.32
@ -170,7 +170,7 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *testing.T) {
getIP := func(hosts []byte, hostname string) string {
re := regexp.MustCompile(fmt.Sprintf(`(\S*)\t%s`, regexp.QuoteMeta(hostname)))
matches := re.FindSubmatch(hosts)
assert.Assert(c, matches != nil, check.Commentf("Hostname %s have no matches in hosts", hostname))
assert.Assert(c, matches != nil, fmt.Sprintf("Hostname %s have no matches in hosts", hostname))
return string(matches[1])
}
ip := getIP(content, "one")
@ -221,7 +221,7 @@ func (s *DockerSuite) TestLinksNetworkHostContainer(c *testing.T) {
out, _, err := dockerCmdWithError("run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")
// Running container linking to a container with --net host should have failed
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
// Running container linking to a container with --net host should have failed
assert.Assert(c, strings.Contains(out, runconfig.ErrConflictHostNetworkAndLinks.Error()))
}

View File

@ -20,7 +20,7 @@ const stringCheckPS = "PID USER"
// stop the tests.
func dockerCmdWithFail(c *testing.T, args ...string) (string, int) {
out, status, err := dockerCmdWithError(args...)
assert.Assert(c, err != nil, check.Commentf("%v", out))
assert.Assert(c, err != nil, fmt.Sprintf("%v", out))
return out, status
}

View File

@ -358,7 +358,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkLsFilter(c *testing.T) {
out, _ = dockerCmd(c, "network", "ls", "-f", "label=nonexistent")
outArr := strings.Split(strings.TrimSpace(out), "\n")
assert.Equal(c, len(outArr), 1, check.Commentf("%s\n", out))
assert.Equal(c, len(outArr), 1, fmt.Sprintf("%s\n", out))
out, _ = dockerCmd(c, "network", "ls", "-f", "driver=null")
assertNwList(c, out, []string{"none"})
@ -414,7 +414,7 @@ func (s *DockerSuite) TestDockerNetworkDeleteMultiple(c *testing.T) {
// contains active container, its deletion should fail.
out, _, err := dockerCmdWithError("network", "rm", "testDelMulti0", "testDelMulti1", "testDelMulti2")
// err should not be nil due to deleting testDelMulti2 failed.
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
// testDelMulti2 should fail due to network has active endpoints
assert.Assert(c, strings.Contains(out, "has active endpoints"))
assertNwNotAvailable(c, "testDelMulti0")
@ -823,14 +823,14 @@ func (s *DockerDaemonSuite) TestDockerNetworkNoDiscoveryDefaultBridgeNetwork(c *
// verify first container's etc/hosts file has not changed after spawning the second named container
hostsPost, err := s.d.Cmd("exec", cid1, "cat", hostsFile)
assert.NilError(c, err)
assert.Equal(c, string(hosts), string(hostsPost), check.Commentf("Unexpected %s change on second container creation", hostsFile))
assert.Equal(c, string(hosts), string(hostsPost), fmt.Sprintf("Unexpected %s change on second container creation", hostsFile))
// stop container 2 and verify first container's etc/hosts has not changed
_, err = s.d.Cmd("stop", cid2)
assert.NilError(c, err)
hostsPost, err = s.d.Cmd("exec", cid1, "cat", hostsFile)
assert.NilError(c, err)
assert.Equal(c, string(hosts), string(hostsPost), check.Commentf("Unexpected %s change on second container creation", hostsFile))
assert.Equal(c, string(hosts), string(hostsPost), fmt.Sprintf("Unexpected %s change on second container creation", hostsFile))
// but discovery is on when connecting to non default bridge network
network := "anotherbridge"
out, err = s.d.Cmd("network", "create", network)
@ -845,7 +845,7 @@ func (s *DockerDaemonSuite) TestDockerNetworkNoDiscoveryDefaultBridgeNetwork(c *
hostsPost, err = s.d.Cmd("exec", cid1, "cat", hostsFile)
assert.NilError(c, err)
assert.Equal(c, string(hosts), string(hostsPost), check.Commentf("Unexpected %s change on second network connection", hostsFile))
assert.Equal(c, string(hosts), string(hostsPost), fmt.Sprintf("Unexpected %s change on second network connection", hostsFile))
}
func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *testing.T) {
@ -868,7 +868,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *testing.T) {
// verify first container etc/hosts file has not changed
hosts1post := readContainerFileWithExec(c, cid1, hostsFile)
assert.Equal(c, string(hosts1), string(hosts1post), check.Commentf("Unexpected %s change on anonymous container creation", hostsFile))
assert.Equal(c, string(hosts1), string(hosts1post), fmt.Sprintf("Unexpected %s change on anonymous container creation", hostsFile))
// Connect the 2nd container to a new network and verify the
// first container /etc/hosts file still hasn't changed.
dockerCmd(c, "network", "create", "-d", "bridge", cstmBridgeNw1)
@ -878,7 +878,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *testing.T) {
hosts2 := readContainerFileWithExec(c, cid2, hostsFile)
hosts1post = readContainerFileWithExec(c, cid1, hostsFile)
assert.Equal(c, string(hosts1), string(hosts1post), check.Commentf("Unexpected %s change on container connect", hostsFile))
assert.Equal(c, string(hosts1), string(hosts1post), fmt.Sprintf("Unexpected %s change on container connect", hostsFile))
// start a named container
cName := "AnyName"
out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "--name", cName, "busybox", "top")
@ -891,9 +891,9 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *testing.T) {
// Stop named container and verify first two containers' etc/hosts file hasn't changed
dockerCmd(c, "stop", cid3)
hosts1post = readContainerFileWithExec(c, cid1, hostsFile)
assert.Equal(c, string(hosts1), string(hosts1post), check.Commentf("Unexpected %s change on name container creation", hostsFile))
assert.Equal(c, string(hosts1), string(hosts1post), fmt.Sprintf("Unexpected %s change on name container creation", hostsFile))
hosts2post := readContainerFileWithExec(c, cid2, hostsFile)
assert.Equal(c, string(hosts2), string(hosts2post), check.Commentf("Unexpected %s change on name container creation", hostsFile))
assert.Equal(c, string(hosts2), string(hosts2post), fmt.Sprintf("Unexpected %s change on name container creation", hostsFile))
// verify that container 1 and 2 can't ping the named container now
_, _, err := dockerCmdWithError("exec", cid1, "ping", "-c", "1", cName)
assert.ErrorContains(c, err, "")
@ -1309,7 +1309,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIP(c *testing.T) {
// Still it should fail to connect to the default network with a specified IP (whatever ip)
out, _, err := dockerCmdWithError("network", "connect", "--ip", "172.21.55.44", "bridge", "c0")
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
assert.Assert(c, strings.Contains(out, runconfig.ErrUnsupportedNetworkAndIP.Error()))
}
@ -1347,10 +1347,10 @@ func (s *DockerNetworkSuite) TestDockerNetworkUnsupportedRequiredIP(c *testing.T
assertNwIsAvailable(c, "n0")
out, _, err := dockerCmdWithError("run", "-d", "--ip", "172.28.99.88", "--net", "n0", "busybox", "top")
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
assert.Assert(c, strings.Contains(out, runconfig.ErrUnsupportedNetworkNoSubnetAndIP.Error()))
out, _, err = dockerCmdWithError("run", "-d", "--ip6", "2001:db8:1234::9988", "--net", "n0", "busybox", "top")
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
assert.Assert(c, strings.Contains(out, runconfig.ErrUnsupportedNetworkNoSubnetAndIP.Error()))
dockerCmd(c, "network", "rm", "n0")
assertNwNotAvailable(c, "n0")
@ -1358,7 +1358,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkUnsupportedRequiredIP(c *testing.T
func checkUnsupportedNetworkAndIP(c *testing.T, nwMode string) {
out, _, err := dockerCmdWithError("run", "-d", "--net", nwMode, "--ip", "172.28.99.88", "--ip6", "2001:db8:1234::9988", "busybox", "top")
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
assert.Assert(c, strings.Contains(out, runconfig.ErrUnsupportedNetworkAndIP.Error()))
}
@ -1485,8 +1485,8 @@ func (s *DockerNetworkSuite) TestDockerNetworkDisconnectDefault(c *testing.T) {
dockerCmd(c, "start", containerName)
assert.Assert(c, waitRun(containerName) == nil)
networks := inspectField(c, containerName, "NetworkSettings.Networks")
assert.Assert(c, strings.Contains(networks, netWorkName1), check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName1)))
assert.Assert(c, strings.Contains(networks, netWorkName2), check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName2)))
assert.Assert(c, strings.Contains(networks, netWorkName1), fmt.Sprintf(fmt.Sprintf("Should contain '%s' network", netWorkName1)))
assert.Assert(c, strings.Contains(networks, netWorkName2), fmt.Sprintf(fmt.Sprintf("Should contain '%s' network", netWorkName2)))
assert.Assert(c, !strings.Contains(networks, "bridge"), check.Commentf("Should not contain 'bridge' network"))
}
@ -1549,11 +1549,11 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectAlias(c *testing.T)
// verify the alias option is rejected when running on predefined network
out, _, err := dockerCmdWithError("run", "--rm", "--name=any", "--net-alias=any", "busybox:glibc", "top")
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
assert.Assert(c, strings.Contains(out, runconfig.ErrUnsupportedNetworkAndAlias.Error()))
// verify the alias option is rejected when connecting to predefined network
out, _, err = dockerCmdWithError("network", "connect", "--alias=any", "bridge", "first")
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
assert.Assert(c, strings.Contains(out, runconfig.ErrUnsupportedNetworkAndAlias.Error()))
}
@ -1705,13 +1705,13 @@ func (s *DockerDaemonSuite) TestDaemonRestartRestoreBridgeNetwork(t *testing.T)
func (s *DockerNetworkSuite) TestDockerNetworkFlagAlias(c *testing.T) {
dockerCmd(c, "network", "create", "user")
output, status := dockerCmd(c, "run", "--rm", "--network=user", "--network-alias=foo", "busybox", "true")
assert.Equal(c, status, 0, check.Commentf("unexpected status code %d (%s)", status, output))
assert.Equal(c, status, 0, fmt.Sprintf("unexpected status code %d (%s)", status, output))
output, status, _ = dockerCmdWithError("run", "--rm", "--net=user", "--network=user", "busybox", "true")
assert.Equal(c, status, 0, check.Commentf("unexpected status code %d (%s)", status, output))
assert.Equal(c, status, 0, fmt.Sprintf("unexpected status code %d (%s)", status, output))
output, status, _ = dockerCmdWithError("run", "--rm", "--network=user", "--net-alias=foo", "--network-alias=bar", "busybox", "true")
assert.Equal(c, status, 0, check.Commentf("unexpected status code %d (%s)", status, output))
assert.Equal(c, status, 0, fmt.Sprintf("unexpected status code %d (%s)", status, output))
}
func (s *DockerNetworkSuite) TestDockerNetworkValidateIP(c *testing.T) {

View File

@ -429,7 +429,7 @@ func (s *DockerSuite) TestPluginUpgrade(c *testing.T) {
// make sure "v2" does not exists
_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
assert.Assert(c, os.IsNotExist(err), check.Commentf("%s", out))
assert.Assert(c, os.IsNotExist(err), fmt.Sprintf("%s", out))
dockerCmd(c, "plugin", "disable", "-f", plugin)
dockerCmd(c, "plugin", "upgrade", "--grant-all-permissions", "--skip-remote-check", plugin, pluginV2)

View File

@ -105,7 +105,7 @@ func (s *DockerSuite) TestPortList(c *testing.T) {
"-p", "9090-9092:80",
"busybox", "top")
// Exhausted port range did not return an error
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
for i := 0; i < 3; i++ {
dockerCmd(c, "rm", "-f", IDs[i])
@ -121,7 +121,7 @@ func (s *DockerSuite) TestPortList(c *testing.T) {
"-p", invalidRange,
"busybox", "top")
// Port range should have returned an error
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
}
// test host range:container range spec.
@ -235,9 +235,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *testing.T) {
expBndRegx2 := regexp.MustCompile(`0.0.0.0:\d\d\d\d\d->` + unpPort2)
out, _ = dockerCmd(c, "ps", "-n=1")
// Cannot find expected port binding port (0.0.0.0:xxxxx->unpPort1) in docker ps output
assert.Equal(c, expBndRegx1.MatchString(out), true, check.Commentf("out: %s; unpPort1: %s", out, unpPort1))
assert.Equal(c, expBndRegx1.MatchString(out), true, fmt.Sprintf("out: %s; unpPort1: %s", out, unpPort1))
// Cannot find expected port binding port (0.0.0.0:xxxxx->unpPort2) in docker ps output
assert.Equal(c, expBndRegx2.MatchString(out), true, check.Commentf("out: %s; unpPort2: %s", out, unpPort2))
assert.Equal(c, expBndRegx2.MatchString(out), true, fmt.Sprintf("out: %s; unpPort2: %s", out, unpPort2))
// Run the container specifying explicit port bindings for the exposed ports
offset := 10000
@ -300,7 +300,7 @@ func (s *DockerSuite) TestPortHostBinding(c *testing.T) {
out, _, err = dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "9876")
// Port is still bound after the Container is removed
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
}
func (s *DockerSuite) TestPortExposeHostBinding(c *testing.T) {
@ -312,7 +312,7 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *testing.T) {
out, _ = dockerCmd(c, "port", firstID, "80")
_, exposedPort, err := net.SplitHostPort(out)
assert.Assert(c, err == nil, check.Commentf("out: %s", out))
assert.Assert(c, err == nil, fmt.Sprintf("out: %s", out))
dockerCmd(c, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
@ -322,7 +322,7 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *testing.T) {
out, _, err = dockerCmdWithError("run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
// Port is still bound after the Container is removed
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
}
func (s *DockerSuite) TestPortBindingOnSandbox(c *testing.T) {

View File

@ -45,79 +45,79 @@ func (s *DockerSuite) TestPsListContainersBase(c *testing.T) {
// all
out, _ = dockerCmd(c, "ps", "-a")
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, thirdID, secondID, firstID}), true, check.Commentf("ALL: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, thirdID, secondID, firstID}), true, fmt.Sprintf("ALL: Container list is not in the correct order: \n%s", out))
// running
out, _ = dockerCmd(c, "ps")
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, secondID, firstID}), true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, secondID, firstID}), true, fmt.Sprintf("RUNNING: Container list is not in the correct order: \n%s", out))
// limit
out, _ = dockerCmd(c, "ps", "-n=2", "-a")
expected := []string{fourthID, thirdID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-n=2")
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("LIMIT: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("LIMIT: Container list is not in the correct order: \n%s", out))
// filter since
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-a")
expected = []string{fourthID, thirdID, secondID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID)
expected = []string{fourthID, secondID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "since="+thirdID)
expected = []string{fourthID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter: Container list is not in the correct order: \n%s", out))
// filter before
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-a")
expected = []string{thirdID, secondID, firstID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID)
expected = []string{secondID, firstID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("BEFORE filter: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "before="+thirdID)
expected = []string{secondID, firstID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter: Container list is not in the correct order: \n%s", out))
// filter since & before
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-a")
expected = []string{thirdID, secondID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID)
expected = []string{secondID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
// filter since & limit
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2", "-a")
expected = []string{fourthID, thirdID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2")
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
// filter before & limit
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1", "-a")
expected = []string{thirdID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1")
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
// filter since & filter before & limit
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1", "-a")
expected = []string{thirdID}
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-f", "before="+fourthID, "-n=1")
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, check.Commentf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
assert.Equal(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), true, fmt.Sprintf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
}
@ -173,10 +173,10 @@ func (s *DockerSuite) TestPsListContainersSize(c *testing.T) {
sizeIndex := strings.Index(lines[0], "SIZE")
idIndex := strings.Index(lines[0], "CONTAINER ID")
foundID := lines[1][idIndex : idIndex+12]
assert.Equal(c, foundID, id[:12], check.Commentf("Expected id %s, got %s", id[:12], foundID))
assert.Equal(c, foundID, id[:12], fmt.Sprintf("Expected id %s, got %s", id[:12], foundID))
expectedSize := fmt.Sprintf("%dB", 2+baseBytes)
foundSize := lines[1][sizeIndex:]
assert.Assert(c, strings.Contains(foundSize, expectedSize), check.Commentf("Expected size %q, got %q", expectedSize, foundSize))
assert.Assert(c, strings.Contains(foundSize, expectedSize), fmt.Sprintf("Expected size %q, got %q", expectedSize, foundSize))
}
func (s *DockerSuite) TestPsListContainersFilterStatus(c *testing.T) {
@ -236,7 +236,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *testing.T) {
out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined()
containerOut := strings.TrimSpace(out)
assert.Equal(c, containerOut, containerID, check.Commentf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out))
assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out))
// Test no health check specified explicitly
out = runSleepingContainer(c, "--name=none", "--no-healthcheck")
@ -246,7 +246,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *testing.T) {
out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined()
containerOut = strings.TrimSpace(out)
assert.Equal(c, containerOut, containerID, check.Commentf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out))
assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out))
// Test failing health check
out = runSleepingContainer(c, "--name=failing_container", "--health-cmd=exit 1", "--health-interval=1s")
@ -256,7 +256,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *testing.T) {
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy").Combined()
containerOut = strings.TrimSpace(out)
assert.Equal(c, containerOut, containerID, check.Commentf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out))
assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out))
// Check passing healthcheck
out = runSleepingContainer(c, "--name=passing_container", "--health-cmd=exit 0", "--health-interval=1s")
@ -266,7 +266,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *testing.T) {
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy").Combined()
containerOut = strings.TrimSpace(RemoveOutputForExistingElements(out, existingContainers))
assert.Equal(c, containerOut, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
assert.Equal(c, containerOut, containerID, fmt.Sprintf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
}
func (s *DockerSuite) TestPsListContainersFilterID(c *testing.T) {
@ -280,7 +280,7 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *testing.T) {
// filter containers by id
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID)
containerOut := strings.TrimSpace(out)
assert.Equal(c, containerOut, firstID[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
assert.Equal(c, containerOut, firstID[:12], fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
}
func (s *DockerSuite) TestPsListContainersFilterName(c *testing.T) {
@ -294,7 +294,7 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *testing.T) {
// filter containers by name
out, _ := dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match")
containerOut := strings.TrimSpace(out)
assert.Equal(c, containerOut, id[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", id[:12], containerOut, out))
assert.Equal(c, containerOut, id[:12], fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", id[:12], containerOut, out))
}
// Test for the ancestor filter for ps.
@ -386,7 +386,7 @@ func checkPsAncestorFilterOutput(c *testing.T, out string, filterName string, ex
sort.Strings(actualIDs)
sort.Strings(expectedIDs)
assert.Equal(c, len(actualIDs), len(expectedIDs), check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs))
assert.Equal(c, len(actualIDs), len(expectedIDs), fmt.Sprintf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs))
if len(expectedIDs) > 0 {
same := true
for i := range expectedIDs {
@ -396,7 +396,7 @@ func checkPsAncestorFilterOutput(c *testing.T, out string, filterName string, ex
break
}
}
assert.Equal(c, same, true, check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs))
assert.Equal(c, same, true, fmt.Sprintf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs))
}
}
@ -416,17 +416,17 @@ func (s *DockerSuite) TestPsListContainersFilterLabel(c *testing.T) {
// filter containers by exact match
out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
containerOut := strings.TrimSpace(out)
assert.Equal(c, containerOut, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
assert.Equal(c, containerOut, firstID, fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
// filter containers by two labels
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag")
containerOut = strings.TrimSpace(out)
assert.Equal(c, containerOut, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
assert.Equal(c, containerOut, firstID, fmt.Sprintf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
// filter containers by two labels, but expect not found because of AND behavior
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me", "--filter=label=second=tag-no")
containerOut = strings.TrimSpace(out)
assert.Equal(c, containerOut, "", check.Commentf("Expected nothing, got %s for exited filter, output: %q", containerOut, out))
assert.Equal(c, containerOut, "", fmt.Sprintf("Expected nothing, got %s for exited filter, output: %q", containerOut, out))
// filter containers by exact key
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match")
@ -443,11 +443,11 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *testing.T) {
secondZero, _ := dockerCmd(c, "run", "-d", "busybox", "true")
out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false")
assert.Assert(c, err != nil, check.Commentf("Should fail. out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("Should fail. out: %s", out))
firstNonZero := getIDByName(c, "nonzero1")
out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false")
assert.Assert(c, err != nil, check.Commentf("Should fail. out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("Should fail. out: %s", out))
secondNonZero := getIDByName(c, "nonzero2")
// filter containers by exited=0
@ -498,11 +498,11 @@ func (s *DockerSuite) TestPsRightTagName(c *testing.T) {
f := strings.Fields(line)
switch f[0] {
case id1:
assert.Equal(c, f[1], "busybox", check.Commentf("Expected %s tag for id %s, got %s", "busybox", id1, f[1]))
assert.Equal(c, f[1], "busybox", fmt.Sprintf("Expected %s tag for id %s, got %s", "busybox", id1, f[1]))
case id2:
assert.Equal(c, f[1], tag, check.Commentf("Expected %s tag for id %s, got %s", tag, id2, f[1]))
assert.Equal(c, f[1], tag, fmt.Sprintf("Expected %s tag for id %s, got %s", tag, id2, f[1]))
case id3:
assert.Equal(c, f[1], imageID, check.Commentf("Expected %s imageID for id %s, got %s", tag, id3, f[1]))
assert.Equal(c, f[1], imageID, fmt.Sprintf("Expected %s imageID for id %s, got %s", tag, id3, f[1]))
default:
c.Fatalf("Unexpected id %s, expected %s and %s and %s", f[0], id1, id2, id3)
}
@ -517,7 +517,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *testing.T) {
// Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
out, _ = dockerCmd(c, "ps", "-q")
assert.Assert(c, !strings.Contains(out, shortCID), check.Commentf("Should have not seen '%s' in ps output:\n%s", shortCID, out))
assert.Assert(c, !strings.Contains(out, shortCID), fmt.Sprintf("Should have not seen '%s' in ps output:\n%s", shortCID, out))
// Make sure it DOES show up as 'Created' for 'ps -a'
out, _ = dockerCmd(c, "ps", "-a")
@ -527,10 +527,10 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *testing.T) {
continue
}
hits++
assert.Assert(c, strings.Contains(line, "Created"), check.Commentf("Missing 'Created' on '%s'", line))
assert.Assert(c, strings.Contains(line, "Created"), fmt.Sprintf("Missing 'Created' on '%s'", line))
}
assert.Equal(c, hits, 1, check.Commentf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out))
assert.Equal(c, hits, 1, fmt.Sprintf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out))
// filter containers by 'create' - note, no -a needed
out, _ = dockerCmd(c, "ps", "-q", "-f", "status=created")
@ -596,14 +596,14 @@ func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *testing.T) {
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
expected := "0.0.0.0:5000->5000/tcp"
fields := strings.Fields(lines[1])
assert.Equal(c, fields[len(fields)-2], expected, check.Commentf("Expected: %v, got: %v", expected, fields[len(fields)-2]))
assert.Equal(c, fields[len(fields)-2], expected, fmt.Sprintf("Expected: %v, got: %v", expected, fields[len(fields)-2]))
dockerCmd(c, "kill", "foo")
dockerCmd(c, "wait", "foo")
out, _ = dockerCmd(c, "ps", "-l")
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
fields = strings.Fields(lines[1])
assert.Assert(c, fields[len(fields)-2] != expected, check.Commentf("Should not got %v", expected))
assert.Assert(c, fields[len(fields)-2] != expected, fmt.Sprintf("Should not got %v", expected))
}
func (s *DockerSuite) TestPsShowMounts(c *testing.T) {

View File

@ -355,7 +355,7 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *testing.T) {
// The pull output includes "Digest: <digest>", so find that
matches := digestRegex.FindStringSubmatch(out)
assert.Equal(c, len(matches), 2, check.Commentf("unable to parse digest from pull output: %s", out))
assert.Equal(c, len(matches), 2, fmt.Sprintf("unable to parse digest from pull output: %s", out))
pullDigest := matches[1]
// Make sure the pushed and pull digests match

View File

@ -27,7 +27,7 @@ func (s *DockerSuite) TestRmiWithContainerFails(c *testing.T) {
// Container is using image, should not be able to rmi
assert.ErrorContains(c, err, "")
// Container is using image, error message should contain errSubstr
assert.Assert(c, strings.Contains(out, errSubstr), check.Commentf("Container: %q", cleanedContainerID))
assert.Assert(c, strings.Contains(out, errSubstr), fmt.Sprintf("Container: %q", cleanedContainerID))
// make sure it didn't delete the busybox name
images, _ := dockerCmd(c, "images")
// The name 'busybox' should not have been removed from images
@ -41,23 +41,23 @@ func (s *DockerSuite) TestRmiTag(c *testing.T) {
dockerCmd(c, "tag", "busybox", "utest:5000/docker:tag3")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+3, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+3, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
dockerCmd(c, "rmi", "utest/docker:tag2")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+2, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+2, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
dockerCmd(c, "rmi", "utest:5000/docker:tag3")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+1, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+1, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
dockerCmd(c, "rmi", "utest:tag1")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n"), check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n"), fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
}
@ -80,7 +80,7 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *testing.T) {
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
// tag busybox to create 2 more images with same imageID
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+2, check.Commentf("docker images shows: %q\n", imagesAfter))
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+2, fmt.Sprintf("docker images shows: %q\n", imagesAfter))
imgID := inspectField(c, "busybox-one:tag1", "Id")
@ -100,7 +100,7 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *testing.T) {
imagesAfter = cli.DockerCmd(c, "images", "-a").Combined()
// rmi -f failed, image still exists
assert.Assert(c, !strings.Contains(imagesAfter, imgID[:12]), check.Commentf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter))
assert.Assert(c, !strings.Contains(imagesAfter, imgID[:12]), fmt.Sprintf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter))
}
func (s *DockerSuite) TestRmiImgIDForce(c *testing.T) {
@ -122,7 +122,7 @@ func (s *DockerSuite) TestRmiImgIDForce(c *testing.T) {
cli.DockerCmd(c, "tag", "busybox-test", "utest:5000/docker:tag4")
{
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+4, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Equal(c, strings.Count(imagesAfter, "\n"), strings.Count(imagesBefore, "\n")+4, fmt.Sprintf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
imgID := inspectField(c, "busybox-test", "Id")
@ -210,7 +210,7 @@ func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *testing.T) {
assert.Assert(c, !strings.Contains(out, "Untagged: "+tag1))
// Check built image still exists
images, _ := dockerCmd(c, "images", "-a")
assert.Assert(c, strings.Contains(images, imageName), check.Commentf("Built image missing %q; Images: %q", imageName, images))
assert.Assert(c, strings.Contains(images, imageName), fmt.Sprintf("Built image missing %q; Images: %q", imageName, images))
}
func (s *DockerSuite) TestRmiBlank(c *testing.T) {
@ -218,9 +218,9 @@ func (s *DockerSuite) TestRmiBlank(c *testing.T) {
// Should have failed to delete ' ' image
assert.ErrorContains(c, err, "")
// Wrong error message generated
assert.Assert(c, !strings.Contains(out, "no such id"), check.Commentf("out: %s", out))
assert.Assert(c, !strings.Contains(out, "no such id"), fmt.Sprintf("out: %s", out))
// Expected error message not generated
assert.Assert(c, strings.Contains(out, "image name cannot be blank"), check.Commentf("out: %s", out))
assert.Assert(c, strings.Contains(out, "image name cannot be blank"), fmt.Sprintf("out: %s", out))
}
func (s *DockerSuite) TestRmiContainerImageNotFound(c *testing.T) {
@ -245,7 +245,7 @@ func (s *DockerSuite) TestRmiContainerImageNotFound(c *testing.T) {
out, _, err := dockerCmdWithError("rmi", "-f", imageIds[0])
// The image of the running container should not be removed.
assert.ErrorContains(c, err, "")
assert.Assert(c, strings.Contains(out, "image is being used by running container"), check.Commentf("out: %s", out))
assert.Assert(c, strings.Contains(out, "image is being used by running container"), fmt.Sprintf("out: %s", out))
}
// #13422
@ -272,7 +272,7 @@ RUN echo 2 #layer2
// See if the "tmp2" can be untagged.
out, _ = dockerCmd(c, "rmi", newTag)
// Expected 1 untagged entry
assert.Equal(c, strings.Count(out, "Untagged: "), 1, check.Commentf("out: %s", out))
assert.Equal(c, strings.Count(out, "Untagged: "), 1, fmt.Sprintf("out: %s", out))
// Now let's add the tag again and create a container based on it.
dockerCmd(c, "tag", idToTag, newTag)

View File

@ -3212,8 +3212,8 @@ func (s *DockerSuite) TestRunCreateContainerFailedCleanUp(c *testing.T) {
assert.Assert(c, err != nil, check.Commentf("Expected docker run to fail!"))
containerID, err := inspectFieldWithError(name, "Id")
assert.Assert(c, err != nil, check.Commentf("Expected not to have this container: %s!", containerID))
assert.Equal(c, containerID, "", check.Commentf("Expected not to have this container: %s!", containerID))
assert.Assert(c, err != nil, fmt.Sprintf("Expected not to have this container: %s!", containerID))
assert.Equal(c, containerID, "", fmt.Sprintf("Expected not to have this container: %s!", containerID))
}
func (s *DockerSuite) TestRunNamedVolume(c *testing.T) {
@ -3948,14 +3948,14 @@ func (s *DockerSuite) TestRunAttachFailedNoLeak(c *testing.T) {
// We will need the following `inspect` to diagnose the issue if test fails (#21247)
out1, err1 := dockerCmd(c, "inspect", "--format", "{{json .State}}", "test")
out2, err2 := dockerCmd(c, "inspect", "--format", "{{json .State}}", "fail")
assert.Assert(c, err != nil, check.Commentf("Command should have failed but succeeded with: %s\nContainer 'test' [%+v]: %s\nContainer 'fail' [%+v]: %s", out, err1, out1, err2, out2))
assert.Assert(c, err != nil, fmt.Sprintf("Command should have failed but succeeded with: %s\nContainer 'test' [%+v]: %s\nContainer 'fail' [%+v]: %s", out, err1, out1, err2, out2))
// check for windows error as well
// TODO Windows Post TP5. Fix the error message string
assert.Assert(c, strings.Contains(string(out), "port is already allocated") ||
strings.Contains(string(out), "were not connected because a duplicate name exists") ||
strings.Contains(string(out), "The specified port already exists") ||
strings.Contains(string(out), "HNS failed with error : Failed to create endpoint") ||
strings.Contains(string(out), "HNS failed with error : The object already exists"), checker.Equals, true, check.Commentf("Output: %s", out))
strings.Contains(string(out), "HNS failed with error : The object already exists"), checker.Equals, true, fmt.Sprintf("Output: %s", out))
dockerCmd(c, "rm", "-f", "test")
// NGoroutines is not updated right away, so we need to wait before failing
@ -4034,9 +4034,9 @@ func (s *DockerSuite) TestRunDNSInHostMode(c *testing.T) {
expectedOutput2 := "search example.com"
expectedOutput3 := "options timeout:3"
out := cli.DockerCmd(c, "run", "--dns=1.2.3.4", "--dns-search=example.com", "--dns-opt=timeout:3", "--net=host", "busybox", "cat", "/etc/resolv.conf").Combined()
assert.Assert(c, strings.Contains(out, expectedOutput1), check.Commentf("Expected '%s', but got %q", expectedOutput1, out))
assert.Assert(c, strings.Contains(out, expectedOutput2), check.Commentf("Expected '%s', but got %q", expectedOutput2, out))
assert.Assert(c, strings.Contains(out, expectedOutput3), check.Commentf("Expected '%s', but got %q", expectedOutput3, out))
assert.Assert(c, strings.Contains(out, expectedOutput1), fmt.Sprintf("Expected '%s', but got %q", expectedOutput1, out))
assert.Assert(c, strings.Contains(out, expectedOutput2), fmt.Sprintf("Expected '%s', but got %q", expectedOutput2, out))
assert.Assert(c, strings.Contains(out, expectedOutput3), fmt.Sprintf("Expected '%s', but got %q", expectedOutput3, out))
}
// Test case for #21976
@ -4045,14 +4045,14 @@ func (s *DockerSuite) TestRunAddHostInHostMode(c *testing.T) {
expectedOutput := "1.2.3.4\textra"
out, _ := dockerCmd(c, "run", "--add-host=extra:1.2.3.4", "--net=host", "busybox", "cat", "/etc/hosts")
assert.Assert(c, strings.Contains(out, expectedOutput), check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
}
func (s *DockerSuite) TestRunRmAndWait(c *testing.T) {
dockerCmd(c, "run", "--name=test", "--rm", "-d", "busybox", "sh", "-c", "sleep 3;exit 2")
out, code, err := dockerCmdWithError("wait", "test")
assert.Assert(c, err == nil, check.Commentf("out: %s; exit code: %d", out, code))
assert.Assert(c, err == nil, fmt.Sprintf("out: %s; exit code: %d", out, code))
assert.Equal(c, out, "2\n", "exit code: %d", code)
assert.Equal(c, code, 0)
}
@ -4138,7 +4138,7 @@ func (s *DockerSuite) TestRunStoppedLoggingDriverNoLeak(c *testing.T) {
out, _, err := dockerCmdWithError("run", "--name=fail", "--log-driver=splunk", "busybox", "true")
assert.ErrorContains(c, err, "")
assert.Assert(c, strings.Contains(out, "failed to initialize logging driver"), check.Commentf("error should be about logging driver, got output %s", out))
assert.Assert(c, strings.Contains(out, "failed to initialize logging driver"), fmt.Sprintf("error should be about logging driver, got output %s", out))
// NGoroutines is not updated right away, so we need to wait before failing
assert.Assert(c, waitForGoroutines(nroutines) == nil)
}
@ -4158,8 +4158,8 @@ func (s *DockerSuite) TestRunCredentialSpecFailures(c *testing.T) {
}
for _, attempt := range attempts {
_, _, err := dockerCmdWithError("run", "--security-opt=credentialspec="+attempt.value, "busybox", "true")
assert.Assert(c, err != nil, check.Commentf("%s expected non-nil err", attempt.value))
assert.Assert(c, strings.Contains(err.Error(), attempt.expectedError), check.Commentf("%s expected %s got %s", attempt.value, attempt.expectedError, err))
assert.Assert(c, err != nil, fmt.Sprintf("%s expected non-nil err", attempt.value))
assert.Assert(c, strings.Contains(err.Error(), attempt.expectedError), fmt.Sprintf("%s expected %s got %s", attempt.value, attempt.expectedError, err))
}
}
@ -4490,11 +4490,11 @@ func (s *DockerSuite) TestRunMount(c *testing.T) {
_, _, err := dockerCmdWithError(append([]string{"run", "-i", "-d", "--name", cName},
append(opts, []string{"busybox", "top"}...)...)...)
if testCase.valid {
assert.Assert(c, err == nil, check.Commentf("got error while creating a container with %v (%s)", opts, cName))
assert.Assert(c, testCase.fn(cName) == nil, check.Commentf("got error while executing test for %v (%s)", opts, cName))
assert.Assert(c, err == nil, fmt.Sprintf("got error while creating a container with %v (%s)", opts, cName))
assert.Assert(c, testCase.fn(cName) == nil, fmt.Sprintf("got error while executing test for %v (%s)", opts, cName))
dockerCmd(c, "rm", "-f", cName)
} else {
assert.Assert(c, err != nil, check.Commentf("got nil while creating a container with %v (%s)", opts, cName))
assert.Assert(c, err != nil, fmt.Sprintf("got nil while creating a container with %v (%s)", opts, cName))
}
}
}

View File

@ -70,8 +70,8 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *testing.T) {
// Create a temporary tmpfs mount.
tmpfsDir := filepath.Join(tmpDir, "tmpfs")
assert.Assert(c, os.MkdirAll(tmpfsDir, 0777) == nil, check.Commentf("failed to mkdir at %s", tmpfsDir))
assert.Assert(c, mount.Mount("tmpfs", tmpfsDir, "tmpfs", "") == nil, check.Commentf("failed to create a tmpfs mount at %s", tmpfsDir))
assert.Assert(c, os.MkdirAll(tmpfsDir, 0777) == nil, fmt.Sprintf("failed to mkdir at %s", tmpfsDir))
assert.Assert(c, mount.Mount("tmpfs", tmpfsDir, "tmpfs", "") == nil, fmt.Sprintf("failed to create a tmpfs mount at %s", tmpfsDir))
f, err := ioutil.TempFile(tmpfsDir, "touch-me")
assert.NilError(c, err)
@ -672,10 +672,10 @@ func (s *DockerSuite) TestRunWithSwappinessInvalid(c *testing.T) {
out, _, err := dockerCmdWithError("run", "--memory-swappiness", "101", "busybox", "true")
assert.ErrorContains(c, err, "")
expected := "Valid memory swappiness range is 0-100"
assert.Assert(c, strings.Contains(out, expected), check.Commentf("Expected output to contain %q, not %q", out, expected))
assert.Assert(c, strings.Contains(out, expected), fmt.Sprintf("Expected output to contain %q, not %q", out, expected))
out, _, err = dockerCmdWithError("run", "--memory-swappiness", "-10", "busybox", "true")
assert.ErrorContains(c, err, "")
assert.Assert(c, strings.Contains(out, expected), check.Commentf("Expected output to contain %q, not %q", out, expected))
assert.Assert(c, strings.Contains(out, expected), fmt.Sprintf("Expected output to contain %q, not %q", out, expected))
}
func (s *DockerSuite) TestRunWithMemoryReservation(c *testing.T) {

View File

@ -137,13 +137,13 @@ func (s *DockerSuite) TestSaveImageId(c *testing.T) {
var err error
tarCmd.Stdin, err = saveCmd.StdoutPipe()
assert.Assert(c, err == nil, check.Commentf("cannot set stdout pipe for tar: %v", err))
assert.Assert(c, err == nil, fmt.Sprintf("cannot set stdout pipe for tar: %v", err))
grepCmd := exec.Command("grep", cleanedLongImageID)
grepCmd.Stdin, err = tarCmd.StdoutPipe()
assert.Assert(c, err == nil, check.Commentf("cannot set stdout pipe for grep: %v", err))
assert.Assert(c, err == nil, fmt.Sprintf("cannot set stdout pipe for grep: %v", err))
assert.Assert(c, tarCmd.Start() == nil, check.Commentf("tar failed with error: %v", err))
assert.Assert(c, saveCmd.Start() == nil, check.Commentf("docker save failed with error: %v", err))
assert.Assert(c, tarCmd.Start() == nil, fmt.Sprintf("tar failed with error: %v", err))
assert.Assert(c, saveCmd.Start() == nil, fmt.Sprintf("docker save failed with error: %v", err))
defer func() {
saveCmd.Wait()
tarCmd.Wait()
@ -152,7 +152,7 @@ func (s *DockerSuite) TestSaveImageId(c *testing.T) {
out, _, err = runCommandWithOutput(grepCmd)
assert.Assert(c, err == nil, check.Commentf("failed to save repo with image ID: %s, %v", out, err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to save repo with image ID: %s, %v", out, err))
}
// save a repo and try to load it using flags
@ -264,7 +264,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *testing.T) {
name := "save-directory-permissions"
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
assert.Assert(c, err == nil, check.Commentf("failed to create temporary directory: %s", err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to create temporary directory: %s", err))
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
os.Mkdir(extractionDirectory, 0777)

View File

@ -76,7 +76,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *testing.T) {
},
Data: []byte("TESTINGDATA"),
})
assert.Assert(c, id != "", check.Commentf("secrets: %s", id))
assert.Assert(c, id != "", fmt.Sprintf("secrets: %s", id))
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--secret", testName, "busybox", "top")
assert.NilError(c, err, out)
@ -118,7 +118,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *testi
},
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
})
assert.Assert(c, id != "", check.Commentf("secrets: %s", id))
assert.Assert(c, id != "", fmt.Sprintf("secrets: %s", id))
secretFlags = append(secretFlags, "--secret", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
}
@ -174,7 +174,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *testing
},
Data: []byte("TESTINGDATA"),
})
assert.Assert(c, id != "", check.Commentf("secrets: %s", id))
assert.Assert(c, id != "", fmt.Sprintf("secrets: %s", id))
serviceName := "svc"
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--secret", "source=mysecret,target=target1", "--secret", "source=mysecret,target=target2", "busybox", "top")
@ -224,7 +224,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *testing.T) {
},
Data: []byte("TESTINGDATA"),
})
assert.Assert(c, id != "", check.Commentf("configs: %s", id))
assert.Assert(c, id != "", fmt.Sprintf("configs: %s", id))
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--config", testName, "busybox", "top")
assert.NilError(c, err, out)
@ -265,7 +265,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *testi
},
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
})
assert.Assert(c, id != "", check.Commentf("configs: %s", id))
assert.Assert(c, id != "", fmt.Sprintf("configs: %s", id))
configFlags = append(configFlags, "--config", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
}
@ -321,7 +321,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *testing
},
Data: []byte("TESTINGDATA"),
})
assert.Assert(c, id != "", check.Commentf("configs: %s", id))
assert.Assert(c, id != "", fmt.Sprintf("configs: %s", id))
serviceName := "svc"
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--config", "source=myconfig,target=target1", "--config", "source=myconfig,target=target2", "busybox", "top")

View File

@ -66,7 +66,7 @@ func countLogLines(d *daemon.Daemon, name string) func(*testing.T) (interface{},
return 0, check.Commentf("Empty stdout")
}
lines := strings.Split(strings.TrimSpace(result.Stdout()), "\n")
return len(lines), check.Commentf("output, %q", string(result.Stdout()))
return len(lines), fmt.Sprintf("output, %q", string(result.Stdout()))
}
}

View File

@ -21,7 +21,7 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *testing.T) {
// Expect this to fail because the above container is stopped, this is what we want
out, _, err := dockerCmdWithError("run", "--name", "test2", "--link", "test:test", "busybox")
// err shouldn't be nil because container test2 try to link to stopped container
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
ch := make(chan error)
go func() {
@ -79,7 +79,7 @@ func (s *DockerSuite) TestStartRecordError(c *testing.T) {
// Expect this to fail and records error because of ports conflict
out, _, err := dockerCmdWithError("run", "-d", "--name", "test2", "-p", "9999:9999", "busybox", "top")
// err shouldn't be nil because docker run will fail
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
stateErr = inspectField(c, "test2", "State.Error")
assert.Assert(c, strings.Contains(stateErr, "port is already allocated"))
@ -101,7 +101,7 @@ func (s *DockerSuite) TestStartPausedContainer(c *testing.T) {
out, _, err := dockerCmdWithError("start", "testing")
// an error should have been shown that you cannot start paused container
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
// an error should have been shown that you cannot start paused container
assert.Assert(c, strings.Contains(strings.ToLower(out), "cannot start a paused container, try unpause instead"))
}
@ -129,7 +129,7 @@ func (s *DockerSuite) TestStartMultipleContainers(c *testing.T) {
expErr := "failed to start containers: [child_first]"
out, _, err := dockerCmdWithError("start", "child_first", "parent", "child_second")
// err shouldn't be nil because start will fail
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
// output does not correspond to what was expected
if !(strings.Contains(out, expOut) || strings.Contains(err.Error(), expErr)) {
c.Fatalf("Expected out: %v with err: %v but got out: %v with err: %v", expOut, expErr, out, err)
@ -157,7 +157,7 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *testing.T) {
for _, option := range []string{"-a", "-i", "-ai"} {
out, _, err := dockerCmdWithError("start", option, "test1", "test2", "test3")
// err shouldn't be nil because start will fail
assert.Assert(c, err != nil, check.Commentf("out: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("out: %s", out))
// output does not correspond to what was expected
assert.Assert(c, strings.Contains(out, "you cannot start and attach multiple containers at once"))
}
@ -192,9 +192,9 @@ func (s *DockerSuite) TestStartReturnCorrectExitCode(c *testing.T) {
out, exitCode, err := dockerCmdWithError("start", "-a", "withRestart")
assert.ErrorContains(c, err, "")
assert.Equal(c, exitCode, 11, check.Commentf("out: %s", out))
assert.Equal(c, exitCode, 11, fmt.Sprintf("out: %s", out))
out, exitCode, err = dockerCmdWithError("start", "-a", "withRm")
assert.ErrorContains(c, err, "")
assert.Equal(c, exitCode, 12, check.Commentf("out: %s", out))
assert.Equal(c, exitCode, 12, fmt.Sprintf("out: %s", out))
}

View File

@ -171,7 +171,7 @@ func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *testing.T) {
func (s *DockerSwarmSuite) TestSwarmServiceTemplatingHostname(c *testing.T) {
d := s.AddDaemon(c, true, true)
hostname, err := d.Cmd("node", "inspect", "--format", "{{.Description.Hostname}}", "self")
assert.Assert(c, err == nil, check.Commentf("%s", hostname))
assert.Assert(c, err == nil, fmt.Sprintf("%s", hostname))
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "test", "--hostname", "{{.Service.Name}}-{{.Task.Slot}}-{{.Node.Hostname}}", "busybox", "top")
assert.NilError(c, err, out)
@ -607,14 +607,14 @@ func (s *DockerSwarmSuite) TestPsListContainersFilterIsTask(c *testing.T) {
out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=false")
assert.NilError(c, err, out)
psOut := strings.TrimSpace(out)
assert.Equal(c, psOut, bareID, check.Commentf("Expected id %s, got %s for is-task label, output %q", bareID, psOut, out))
assert.Equal(c, psOut, bareID, fmt.Sprintf("Expected id %s, got %s for is-task label, output %q", bareID, psOut, out))
// Filter tasks
out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=true")
assert.NilError(c, err, out)
lines := strings.Split(strings.Trim(out, "\n "), "\n")
assert.Equal(c, len(lines), 1)
assert.Assert(c, lines[0] != bareID, check.Commentf("Expected not %s, but got it for is-task label, output %q", bareID, out))
assert.Assert(c, lines[0] != bareID, fmt.Sprintf("Expected not %s, but got it for is-task label, output %q", bareID, out))
}
const globalNetworkPlugin = "global-network-plugin"
@ -847,7 +847,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
out, err = d.Cmd("exec", id, "cat", "/status")
assert.NilError(c, err, out)
assert.Assert(c, strings.Contains(out, expectedOutput), check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
// Remove service
out, err = d.Cmd("service", "rm", name)
assert.NilError(c, err, out)
@ -869,7 +869,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *testing.T) {
out, err = d.Cmd("exec", id, "cat", "/status")
assert.NilError(c, err, out)
assert.Assert(c, strings.Contains(out, expectedOutput), check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
}
func (s *DockerSwarmSuite) TestSwarmServiceTTYUpdate(c *testing.T) {
@ -956,9 +956,9 @@ func (s *DockerSwarmSuite) TestDNSConfig(c *testing.T) {
expectedOutput3 := "options timeout:3"
out, err = d.Cmd("exec", id, "cat", "/etc/resolv.conf")
assert.NilError(c, err, out)
assert.Assert(c, strings.Contains(out, expectedOutput1), check.Commentf("Expected '%s', but got %q", expectedOutput1, out))
assert.Assert(c, strings.Contains(out, expectedOutput2), check.Commentf("Expected '%s', but got %q", expectedOutput2, out))
assert.Assert(c, strings.Contains(out, expectedOutput3), check.Commentf("Expected '%s', but got %q", expectedOutput3, out))
assert.Assert(c, strings.Contains(out, expectedOutput1), fmt.Sprintf("Expected '%s', but got %q", expectedOutput1, out))
assert.Assert(c, strings.Contains(out, expectedOutput2), fmt.Sprintf("Expected '%s', but got %q", expectedOutput2, out))
assert.Assert(c, strings.Contains(out, expectedOutput3), fmt.Sprintf("Expected '%s', but got %q", expectedOutput3, out))
}
func (s *DockerSwarmSuite) TestDNSConfigUpdate(c *testing.T) {
@ -1045,7 +1045,7 @@ func (s *DockerSwarmSuite) TestSwarmInitLocked(c *testing.T) {
d := s.AddDaemon(c, false, false)
outs, err := d.Cmd("swarm", "init", "--autolock")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
unlockKey := getUnlockKey(d, c, outs)
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
@ -1070,15 +1070,15 @@ func (s *DockerSwarmSuite) TestSwarmInitLocked(c *testing.T) {
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
outs, err = d.Cmd("node", "ls")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, !strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"))
outs, err = d.Cmd("swarm", "update", "--autolock=false")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
checkSwarmLockedToUnlocked(c, d)
outs, err = d.Cmd("node", "ls")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, !strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"))
}
@ -1086,7 +1086,7 @@ func (s *DockerSwarmSuite) TestSwarmLeaveLocked(c *testing.T) {
d := s.AddDaemon(c, false, false)
outs, err := d.Cmd("swarm", "init", "--autolock")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
// It starts off locked
d.RestartNode(c)
@ -1101,13 +1101,13 @@ func (s *DockerSwarmSuite) TestSwarmLeaveLocked(c *testing.T) {
assert.Assert(c, strings.Contains(outs, "Swarm is encrypted and locked."))
// It is OK for user to leave a locked swarm with --force
outs, err = d.Cmd("swarm", "leave", "--force")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
info = d.SwarmInfo(c)
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
outs, err = d.Cmd("swarm", "init")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
info = d.SwarmInfo(c)
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
@ -1127,7 +1127,7 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *testing.T) {
// enable autolock
outs, err := d1.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
unlockKey := getUnlockKey(d1, c, outs)
// The ones that got the cluster update should be set to locked
@ -1149,7 +1149,7 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *testing.T) {
// leave it locked, and set the cluster to no longer autolock
outs, err = d1.Cmd("swarm", "update", "--autolock=false")
assert.Assert(c, err == nil, check.Commentf("out: %v", outs))
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
// the ones that got the update are now set to unlocked
for _, d := range []*daemon.Daemon{d1, d3} {
@ -1179,7 +1179,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
// enable autolock
outs, err := d1.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, check.Commentf("out: %v", outs))
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
unlockKey := getUnlockKey(d1, c, outs)
// joined workers start off unlocked
@ -1217,7 +1217,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) {
waitAndAssert(c, defaultReconciliationTimeout, func(c *testing.T) (interface{}, check.CommentInterface) {
certBytes, err := ioutil.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt"))
if err != nil {
return "", check.Commentf("error: %v", err)
return "", fmt.Sprintf("error: %v", err)
}
certs, err := helpers.ParseCertificatesPEM(certBytes)
if err == nil && len(certs) > 0 && len(certs[0].Subject.OrganizationalUnit) > 0 {
@ -1235,13 +1235,13 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *testing.T) {
d := s.AddDaemon(c, true, true)
outs, err := d.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, check.Commentf("out: %v", outs))
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
unlockKey := getUnlockKey(d, c, outs)
// Rotate multiple times
for i := 0; i != 3; i++ {
outs, err = d.Cmd("swarm", "unlock-key", "-q", "--rotate")
assert.Assert(c, err == nil, check.Commentf("out: %v", outs))
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
// Strip \n
newUnlockKey := outs[:len(outs)-1]
assert.Assert(c, newUnlockKey != "")
@ -1322,13 +1322,13 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *testing.T) {
d3 := s.AddDaemon(c, true, true)
outs, err := d1.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
unlockKey := getUnlockKey(d1, c, outs)
// Rotate multiple times
for i := 0; i != 3; i++ {
outs, err = d1.Cmd("swarm", "unlock-key", "-q", "--rotate")
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
// Strip \n
newUnlockKey := outs[:len(outs)-1]
assert.Assert(c, newUnlockKey != "")
@ -1387,7 +1387,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *testing.T) {
continue
}
}
assert.Assert(c, err == nil, check.Commentf("%s", outs))
assert.Assert(c, err == nil, fmt.Sprintf("%s", outs))
assert.Assert(c, !strings.Contains(outs, "Swarm is encrypted and needs to be unlocked"))
break
}
@ -1403,7 +1403,7 @@ func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *testing.T) {
for i := 0; i < 2; i++ {
// set to lock
outs, err := d.Cmd("swarm", "update", "--autolock")
assert.Assert(c, err == nil, check.Commentf("out: %v", outs))
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
assert.Assert(c, strings.Contains(outs, "docker swarm unlock"))
unlockKey := getUnlockKey(d, c, outs)
@ -1416,7 +1416,7 @@ func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *testing.T) {
assert.Equal(c, getNodeStatus(c, d), swarm.LocalNodeStateActive)
outs, err = d.Cmd("swarm", "update", "--autolock=false")
assert.Assert(c, err == nil, check.Commentf("out: %v", outs))
assert.Assert(c, err == nil, fmt.Sprintf("out: %v", outs))
checkSwarmLockedToUnlocked(c, d)
}
@ -1442,7 +1442,7 @@ func (s *DockerSwarmSuite) TestExtraHosts(c *testing.T) {
expectedOutput := "1.2.3.4\texample.com"
out, err = d.Cmd("exec", id, "cat", "/etc/hosts")
assert.NilError(c, err, out)
assert.Assert(c, strings.Contains(out, expectedOutput), check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, strings.Contains(out, expectedOutput), fmt.Sprintf("Expected '%s', but got %q", expectedOutput, out))
}
func (s *DockerSwarmSuite) TestSwarmManagerAddress(c *testing.T) {
@ -1952,7 +1952,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSecret(c *testing.T) {
},
Data: []byte("TESTINGDATA"),
})
assert.Assert(c, id != "", check.Commentf("secrets: %s", id))
assert.Assert(c, id != "", fmt.Sprintf("secrets: %s", id))
waitForEvent(c, d, "0", "-f scope=swarm", "secret create "+id, defaultRetryCount)
@ -1972,7 +1972,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *testing.T) {
},
Data: []byte("TESTINGDATA"),
})
assert.Assert(c, id != "", check.Commentf("configs: %s", id))
assert.Assert(c, id != "", fmt.Sprintf("configs: %s", id))
waitForEvent(c, d, "0", "-f scope=swarm", "config create "+id, defaultRetryCount)
@ -1984,7 +1984,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *testing.T) {
func getUnlockKey(d *daemon.Daemon, c *testing.T, autolockOutput string) string {
unlockKey, err := d.Cmd("swarm", "unlock-key", "-q")
assert.Assert(c, err == nil, check.Commentf("%s", unlockKey))
assert.Assert(c, err == nil, fmt.Sprintf("%s", unlockKey))
unlockKey = strings.TrimSuffix(unlockKey, "\n")
// Check that "docker swarm init --autolock" or "docker swarm update --autolock"

View File

@ -38,7 +38,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
// we need to find the uid and gid of the remapped root from the daemon's root dir info
uidgid := strings.Split(filepath.Base(s.d.Root), ".")
assert.Equal(c, len(uidgid), 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.Root)))
assert.Equal(c, len(uidgid), 2, fmt.Sprintf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.Root)))
uid, err := strconv.Atoi(uidgid[0])
assert.NilError(c, err, "Can't parse uid")
gid, err := strconv.Atoi(uidgid[1])
@ -60,7 +60,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
assert.Equal(c, statNotExists.GID(), uint32(gid), check.Commentf("Created directory not owned by remapped root GID"))
pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns")
assert.Assert(c, err == nil, check.Commentf("Could not inspect running container: out: %q", pid))
assert.Assert(c, err == nil, fmt.Sprintf("Could not inspect running container: out: %q", pid))
// check the uid and gid maps for the PID to ensure root is remapped
// (cmd = cat /proc/<pid>/uid_map | grep -E '0\s+9999\s+1')
_, err = RunCommandPipelineWithOutput(
@ -81,7 +81,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
// use host usernamespace
out, err = s.d.Cmd("run", "-d", "--name", "userns_skip", "--userns", "host", "busybox", "sh", "-c", "touch /goofy/testfile; top")
assert.Assert(c, err == nil, check.Commentf("Output: %s", out))
assert.Assert(c, err == nil, fmt.Sprintf("Output: %s", out))
user = s.findUser(c, "userns_skip")
// userns are skipped, user is root
assert.Equal(c, user, "root")
@ -90,7 +90,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
// findUser finds the uid or name of the user of the first process that runs in a container
func (s *DockerDaemonSuite) findUser(c *testing.T, container string) string {
out, err := s.d.Cmd("top", container)
assert.Assert(c, err == nil, check.Commentf("Output: %s", out))
assert.Assert(c, err == nil, fmt.Sprintf("Output: %s", out))
rows := strings.Split(out, "\n")
if len(rows) < 2 {
// No process rows founds

View File

@ -147,13 +147,13 @@ func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *testing.T) {
// Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output
assert.Assert(c, strings.Contains(out, "testnotinuse1\n"), check.Commentf("expected volume 'testnotinuse1' in output"))
assert.Assert(c, !strings.Contains(out, "testisinuse1\n"), check.Commentf("volume 'testisinuse1' in output, but not expected"))
assert.Assert(c, !strings.Contains(out, "testisinuse2\n"), check.Commentf("volume 'testisinuse2' in output, but not expected"))
assert.Assert(c, !strings.Contains(out, "testisinuse1\n"), fmt.Sprintf("volume 'testisinuse1' in output, but not expected"))
assert.Assert(c, !strings.Contains(out, "testisinuse2\n"), fmt.Sprintf("volume 'testisinuse2' in output, but not expected"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=1")
// Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output, dangling also accept 1
assert.Assert(c, strings.Contains(out, "testnotinuse1\n"), check.Commentf("expected volume 'testnotinuse1' in output"))
assert.Assert(c, !strings.Contains(out, "testisinuse1\n"), check.Commentf("volume 'testisinuse1' in output, but not expected"))
assert.Assert(c, !strings.Contains(out, "testisinuse2\n"), check.Commentf("volume 'testisinuse2' in output, but not expected"))
assert.Assert(c, !strings.Contains(out, "testisinuse1\n"), fmt.Sprintf("volume 'testisinuse1' in output, but not expected"))
assert.Assert(c, !strings.Contains(out, "testisinuse2\n"), fmt.Sprintf("volume 'testisinuse2' in output, but not expected"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=0")
// dangling=0 is same as dangling=false case
assert.Assert(c, !strings.Contains(out, "testnotinuse1\n"), check.Commentf("expected volume 'testnotinuse1' in output"))
@ -236,8 +236,8 @@ func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *testing.T) {
name := strings.TrimSpace(out)
out, exitCode, err := dockerCmdWithError("volume", "inspect", "--format='{{ .FooBar }}'", name)
assert.Assert(c, err != nil, check.Commentf("Output: %s", out))
assert.Equal(c, exitCode, 1, check.Commentf("Output: %s", out))
assert.Assert(c, err != nil, fmt.Sprintf("Output: %s", out))
assert.Equal(c, exitCode, 1, fmt.Sprintf("Output: %s", out))
assert.Assert(c, strings.Contains(out, "Template parsing error"))
}
@ -325,11 +325,11 @@ func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *testing.T) {
assert.Assert(c, !strings.Contains(out, "testvolcreatelabel-2\n"), check.Commentf("expected volume 'testvolcreatelabel-2 in output"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=non-exist")
outArr := strings.Split(strings.TrimSpace(out), "\n")
assert.Equal(c, len(outArr), 1, check.Commentf("\n%s", out))
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=non-exist")
outArr = strings.Split(strings.TrimSpace(out), "\n")
assert.Equal(c, len(outArr), 1, check.Commentf("\n%s", out))
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
}
func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *testing.T) {
@ -349,17 +349,17 @@ func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *testing.T) {
// filter with driver=invaliddriver
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invaliddriver")
outArr := strings.Split(strings.TrimSpace(out), "\n")
assert.Equal(c, len(outArr), 1, check.Commentf("\n%s", out))
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
// filter with driver=loca
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loca")
outArr = strings.Split(strings.TrimSpace(out), "\n")
assert.Equal(c, len(outArr), 1, check.Commentf("\n%s", out))
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
// filter with driver=
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=")
outArr = strings.Split(strings.TrimSpace(out), "\n")
assert.Equal(c, len(outArr), 1, check.Commentf("\n%s", out))
assert.Equal(c, len(outArr), 1, fmt.Sprintf("\n%s", out))
}
func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *testing.T) {
@ -475,7 +475,7 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *testing.T) {
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data1))
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data2))
out, _, err := dockerCmdWithError("run", "--name=app", "--volumes-from=data1", "--volumes-from=data2", "-d", "busybox", "top")
assert.Assert(c, err == nil, check.Commentf("Out: %s", out))
assert.Assert(c, err == nil, fmt.Sprintf("Out: %s", out))
// Only the second volume will be referenced, this is backward compatible
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "app")
@ -517,7 +517,7 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *testing.T
assert.Assert(c, strings.Contains(strings.TrimSpace(out), data2))
// /tmp/data is automatically created, because we are not using the modern mount API here
out, _, err := dockerCmdWithError("run", "--name=app", "--volumes-from=data1", "--volumes-from=data2", "-v", "/tmp/data:/tmp/data", "-d", "busybox", "top")
assert.Assert(c, err == nil, check.Commentf("Out: %s", out))
assert.Assert(c, err == nil, fmt.Sprintf("Out: %s", out))
// No volume will be referenced (mount is /tmp/data), this is backward compatible
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "app")

View File

@ -71,7 +71,7 @@ func (s *DockerHubPullSuite) TearDownTest(c *testing.T) {
// output. The function fails the test when the command returns an error.
func (s *DockerHubPullSuite) Cmd(c *testing.T, name string, arg ...string) string {
out, err := s.CmdWithError(name, arg...)
assert.Assert(c, err == nil, check.Commentf("%q failed with errors: %s, %v", strings.Join(arg, " "), out, err))
assert.Assert(c, err == nil, fmt.Sprintf("%q failed with errors: %s, %v", strings.Join(arg, " "), out, err))
return out
}

View File

@ -78,7 +78,7 @@ func inspectFieldAndUnmarshall(c *testing.T, name, field string, output interfac
str := inspectFieldJSON(c, name, field)
err := json.Unmarshal([]byte(str), output)
if c != nil {
assert.Assert(c, err == nil, check.Commentf("failed to unmarshal: %v", err))
assert.Assert(c, err == nil, fmt.Sprintf("failed to unmarshal: %v", err))
}
}
@ -455,7 +455,7 @@ func reducedCheck(r reducer, funcs ...checkF) checkF {
comments = append(comments, comment.CheckCommentString())
}
}
return r(values...), check.Commentf("%v", strings.Join(comments, ", "))
return r(values...), fmt.Sprintf("%v", strings.Join(comments, ", "))
}
}