rm-gocheck: c.Assert(...) -> assert.Assert(c, ...)

sed -E -i 's#\bc\.Assert\(#assert.Assert(c, #g' \
-- "integration-cli/docker_api_containers_test.go" "integration-cli/docker_api_swarm_node_test.go" "integration-cli/docker_cli_attach_test.go" "integration-cli/docker_cli_attach_unix_test.go" "integration-cli/docker_cli_build_test.go" "integration-cli/docker_cli_build_unix_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_health_test.go" "integration-cli/docker_cli_history_test.go" "integration-cli/docker_cli_images_test.go" "integration-cli/docker_cli_import_test.go" "integration-cli/docker_cli_info_test.go" "integration-cli/docker_cli_info_unix_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_prune_unix_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_health_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" "pkg/discovery/discovery_test.go" "pkg/discovery/file/file_test.go" "pkg/discovery/generator_test.go" "pkg/discovery/kv/kv_test.go" "pkg/discovery/memory/memory_test.go" "pkg/discovery/nodes/nodes_test.go"

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2019-09-09 21:05:55 +00:00
parent 36e7001b99
commit 1f69c62540
46 changed files with 1743 additions and 1743 deletions

View file

@ -53,7 +53,7 @@ func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) {
assert.NilError(c, err)
assert.Equal(c, len(containers), startCount+1)
actual := containers[0].Names[0]
c.Assert(actual, checker.Equals, "/"+name)
assert.Assert(c, actual, checker.Equals, "/"+name)
}
// regression test for empty json field being omitted #13691
@ -121,7 +121,7 @@ func (s *DockerSuite) TestContainerAPIGetExport(c *check.C) {
break
}
}
c.Assert(found, checker.True, check.Commentf("The created test file has not been found in the exported image"))
assert.Assert(c, found, checker.True, check.Commentf("The created test file has not been found in the exported image"))
}
func (s *DockerSuite) TestContainerAPIGetChanges(c *check.C) {
@ -144,7 +144,7 @@ func (s *DockerSuite) TestContainerAPIGetChanges(c *check.C) {
success = true
}
}
c.Assert(success, checker.True, check.Commentf("/etc/passwd has been removed but is not present in the diff"))
assert.Assert(c, success, checker.True, check.Commentf("/etc/passwd has been removed but is not present in the diff"))
}
func (s *DockerSuite) TestGetContainerStats(c *check.C) {
@ -215,12 +215,12 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
// Now remove without `-f` and make sure we are still pulling stats
_, _, err = dockerCmdWithError("rm", id)
c.Assert(err, checker.Not(checker.IsNil), check.Commentf("rm should have failed but didn't"))
assert.Assert(c, err, checker.Not(checker.IsNil), check.Commentf("rm should have failed but didn't"))
_, err = buf.ReadTimeout(b, 2*time.Second)
assert.NilError(c, err)
dockerCmd(c, "rm", "-f", id)
c.Assert(<-chErr, checker.IsNil)
assert.Assert(c, <-chErr, checker.IsNil)
}
// ChannelBuffer holds a chan of byte array that can be populate in a goroutine.
@ -389,7 +389,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
assert.NilError(c, err)
pausedContainers = getPaused(c)
c.Assert(pausedContainers, checker.HasLen, 0, check.Commentf("There should be no paused container."))
assert.Assert(c, pausedContainers, checker.HasLen, 0, check.Commentf("There should be no paused container."))
}
func (s *DockerSuite) TestContainerAPITop(c *check.C) {
@ -405,14 +405,14 @@ func (s *DockerSuite) TestContainerAPITop(c *check.C) {
// 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)
c.Assert(top.Titles, checker.HasLen, 11, check.Commentf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles))
assert.Assert(c, top.Titles, checker.HasLen, 11, check.Commentf("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)
}
c.Assert(top.Processes, checker.HasLen, 2, check.Commentf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
c.Assert(top.Processes[0][10], checker.Equals, "/bin/sh -c top")
c.Assert(top.Processes[1][10], checker.Equals, "top")
assert.Assert(c, top.Processes, checker.HasLen, 2, check.Commentf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
assert.Assert(c, top.Processes[0][10], checker.Equals, "/bin/sh -c top")
assert.Assert(c, top.Processes[1][10], checker.Equals, "top")
}
func (s *DockerSuite) TestContainerAPITopWindows(c *check.C) {
@ -462,7 +462,7 @@ func (s *DockerSuite) TestContainerAPICommit(c *check.C) {
assert.NilError(c, err)
cmd := inspectField(c, img.ID, "Config.Cmd")
c.Assert(cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd))
assert.Assert(c, cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("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")
@ -488,13 +488,13 @@ func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *check.C) {
assert.NilError(c, err)
label1 := inspectFieldMap(c, img.ID, "Config.Labels", "key1")
c.Assert(label1, checker.Equals, "value1")
assert.Assert(c, label1, checker.Equals, "value1")
label2 := inspectFieldMap(c, img.ID, "Config.Labels", "key2")
c.Assert(label2, checker.Equals, "value2")
assert.Assert(c, label2, checker.Equals, "value2")
cmd := inspectField(c, img.ID, "Config.Cmd")
c.Assert(cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("got wrong Cmd from commit: %q", cmd))
assert.Assert(c, cmd, checker.Equals, "[/bin/sh -c touch /test]", check.Commentf("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")
@ -577,10 +577,10 @@ func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *check.C) {
_, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networkingConfig, "")
msg := err.Error()
// network name order in error message is not deterministic
c.Assert(msg, checker.Contains, "Container cannot be connected to network endpoints")
c.Assert(msg, checker.Contains, "net1")
c.Assert(msg, checker.Contains, "net2")
c.Assert(msg, checker.Contains, "net3")
assert.Assert(c, msg, checker.Contains, "Container cannot be connected to network endpoints")
assert.Assert(c, msg, checker.Contains, "net1")
assert.Assert(c, msg, checker.Contains, "net2")
assert.Assert(c, msg, checker.Contains, "net3")
}
func (s *DockerSuite) TestContainerAPICreateBridgeNetworkMode(c *check.C) {
@ -615,7 +615,7 @@ func UtilCreateNetworkMode(c *check.C, networkMode containertypes.NetworkMode) {
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
assert.NilError(c, err)
c.Assert(containerJSON.HostConfig.NetworkMode, checker.Equals, containertypes.NetworkMode(networkMode), check.Commentf("Mismatched NetworkMode"))
assert.Assert(c, containerJSON.HostConfig.NetworkMode, checker.Equals, containertypes.NetworkMode(networkMode), check.Commentf("Mismatched NetworkMode"))
}
func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) {
@ -646,7 +646,7 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) {
assert.Equal(c, out, "512")
outCpuset := inspectField(c, containerJSON.ID, "HostConfig.CpusetCpus")
c.Assert(outCpuset, checker.Equals, "0")
assert.Assert(c, outCpuset, checker.Equals, "0")
}
func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
@ -656,7 +656,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
create := func(ct string) (*http.Response, io.ReadCloser, error) {
jsonData := bytes.NewBuffer(nil)
c.Assert(json.NewEncoder(jsonData).Encode(config), checker.IsNil)
assert.Assert(c, json.NewEncoder(jsonData).Encode(config), checker.IsNil)
return request.Post("/containers/create", request.RawContent(ioutil.NopCloser(jsonData)), request.ContentType(ct))
}
@ -668,7 +668,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
assert.Assert(c, res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
body.Close()
@ -678,7 +678,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
assert.Assert(c, res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
body.Close()
@ -708,12 +708,12 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
assert.Assert(c, res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
b, err := request.ReadBody(body)
assert.NilError(c, err)
c.Assert(string(b[:]), checker.Contains, "invalid port")
assert.Assert(c, string(b[:]), checker.Contains, "invalid port")
}
func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C) {
@ -732,12 +732,12 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
assert.Assert(c, res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
b, err := request.ReadBody(body)
assert.NilError(c, err)
c.Assert(string(b[:]), checker.Contains, "invalid restart policy")
assert.Assert(c, string(b[:]), checker.Contains, "invalid restart policy")
}
func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
@ -756,12 +756,12 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
assert.Assert(c, res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
b, err := request.ReadBody(body)
assert.NilError(c, err)
c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be used with restart policy")
assert.Assert(c, string(b[:]), checker.Contains, "maximum retry count cannot be used with restart policy")
}
func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C) {
@ -780,12 +780,12 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
assert.Assert(c, res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
b, err := request.ReadBody(body)
assert.NilError(c, err)
c.Assert(string(b[:]), checker.Contains, "maximum retry count cannot be negative")
assert.Assert(c, string(b[:]), checker.Contains, "maximum retry count cannot be negative")
}
func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *check.C) {
@ -840,14 +840,14 @@ func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) {
ID string
}
var container createResp
c.Assert(json.Unmarshal(b, &container), checker.IsNil)
assert.Assert(c, json.Unmarshal(b, &container), checker.IsNil)
out := inspectField(c, container.ID, "HostConfig.CpusetCpus")
assert.Equal(c, out, "")
outMemory := inspectField(c, container.ID, "HostConfig.Memory")
c.Assert(outMemory, checker.Equals, "0")
assert.Assert(c, outMemory, checker.Equals, "0")
outMemorySwap := inspectField(c, container.ID, "HostConfig.MemorySwap")
c.Assert(outMemorySwap, checker.Equals, "0")
assert.Assert(c, outMemorySwap, checker.Equals, "0")
}
func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
@ -864,14 +864,14 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
assert.NilError(c, err)
b, err2 := request.ReadBody(body)
c.Assert(err2, checker.IsNil)
assert.Assert(c, err2, checker.IsNil)
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
assert.Assert(c, res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
c.Assert(string(b), checker.Contains, "Minimum memory limit allowed is 4MB")
assert.Assert(c, string(b), checker.Contains, "Minimum memory limit allowed is 4MB")
}
func (s *DockerSuite) TestContainerAPIRename(c *check.C) {
@ -888,7 +888,7 @@ func (s *DockerSuite) TestContainerAPIRename(c *check.C) {
assert.NilError(c, err)
name := inspectField(c, containerID, "Name")
c.Assert(name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container"))
assert.Assert(c, name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container"))
}
func (s *DockerSuite) TestContainerAPIKill(c *check.C) {
@ -903,7 +903,7 @@ func (s *DockerSuite) TestContainerAPIKill(c *check.C) {
assert.NilError(c, err)
state := inspectField(c, name, "State.Running")
c.Assert(state, checker.Equals, "false", check.Commentf("got wrong State from container %s: %q", name, state))
assert.Assert(c, state, checker.Equals, "false", check.Commentf("got wrong State from container %s: %q", name, state))
}
func (s *DockerSuite) TestContainerAPIRestart(c *check.C) {
@ -917,7 +917,7 @@ func (s *DockerSuite) TestContainerAPIRestart(c *check.C) {
err = cli.ContainerRestart(context.Background(), name, &timeout)
assert.NilError(c, err)
c.Assert(waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil)
assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil)
}
func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *check.C) {
@ -933,7 +933,7 @@ func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *check.C) {
err = cli.ContainerRestart(context.Background(), name, nil)
assert.NilError(c, err)
c.Assert(waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil)
assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil)
}
func (s *DockerSuite) TestContainerAPIStart(c *check.C) {
@ -973,7 +973,7 @@ func (s *DockerSuite) TestContainerAPIStop(c *check.C) {
err = cli.ContainerStop(context.Background(), name, &timeout)
assert.NilError(c, err)
c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
assert.Assert(c, waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
// second call to start should give 304
// maybe add ContainerStartWithRaw to test it
@ -1000,7 +1000,7 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) {
case err = <-errC:
assert.NilError(c, err)
case waitres := <-waitresC:
c.Assert(waitres.StatusCode, checker.Equals, int64(0))
assert.Assert(c, waitres.StatusCode, checker.Equals, int64(0))
}
}
@ -1044,7 +1044,7 @@ func (s *DockerSuite) TestContainerAPICopyPre124(c *check.C) {
break
}
}
c.Assert(found, checker.True)
assert.Assert(c, found, checker.True)
}
func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *check.C) {
@ -1061,11 +1061,11 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPre124(c *check.C) {
if versions.GreaterThanOrEqualTo(testEnv.DaemonAPIVersion(), "1.32") {
assert.Equal(c, res.StatusCode, http.StatusBadRequest)
} else {
c.Assert(res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
assert.Assert(c, res.StatusCode, checker.Not(checker.Equals), http.StatusOK)
}
b, err := request.ReadBody(body)
assert.NilError(c, err)
c.Assert(string(b), checker.Matches, "Path cannot be empty\n")
assert.Assert(c, string(b), checker.Matches, "Path cannot be empty\n")
}
func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *check.C) {
@ -1086,7 +1086,7 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *check.C)
}
b, err := request.ReadBody(body)
assert.NilError(c, err)
c.Assert(string(b), checker.Matches, "Could not find the file /notexist in container "+name+"\n")
assert.Assert(c, string(b), checker.Matches, "Could not find the file /notexist in container "+name+"\n")
}
func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *check.C) {
@ -1153,10 +1153,10 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *check.C) {
out, _ = dockerCmd(c, "run", "--link", "tlink1:tlink1", "--name", "tlink2", "-d", "busybox", "top")
id2 := strings.TrimSpace(out)
c.Assert(waitRun(id2), checker.IsNil)
assert.Assert(c, waitRun(id2), checker.IsNil)
links := inspectFieldJSON(c, id2, "HostConfig.Links")
c.Assert(links, checker.Equals, "[\"/tlink1:/tlink2/tlink1\"]", check.Commentf("expected to have links between containers"))
assert.Assert(c, links, checker.Equals, "[\"/tlink1:/tlink2/tlink1\"]", check.Commentf("expected to have links between containers"))
removeOptions := types.ContainerRemoveOptions{
RemoveLinks: true,
@ -1170,7 +1170,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *check.C) {
assert.NilError(c, err)
linksPostRm := inspectFieldJSON(c, id2, "HostConfig.Links")
c.Assert(linksPostRm, checker.Equals, "null", check.Commentf("call to api deleteContainer links should have removed the specified links"))
assert.Assert(c, linksPostRm, checker.Equals, "null", check.Commentf("call to api deleteContainer links should have removed the specified links"))
}
func (s *DockerSuite) TestContainerAPIDeleteConflict(c *check.C) {
@ -1219,7 +1219,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
assert.NilError(c, err)
_, err = os.Stat(source)
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("expected to get ErrNotExist error, got %v", err))
assert.Assert(c, os.IsNotExist(err), checker.True, check.Commentf("expected to get ErrNotExist error, got %v", err))
}
// Regression test for https://github.com/docker/docker/issues/6231
@ -1238,7 +1238,7 @@ func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *check.C) {
req.ContentLength = -1
return nil
}))
c.Assert(err, checker.IsNil, check.Commentf("error creating container with chunked encoding"))
assert.Assert(c, err, checker.IsNil, check.Commentf("error creating container with chunked encoding"))
defer resp.Body.Close()
assert.Equal(c, resp.StatusCode, http.StatusCreated)
}
@ -1247,7 +1247,7 @@ func (s *DockerSuite) TestContainerAPIPostContainerStop(c *check.C) {
out := runSleepingContainer(c)
containerID := strings.TrimSpace(out)
c.Assert(waitRun(containerID), checker.IsNil)
assert.Assert(c, waitRun(containerID), checker.IsNil)
cli, err := client.NewClientWithOpts(client.FromEnv)
assert.NilError(c, err)
@ -1255,7 +1255,7 @@ func (s *DockerSuite) TestContainerAPIPostContainerStop(c *check.C) {
err = cli.ContainerStop(context.Background(), containerID, nil)
assert.NilError(c, err)
c.Assert(waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
assert.Assert(c, waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
}
// #14170
@ -1457,7 +1457,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
assert.NilError(c, err)
c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, defaultSHMSize)
assert.Assert(c, containerJSON.HostConfig.ShmSize, check.Equals, defaultSHMSize)
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
@ -1484,7 +1484,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) {
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
assert.NilError(c, err)
c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, int64(67108864))
assert.Assert(c, containerJSON.HostConfig.ShmSize, check.Equals, int64(67108864))
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`)
@ -1515,7 +1515,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) {
containerJSON, err := cli.ContainerInspect(context.Background(), container.ID)
assert.NilError(c, err)
c.Assert(containerJSON.HostConfig.ShmSize, check.Equals, int64(1073741824))
assert.Assert(c, containerJSON.HostConfig.ShmSize, check.Equals, int64(1073741824))
out, _ := dockerCmd(c, "start", "-i", containerJSON.ID)
shmRegex := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=1048576k`)
@ -1542,9 +1542,9 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
assert.NilError(c, err)
if versions.LessThan(testEnv.DaemonAPIVersion(), "1.31") {
c.Assert(*containerJSON.HostConfig.MemorySwappiness, check.Equals, int64(-1))
assert.Assert(c, *containerJSON.HostConfig.MemorySwappiness, check.Equals, int64(-1))
} else {
c.Assert(containerJSON.HostConfig.MemorySwappiness, check.IsNil)
assert.Assert(c, containerJSON.HostConfig.MemorySwappiness, check.IsNil)
}
}
@ -1614,7 +1614,7 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
err = cli.ContainerStart(context.Background(), name, types.ContainerStartOptions{})
assert.NilError(c, err)
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
type b struct {
stats types.ContainerStats
@ -1636,7 +1636,7 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
case <-time.After(2 * time.Second):
c.Fatal("stream was not closed after container was removed")
case sr := <-bc:
c.Assert(sr.err, checker.IsNil)
assert.Assert(c, sr.err, checker.IsNil)
sr.stats.Body.Close()
}
}
@ -2052,7 +2052,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
assert.NilError(c, err)
defer os.RemoveAll(tmpDir3)
c.Assert(mount.Mount(tmpDir3, tmpDir3, "none", "bind,shared"), checker.IsNil)
assert.Assert(c, mount.Mount(tmpDir3, tmpDir3, "none", "bind,shared"), checker.IsNil)
cases = append(cases, []testCase{
{
@ -2219,7 +2219,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) {
assert.NilError(c, err)
out, _ := dockerCmd(c, "start", "-a", cName)
for _, option := range x.expectedOptions {
c.Assert(out, checker.Contains, option)
assert.Assert(c, out, checker.Contains, option)
}
}
}

View file

@ -17,7 +17,7 @@ func (s *DockerSwarmSuite) TestAPISwarmListNodes(c *check.C) {
d3 := s.AddDaemon(c, true, false)
nodes := d1.ListNodes(c)
c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
assert.Assert(c, len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
loop0:
for _, n := range nodes {
@ -40,7 +40,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeUpdate(c *check.C) {
})
n := d.GetNode(c, nodes[0].ID)
c.Assert(n.Spec.Availability, checker.Equals, swarm.NodeAvailabilityPause)
assert.Assert(c, n.Spec.Availability, checker.Equals, swarm.NodeAvailabilityPause)
}
func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
@ -50,7 +50,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
_ = s.AddDaemon(c, true, false)
nodes := d1.ListNodes(c)
c.Assert(len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
assert.Assert(c, len(nodes), checker.Equals, 3, check.Commentf("nodes: %#v", nodes))
// Getting the info so we can take the NodeID
d2Info := d2.SwarmInfo(c)
@ -59,7 +59,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
d1.RemoveNode(c, d2Info.NodeID, true)
nodes = d1.ListNodes(c)
c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
assert.Assert(c, len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
// Restart the node that was removed
d2.RestartNode(c)
@ -69,7 +69,7 @@ func (s *DockerSwarmSuite) TestAPISwarmNodeRemove(c *check.C) {
// Make sure the node didn't rejoin
nodes = d1.ListNodes(c)
c.Assert(len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
assert.Assert(c, len(nodes), checker.Equals, 2, check.Commentf("nodes: %#v", nodes))
}
func (s *DockerSwarmSuite) TestAPISwarmNodeDrainPause(c *check.C) {

View file

@ -147,7 +147,7 @@ func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
stdout, err := cmd.StdoutPipe()
assert.NilError(c, err)
defer stdout.Close()
c.Assert(cmd.Start(), check.IsNil)
assert.Assert(c, cmd.Start(), check.IsNil)
defer func() {
cmd.Process.Kill()
cmd.Wait()
@ -157,13 +157,13 @@ func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
assert.NilError(c, err)
out, err = bufio.NewReader(stdout).ReadString('\n')
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "hello")
c.Assert(stdin.Close(), check.IsNil)
assert.Assert(c, stdin.Close(), check.IsNil)
// Expect container to still be running after stdin is closed
running := inspectField(c, id, "State.Running")
c.Assert(running, check.Equals, "true")
assert.Assert(c, running, check.Equals, "true")
}
func (s *DockerSuite) TestAttachPausedContainer(c *check.C) {

View file

@ -51,7 +51,7 @@ func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) {
case err := <-errChan:
tty.Close()
out, _ := ioutil.ReadAll(pty)
c.Assert(err, check.IsNil, check.Commentf("out: %v", string(out)))
assert.Assert(c, err, check.IsNil, check.Commentf("out: %v", string(out)))
case <-time.After(attachWait):
c.Fatal("timed out without attach returning")
}
@ -74,7 +74,7 @@ func (s *DockerSuite) TestAttachAfterDetach(c *check.C) {
close(cmdExit)
}()
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
cpty.Write([]byte{16})
time.Sleep(100 * time.Millisecond)

View file

@ -2082,7 +2082,7 @@ CMD ["cat", "/foo"]`),
}).Assert(c, icmd.Success)
res := inspectField(c, name, "Config.Cmd")
c.Assert(strings.TrimSpace(string(res)), checker.Equals, `[cat /foo]`)
assert.Assert(c, strings.TrimSpace(string(res)), checker.Equals, `[cat /foo]`)
}
// FIXME(vdemeester) migrate to docker/cli tests (unit or e2e)
@ -2142,9 +2142,9 @@ COPY . /baz`),
result = cli.DockerCmd(c, "run", "--rm", name, "ls", "-A", "/baz")
if hasDockerignore && !ignoreDockerignore {
c.Assert(result.Stdout(), checker.Equals, ".dockerignore\nfoo\n")
assert.Assert(c, result.Stdout(), checker.Equals, ".dockerignore\nfoo\n")
} else {
c.Assert(result.Stdout(), checker.Equals, "foo\n")
assert.Assert(c, result.Stdout(), checker.Equals, "foo\n")
}
}
@ -4178,7 +4178,7 @@ func (s *DockerSuite) TestBuildTimeArgHistoryExclusions(c *check.C) {
result.Assert(c, icmd.Expected{Out: fmt.Sprintf("%s=%s", explicitProxyKey, explicitProxyVal)})
cacheID := buildImage(imgName + "-two")
c.Assert(origID, checker.Equals, cacheID)
assert.Assert(c, origID, checker.Equals, cacheID)
}
func (s *DockerSuite) TestBuildBuildTimeArgCacheHit(c *check.C) {
@ -4373,7 +4373,7 @@ func (s *DockerSuite) TestBuildBuildTimeArgExpansion(c *check.C) {
)
res := inspectField(c, imgName, "Config.WorkingDir")
c.Assert(filepath.ToSlash(res), check.Equals, filepath.ToSlash(wdVal))
assert.Assert(c, filepath.ToSlash(res), check.Equals, filepath.ToSlash(wdVal))
var resArr []string
inspectFieldAndUnmarshall(c, imgName, "Config.Env", &resArr)
@ -4579,9 +4579,9 @@ func (s *DockerSuite) TestBuildBuildTimeArgEnv(c *check.C) {
out := result.Combined()[i:] // "out" should contain just the warning message now
// These were specified on a --build-arg but no ARG was in the Dockerfile
c.Assert(out, checker.Contains, "FOO7")
c.Assert(out, checker.Contains, "FOO8")
c.Assert(out, checker.Contains, "FOO9")
assert.Assert(c, out, checker.Contains, "FOO7")
assert.Assert(c, out, checker.Contains, "FOO8")
assert.Assert(c, out, checker.Contains, "FOO9")
}
func (s *DockerSuite) TestBuildBuildTimeArgQuotedValVariants(c *check.C) {
@ -4652,11 +4652,11 @@ func (s *DockerSuite) TestBuildMultiStageArg(c *check.C) {
parentID := strings.TrimSpace(result.Stdout())
result = cli.DockerCmd(c, "run", "--rm", parentID, "cat", "/out")
c.Assert(result.Stdout(), checker.Contains, "foo=abc")
assert.Assert(c, result.Stdout(), checker.Contains, "foo=abc")
result = cli.DockerCmd(c, "run", "--rm", imgName, "cat", "/out")
c.Assert(result.Stdout(), checker.Not(checker.Contains), "foo")
c.Assert(result.Stdout(), checker.Contains, "bar=def")
assert.Assert(c, result.Stdout(), checker.Not(checker.Contains), "foo")
assert.Assert(c, result.Stdout(), checker.Contains, "bar=def")
}
func (s *DockerSuite) TestBuildMultiStageGlobalArg(c *check.C) {
@ -4678,10 +4678,10 @@ func (s *DockerSuite) TestBuildMultiStageGlobalArg(c *check.C) {
parentID := strings.TrimSpace(result.Stdout())
result = cli.DockerCmd(c, "run", "--rm", parentID, "cat", "/out")
c.Assert(result.Stdout(), checker.Not(checker.Contains), "tag")
assert.Assert(c, result.Stdout(), checker.Not(checker.Contains), "tag")
result = cli.DockerCmd(c, "run", "--rm", imgName, "cat", "/out")
c.Assert(result.Stdout(), checker.Contains, "tag=latest")
assert.Assert(c, result.Stdout(), checker.Contains, "tag=latest")
}
func (s *DockerSuite) TestBuildMultiStageUnusedArg(c *check.C) {
@ -4696,12 +4696,12 @@ func (s *DockerSuite) TestBuildMultiStageUnusedArg(c *check.C) {
build.WithDockerfile(dockerfile),
cli.WithFlags("--build-arg", fmt.Sprintf("baz=abc")))
result.Assert(c, icmd.Success)
c.Assert(result.Combined(), checker.Contains, "[Warning]")
c.Assert(result.Combined(), checker.Contains, "[baz] were not consumed")
assert.Assert(c, result.Combined(), checker.Contains, "[Warning]")
assert.Assert(c, result.Combined(), checker.Contains, "[baz] were not consumed")
result = cli.DockerCmd(c, "run", "--rm", imgName, "cat", "/out")
c.Assert(result.Stdout(), checker.Not(checker.Contains), "bar")
c.Assert(result.Stdout(), checker.Not(checker.Contains), "baz")
assert.Assert(c, result.Stdout(), checker.Not(checker.Contains), "bar")
assert.Assert(c, result.Stdout(), checker.Not(checker.Contains), "baz")
}
func (s *DockerSuite) TestBuildNoNamedVolume(c *check.C) {
@ -4741,7 +4741,7 @@ func (s *DockerSuite) TestBuildTagEvent(c *check.C) {
}
}
c.Assert(foundTag, checker.True, check.Commentf("No tag event found:\n%s", out))
assert.Assert(c, foundTag, checker.True, check.Commentf("No tag event found:\n%s", out))
}
// #15780
@ -4754,7 +4754,7 @@ func (s *DockerSuite) TestBuildMultipleTags(c *check.C) {
id1 := getIDByName(c, "tag1")
id2 := getIDByName(c, "tag2:v2")
c.Assert(id1, check.Equals, id2)
assert.Assert(c, id1, check.Equals, id2)
}
// #17290
@ -4802,17 +4802,17 @@ func (s *DockerSuite) TestBuildFollowSymlinkToFile(c *check.C) {
cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
out := cli.DockerCmd(c, "run", "--rm", name, "cat", "target").Combined()
c.Assert(out, checker.Matches, "bar")
assert.Assert(c, out, checker.Matches, "bar")
// change target file should invalidate cache
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("baz"), 0644)
assert.NilError(c, err)
result := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache")
assert.Assert(c, result.Combined(), checker.Not(checker.Contains), "Using cache")
out = cli.DockerCmd(c, "run", "--rm", name, "cat", "target").Combined()
c.Assert(out, checker.Matches, "baz")
assert.Assert(c, out, checker.Matches, "baz")
}
func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) {
@ -4833,17 +4833,17 @@ func (s *DockerSuite) TestBuildFollowSymlinkToDir(c *check.C) {
cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
out := cli.DockerCmd(c, "run", "--rm", name, "cat", "abc", "def").Combined()
c.Assert(out, checker.Matches, "barbaz")
assert.Assert(c, out, checker.Matches, "barbaz")
// change target file should invalidate cache
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo/def"), []byte("bax"), 0644)
assert.NilError(c, err)
result := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache")
assert.Assert(c, result.Combined(), checker.Not(checker.Contains), "Using cache")
out = cli.DockerCmd(c, "run", "--rm", name, "cat", "abc", "def").Combined()
c.Assert(out, checker.Matches, "barbax")
assert.Assert(c, out, checker.Matches, "barbax")
}
@ -4866,7 +4866,7 @@ func (s *DockerSuite) TestBuildSymlinkBasename(c *check.C) {
cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
out := cli.DockerCmd(c, "run", "--rm", name, "cat", "asymlink").Combined()
c.Assert(out, checker.Matches, "bar")
assert.Assert(c, out, checker.Matches, "bar")
}
// #17827
@ -4890,7 +4890,7 @@ func (s *DockerSuite) TestBuildCacheRootSource(c *check.C) {
result := cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
c.Assert(result.Combined(), checker.Not(checker.Contains), "Using cache")
assert.Assert(c, result.Combined(), checker.Not(checker.Contains), "Using cache")
}
// #19375
@ -4949,7 +4949,7 @@ func (s *DockerSuite) TestBuildLabelOneNode(c *check.C) {
if !ok {
c.Fatal("label `foo` not found in image")
}
c.Assert(v, checker.Equals, "bar")
assert.Assert(c, v, checker.Equals, "bar")
}
func (s *DockerSuite) TestBuildLabelCacheCommit(c *check.C) {
@ -5044,7 +5044,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestBuildWithExternalAuth(c *check.C)
b, err := ioutil.ReadFile(configPath)
assert.NilError(c, err)
c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":")
assert.Assert(c, string(b), checker.Not(checker.Contains), "\"auth\":")
dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
dockerCmd(c, "--config", tmp, "push", repoName)
@ -5383,9 +5383,9 @@ func (s *DockerSuite) TestBuildStepsWithProgress(c *check.C) {
totalRun := 5
result := buildImage(name, build.WithDockerfile("FROM busybox\n"+strings.Repeat("RUN echo foo\n", totalRun)))
result.Assert(c, icmd.Success)
c.Assert(result.Combined(), checker.Contains, fmt.Sprintf("Step 1/%d : FROM busybox", 1+totalRun))
assert.Assert(c, result.Combined(), checker.Contains, fmt.Sprintf("Step 1/%d : FROM busybox", 1+totalRun))
for i := 2; i <= 1+totalRun; i++ {
c.Assert(result.Combined(), checker.Contains, fmt.Sprintf("Step %d/%d : RUN echo foo", i, 1+totalRun))
assert.Assert(c, result.Combined(), checker.Contains, fmt.Sprintf("Step %d/%d : RUN echo foo", i, 1+totalRun))
}
}
@ -5395,16 +5395,16 @@ func (s *DockerSuite) TestBuildWithFailure(c *check.C) {
// First test case can only detect `nobody` in runtime so all steps will show up
dockerfile := "FROM busybox\nRUN nobody"
result := buildImage(name, build.WithDockerfile(dockerfile))
c.Assert(result.Error, checker.NotNil)
c.Assert(result.Stdout(), checker.Contains, "Step 1/2 : FROM busybox")
c.Assert(result.Stdout(), checker.Contains, "Step 2/2 : RUN nobody")
assert.Assert(c, result.Error, checker.NotNil)
assert.Assert(c, result.Stdout(), checker.Contains, "Step 1/2 : FROM busybox")
assert.Assert(c, result.Stdout(), checker.Contains, "Step 2/2 : RUN nobody")
// Second test case `FFOM` should have been detected before build runs so no steps
dockerfile = "FFOM nobody\nRUN nobody"
result = buildImage(name, build.WithDockerfile(dockerfile))
c.Assert(result.Error, checker.NotNil)
c.Assert(result.Stdout(), checker.Not(checker.Contains), "Step 1/2 : FROM busybox")
c.Assert(result.Stdout(), checker.Not(checker.Contains), "Step 2/2 : RUN nobody")
assert.Assert(c, result.Error, checker.NotNil)
assert.Assert(c, result.Stdout(), checker.Not(checker.Contains), "Step 1/2 : FROM busybox")
assert.Assert(c, result.Stdout(), checker.Not(checker.Contains), "Step 2/2 : RUN nobody")
}
func (s *DockerSuite) TestBuildCacheFromEqualDiffIDsLength(c *check.C) {
@ -5425,8 +5425,8 @@ func (s *DockerSuite) TestBuildCacheFromEqualDiffIDsLength(c *check.C) {
// rebuild with cache-from
result := cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
id2 := getIDByName(c, "build2")
c.Assert(id1, checker.Equals, id2)
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2)
assert.Assert(c, id1, checker.Equals, id2)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 2)
}
func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
@ -5450,15 +5450,15 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
// rebuild with cache-from
result := cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
id2 := getIDByName(c, "build2")
c.Assert(id1, checker.Equals, id2)
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3)
assert.Assert(c, id1, checker.Equals, id2)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 3)
cli.DockerCmd(c, "rmi", "build2")
// no cache match with unknown source
result = cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=nosuchtag"), build.WithExternalBuildContext(ctx))
id2 = getIDByName(c, "build2")
c.Assert(id1, checker.Not(checker.Equals), id2)
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 0)
assert.Assert(c, id1, checker.Not(checker.Equals), id2)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 0)
cli.DockerCmd(c, "rmi", "build2")
// clear parent images
@ -5472,23 +5472,23 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
cli.DockerCmd(c, "rmi", "build1")
cli.DockerCmd(c, "load", "-i", tempFile)
parentID := cli.DockerCmd(c, "inspect", "-f", "{{.Parent}}", "build1").Combined()
c.Assert(strings.TrimSpace(parentID), checker.Equals, "")
assert.Assert(c, strings.TrimSpace(parentID), checker.Equals, "")
// cache still applies without parents
result = cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
id2 = getIDByName(c, "build2")
c.Assert(id1, checker.Equals, id2)
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3)
assert.Assert(c, id1, checker.Equals, id2)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 3)
history1 := cli.DockerCmd(c, "history", "-q", "build2").Combined()
// Retry, no new intermediate images
result = cli.BuildCmd(c, "build3", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
id3 := getIDByName(c, "build3")
c.Assert(id1, checker.Equals, id3)
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 3)
assert.Assert(c, id1, checker.Equals, id3)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 3)
history2 := cli.DockerCmd(c, "history", "-q", "build3").Combined()
c.Assert(history1, checker.Equals, history2)
assert.Assert(c, history1, checker.Equals, history2)
cli.DockerCmd(c, "rmi", "build2")
cli.DockerCmd(c, "rmi", "build3")
cli.DockerCmd(c, "rmi", "build1")
@ -5505,22 +5505,22 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
result = cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
id2 = getIDByName(c, "build2")
c.Assert(id1, checker.Not(checker.Equals), id2)
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2)
assert.Assert(c, id1, checker.Not(checker.Equals), id2)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 2)
layers1Str := cli.DockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build1").Combined()
layers2Str := cli.DockerCmd(c, "inspect", "-f", "{{json .RootFS.Layers}}", "build2").Combined()
var layers1 []string
var layers2 []string
c.Assert(json.Unmarshal([]byte(layers1Str), &layers1), checker.IsNil)
c.Assert(json.Unmarshal([]byte(layers2Str), &layers2), checker.IsNil)
assert.Assert(c, json.Unmarshal([]byte(layers1Str), &layers1), checker.IsNil)
assert.Assert(c, json.Unmarshal([]byte(layers2Str), &layers2), checker.IsNil)
c.Assert(len(layers1), checker.Equals, len(layers2))
assert.Assert(c, len(layers1), checker.Equals, len(layers2))
for i := 0; i < len(layers1)-1; i++ {
c.Assert(layers1[i], checker.Equals, layers2[i])
assert.Assert(c, layers1[i], checker.Equals, layers2[i])
}
c.Assert(layers1[len(layers1)-1], checker.Not(checker.Equals), layers2[len(layers1)-1])
assert.Assert(c, layers1[len(layers1)-1], checker.Not(checker.Equals), layers2[len(layers1)-1])
}
func (s *DockerSuite) TestBuildMultiStageCache(c *check.C) {
@ -5540,11 +5540,11 @@ func (s *DockerSuite) TestBuildMultiStageCache(c *check.C) {
result := cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx))
// second part of dockerfile was a repeat of first so should be cached
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 1)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 1)
result = cli.BuildCmd(c, "build2", cli.WithFlags("--cache-from=build1"), build.WithExternalBuildContext(ctx))
// now both parts of dockerfile should be cached
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 2)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 2)
}
func (s *DockerSuite) TestBuildNetNone(c *check.C) {
@ -5572,7 +5572,7 @@ func (s *DockerSuite) TestBuildNetContainer(c *check.C) {
`))
host, _ := dockerCmd(c, "run", "testbuildnetcontainer", "cat", "/otherhost")
c.Assert(strings.TrimSpace(host), check.Equals, "foobar")
assert.Assert(c, strings.TrimSpace(host), check.Equals, "foobar")
}
func (s *DockerSuite) TestBuildWithExtraHost(c *check.C) {
@ -5628,20 +5628,20 @@ func (s *DockerSuite) TestBuildContChar(c *check.C) {
result := buildImage(name, build.WithDockerfile(`FROM busybox
RUN echo hi \`))
result.Assert(c, icmd.Success)
c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox")
c.Assert(result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi\n")
assert.Assert(c, result.Combined(), checker.Contains, "Step 1/2 : FROM busybox")
assert.Assert(c, result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi\n")
result = buildImage(name, build.WithDockerfile(`FROM busybox
RUN echo hi \\`))
result.Assert(c, icmd.Success)
c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox")
c.Assert(result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi \\\n")
assert.Assert(c, result.Combined(), checker.Contains, "Step 1/2 : FROM busybox")
assert.Assert(c, result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi \\\n")
result = buildImage(name, build.WithDockerfile(`FROM busybox
RUN echo hi \\\`))
result.Assert(c, icmd.Success)
c.Assert(result.Combined(), checker.Contains, "Step 1/2 : FROM busybox")
c.Assert(result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi \\\\\n")
assert.Assert(c, result.Combined(), checker.Contains, "Step 1/2 : FROM busybox")
assert.Assert(c, result.Combined(), checker.Contains, "Step 2/2 : RUN echo hi \\\\\n")
}
func (s *DockerSuite) TestBuildMultiStageCopyFromSyntax(c *check.C) {
@ -5681,22 +5681,22 @@ func (s *DockerSuite) TestBuildMultiStageCopyFromSyntax(c *check.C) {
result := cli.BuildCmd(c, "build2", build.WithExternalBuildContext(ctx))
// all commands should be cached
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 7)
c.Assert(getIDByName(c, "build1"), checker.Equals, getIDByName(c, "build2"))
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 7)
assert.Assert(c, getIDByName(c, "build1"), checker.Equals, getIDByName(c, "build2"))
err := ioutil.WriteFile(filepath.Join(ctx.Dir, "Dockerfile"), []byte(fmt.Sprintf(dockerfile, "COPY baz/aa foo")), 0644)
assert.NilError(c, err)
// changing file in parent block should not affect last block
result = cli.BuildCmd(c, "build3", build.WithExternalBuildContext(ctx))
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 5)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 5)
err = ioutil.WriteFile(filepath.Join(ctx.Dir, "foo"), []byte("pqr"), 0644)
assert.NilError(c, err)
// changing file in parent block should affect both first and last block
result = cli.BuildCmd(c, "build4", build.WithExternalBuildContext(ctx))
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 5)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 5)
cli.DockerCmd(c, "run", "build4", "cat", "bay").Assert(c, icmd.Expected{Out: "pqr"})
cli.DockerCmd(c, "run", "build4", "cat", "baz").Assert(c, icmd.Expected{Out: "pqr"})
@ -5777,9 +5777,9 @@ func (s *DockerSuite) TestBuildMultiStageMultipleBuilds(c *check.C) {
cli.BuildCmd(c, "build2", build.WithExternalBuildContext(ctx))
out := cli.DockerCmd(c, "run", "build2", "cat", "bar").Combined()
c.Assert(strings.TrimSpace(out), check.Equals, "abc")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "abc")
out = cli.DockerCmd(c, "run", "build2", "cat", "foo").Combined()
c.Assert(strings.TrimSpace(out), check.Equals, "def")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "def")
}
func (s *DockerSuite) TestBuildMultiStageImplicitFrom(c *check.C) {
@ -5893,9 +5893,9 @@ func (s *DockerSuite) TestBuildMultiStageMultipleBuildsWindows(c *check.C) {
cli.BuildCmd(c, "build2", build.WithExternalBuildContext(ctx))
out := cli.DockerCmd(c, "run", "build2", "cmd.exe", "/s", "/c", "type", "c:\\bar").Combined()
c.Assert(strings.TrimSpace(out), check.Equals, "abc")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "abc")
out = cli.DockerCmd(c, "run", "build2", "cmd.exe", "/s", "/c", "type", "c:\\foo").Combined()
c.Assert(strings.TrimSpace(out), check.Equals, "def")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "def")
}
func (s *DockerSuite) TestBuildCopyFromForbidWindowsSystemPaths(c *check.C) {
@ -5969,7 +5969,7 @@ func (s *DockerSuite) TestBuildMultiStageResetScratch(c *check.C) {
cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx))
res := cli.InspectCmd(c, "build1", cli.Format(".Config.WorkingDir")).Combined()
c.Assert(strings.TrimSpace(res), checker.Equals, "")
assert.Assert(c, strings.TrimSpace(res), checker.Equals, "")
}
func (s *DockerSuite) TestBuildIntermediateTarget(c *check.C) {
@ -5990,14 +5990,14 @@ func (s *DockerSuite) TestBuildIntermediateTarget(c *check.C) {
cli.WithFlags("--target", "build-env"))
res := cli.InspectCmd(c, "build1", cli.Format("json .Config.Cmd")).Combined()
c.Assert(strings.TrimSpace(res), checker.Equals, `["/dev"]`)
assert.Assert(c, strings.TrimSpace(res), checker.Equals, `["/dev"]`)
// Stage name is case-insensitive by design
cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx),
cli.WithFlags("--target", "BUIld-EnV"))
res = cli.InspectCmd(c, "build1", cli.Format("json .Config.Cmd")).Combined()
c.Assert(strings.TrimSpace(res), checker.Equals, `["/dev"]`)
assert.Assert(c, strings.TrimSpace(res), checker.Equals, `["/dev"]`)
result := cli.Docker(cli.Build("build1"), build.WithExternalBuildContext(ctx),
cli.WithFlags("--target", "nosuchtarget"))
@ -6100,7 +6100,7 @@ func (s *DockerSuite) TestBuildWorkdirCmd(c *check.C) {
buildImageSuccessfully(c, name, build.WithDockerfile(dockerFile))
result := buildImage(name, build.WithDockerfile(dockerFile))
result.Assert(c, icmd.Success)
c.Assert(strings.Count(result.Combined(), "Using cache"), checker.Equals, 1)
assert.Assert(c, strings.Count(result.Combined(), "Using cache"), checker.Equals, 1)
}
// FIXME(vdemeester) should be a unit test
@ -6200,7 +6200,7 @@ ENV BAR BAZ`),
assert.NilError(c, err)
d, err := digest.Parse(string(id))
assert.NilError(c, err)
c.Assert(d.String(), checker.Equals, getIDByName(c, name))
assert.Assert(c, d.String(), checker.Equals, getIDByName(c, name))
}
// FIXME(vdemeester) should migrate to docker/cli tests
@ -6223,5 +6223,5 @@ func (s *DockerSuite) TestBuildIidFileCleanupOnFail(c *check.C) {
})
_, err = os.Stat(tmpIidFile)
assert.ErrorContains(c, err, "")
c.Assert(os.IsNotExist(err), check.Equals, true)
assert.Assert(c, os.IsNotExist(err), check.Equals, true)
}

View file

@ -56,16 +56,16 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
var c1 hostConfig
err := json.Unmarshal([]byte(cfg), &c1)
c.Assert(err, checker.IsNil, check.Commentf(cfg))
assert.Assert(c, err, checker.IsNil, check.Commentf(cfg))
c.Assert(c1.Memory, checker.Equals, int64(64*1024*1024), check.Commentf("resource constraints not set properly for Memory"))
c.Assert(c1.MemorySwap, checker.Equals, int64(-1), check.Commentf("resource constraints not set properly for MemorySwap"))
c.Assert(c1.CpusetCpus, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetCpus"))
c.Assert(c1.CpusetMems, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetMems"))
c.Assert(c1.CPUShares, checker.Equals, int64(100), check.Commentf("resource constraints not set properly for CPUShares"))
c.Assert(c1.CPUQuota, checker.Equals, int64(8000), check.Commentf("resource constraints not set properly for CPUQuota"))
c.Assert(c1.Ulimits[0].Name, checker.Equals, "nofile", check.Commentf("resource constraints not set properly for Ulimits"))
c.Assert(c1.Ulimits[0].Hard, checker.Equals, int64(42), check.Commentf("resource constraints not set properly for Ulimits"))
assert.Assert(c, c1.Memory, checker.Equals, int64(64*1024*1024), check.Commentf("resource constraints not set properly for Memory"))
assert.Assert(c, c1.MemorySwap, checker.Equals, int64(-1), check.Commentf("resource constraints not set properly for MemorySwap"))
assert.Assert(c, c1.CpusetCpus, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetCpus"))
assert.Assert(c, c1.CpusetMems, checker.Equals, "0", check.Commentf("resource constraints not set properly for CpusetMems"))
assert.Assert(c, c1.CPUShares, checker.Equals, int64(100), check.Commentf("resource constraints not set properly for CPUShares"))
assert.Assert(c, c1.CPUQuota, checker.Equals, int64(8000), check.Commentf("resource constraints not set properly for CPUQuota"))
assert.Assert(c, c1.Ulimits[0].Name, checker.Equals, "nofile", check.Commentf("resource constraints not set properly for Ulimits"))
assert.Assert(c, c1.Ulimits[0].Hard, checker.Equals, int64(42), check.Commentf("resource constraints not set properly for Ulimits"))
// Make sure constraints aren't saved to image
cli.DockerCmd(c, "run", "--name=test", name)
@ -74,15 +74,15 @@ func (s *DockerSuite) TestBuildResourceConstraintsAreUsed(c *check.C) {
var c2 hostConfig
err = json.Unmarshal([]byte(cfg), &c2)
c.Assert(err, checker.IsNil, check.Commentf(cfg))
assert.Assert(c, err, checker.IsNil, check.Commentf(cfg))
c.Assert(c2.Memory, check.Not(checker.Equals), int64(64*1024*1024), check.Commentf("resource leaked from build for Memory"))
c.Assert(c2.MemorySwap, check.Not(checker.Equals), int64(-1), check.Commentf("resource leaked from build for MemorySwap"))
c.Assert(c2.CpusetCpus, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetCpus"))
c.Assert(c2.CpusetMems, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetMems"))
c.Assert(c2.CPUShares, check.Not(checker.Equals), int64(100), check.Commentf("resource leaked from build for CPUShares"))
c.Assert(c2.CPUQuota, check.Not(checker.Equals), int64(8000), check.Commentf("resource leaked from build for CPUQuota"))
c.Assert(c2.Ulimits, checker.IsNil, check.Commentf("resource leaked from build for Ulimits"))
assert.Assert(c, c2.Memory, check.Not(checker.Equals), int64(64*1024*1024), check.Commentf("resource leaked from build for Memory"))
assert.Assert(c, c2.MemorySwap, check.Not(checker.Equals), int64(-1), check.Commentf("resource leaked from build for MemorySwap"))
assert.Assert(c, c2.CpusetCpus, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetCpus"))
assert.Assert(c, c2.CpusetMems, check.Not(checker.Equals), "0", check.Commentf("resource leaked from build for CpusetMems"))
assert.Assert(c, c2.CPUShares, check.Not(checker.Equals), int64(100), check.Commentf("resource leaked from build for CPUShares"))
assert.Assert(c, c2.CPUQuota, check.Not(checker.Equals), int64(8000), check.Commentf("resource leaked from build for CPUQuota"))
assert.Assert(c, c2.Ulimits, checker.IsNil, check.Commentf("resource leaked from build for Ulimits"))
}
func (s *DockerSuite) TestBuildAddChangeOwnership(c *check.C) {

View file

@ -73,7 +73,7 @@ func testPullByTagDisplaysDigest(c *check.C) {
pullDigest := matches[1]
// make sure the pushed and pull digests match
c.Assert(pushDigest.String(), checker.Equals, pullDigest)
assert.Assert(c, pushDigest.String(), checker.Equals, pullDigest)
}
func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *check.C) {
@ -99,7 +99,7 @@ func testPullByDigest(c *check.C) {
pullDigest := matches[1]
// make sure the pushed and pull digests match
c.Assert(pushDigest.String(), checker.Equals, pullDigest)
assert.Assert(c, pushDigest.String(), checker.Equals, pullDigest)
}
func (s *DockerRegistrySuite) TestPullByDigest(c *check.C) {
@ -115,8 +115,8 @@ func testPullByDigestNoFallback(c *check.C) {
// pull from the registry using the <name>@<digest> reference
imageReference := fmt.Sprintf("%s@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", repoName)
out, _, err := dockerCmdWithError("pull", imageReference)
c.Assert(err, checker.NotNil, check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image"))
c.Assert(out, checker.Contains, fmt.Sprintf("manifest for %s not found", imageReference), check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image"))
assert.Assert(c, err, checker.NotNil, check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image"))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("manifest for %s not found", imageReference), check.Commentf("expected non-zero exit status and correct error message when pulling non-existing image"))
}
func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *check.C) {
@ -151,8 +151,8 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *check.C) {
foundRegex := regexp.MustCompile("found=([^\n]+)")
matches := foundRegex.FindStringSubmatch(out)
c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
c.Assert(matches[1], checker.Equals, "1", check.Commentf("Expected %q, got %q", "1", matches[1]))
assert.Assert(c, matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
assert.Assert(c, matches[1], checker.Equals, "1", check.Commentf("Expected %q, got %q", "1", matches[1]))
res := inspectField(c, containerName, "Config.Image")
assert.Equal(c, res, imageReference)
@ -234,7 +234,7 @@ func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *check.C) {
dockerCmd(c, "pull", imageReference)
out, _ := dockerCmd(c, "images")
c.Assert(out, checker.Not(checker.Contains), "DIGEST", check.Commentf("list output should not have contained DIGEST header"))
assert.Assert(c, out, checker.Not(checker.Contains), "DIGEST", check.Commentf("list output should not have contained DIGEST header"))
}
func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
@ -253,7 +253,7 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
// make sure repo shown, tag=<none>, digest = $digest1
re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`)
c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
assert.Assert(c, re1.MatchString(out), checker.True, check.Commentf("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 *check.C) {
out, _ = dockerCmd(c, "images", "--digests")
// make sure repo shown, tag=<none>, digest = $digest1
c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
assert.Assert(c, re1.MatchString(out), checker.True, check.Commentf("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`)
c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
assert.Assert(c, re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
// pull tag1
dockerCmd(c, "pull", repoName+":tag1")
@ -285,9 +285,9 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*` + digest1.String() + `\s`)
c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, <none>, digest
c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
assert.Assert(c, re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
// pull tag 2
dockerCmd(c, "pull", repoName+":tag2")
@ -296,22 +296,22 @@ func (s *DockerRegistrySuite) TestListImagesWithDigests(c *check.C) {
out, _ = dockerCmd(c, "images", "--digests")
// make sure image 1 has repo, tag, digest
c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), checker.True, check.Commentf("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`)
c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
assert.Assert(c, reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
// list images
out, _ = dockerCmd(c, "images", "--digests")
// make sure image 1 has repo, tag, digest
c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, tag, digest
c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
assert.Assert(c, reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
// make sure busybox has tag, but not digest
busyboxRe := regexp.MustCompile(`\s*busybox\s*latest\s*<none>\s`)
c.Assert(busyboxRe.MatchString(out), checker.True, check.Commentf("expected %q: %s", busyboxRe.String(), out))
assert.Assert(c, busyboxRe.MatchString(out), checker.True, check.Commentf("expected %q: %s", busyboxRe.String(), out))
}
func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
@ -329,7 +329,7 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
// make sure repo shown, tag=<none>, digest = $digest1
re1 := regexp.MustCompile(`\s*` + repoName + `\s*<none>\s*` + digest1.String() + `\s`)
c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
assert.Assert(c, re1.MatchString(out), checker.True, check.Commentf("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 *check.C) {
out, _ = dockerCmd(c, "images", "--digests", "--filter=dangling=true")
// make sure repo shown, tag=<none>, digest = $digest1
c.Assert(re1.MatchString(out), checker.True, check.Commentf("expected %q: %s", re1.String(), out))
assert.Assert(c, re1.MatchString(out), checker.True, check.Commentf("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`)
c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
assert.Assert(c, re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
// pull dangle1 tag
dockerCmd(c, "pull", repoName+":dangle1")
@ -361,9 +361,9 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
// make sure image 1 has repo, tag, <none> AND repo, <none>, digest
reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*dangle1\s*` + digest1.String() + `\s`)
c.Assert(reWithDigest1.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, <none>, digest
c.Assert(re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
assert.Assert(c, re2.MatchString(out), checker.True, check.Commentf("expected %q: %s", re2.String(), out))
// pull dangle2 tag
dockerCmd(c, "pull", repoName+":dangle2")
@ -372,24 +372,24 @@ func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *check.C) {
out, _ = dockerCmd(c, "images", "--digests")
// make sure image 1 has repo, tag, digest
c.Assert(reWithDigest1.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), checker.True, check.Commentf("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`)
c.Assert(reWithDigest2.MatchString(out), checker.True, check.Commentf("expected %q: %s", reWithDigest2.String(), out))
assert.Assert(c, reWithDigest2.MatchString(out), checker.True, check.Commentf("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
c.Assert(reWithDigest1.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest1.String(), out))
assert.Assert(c, reWithDigest1.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest1.String(), out))
// make sure image 2 has repo, tag, digest
c.Assert(reWithDigest2.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest2.String(), out))
assert.Assert(c, reWithDigest2.MatchString(out), checker.False, check.Commentf("unexpected %q: %s", reWithDigest2.String(), out))
}
func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *check.C) {
digest, err := setupImage(c)
c.Assert(err, check.IsNil, check.Commentf("error setting up image"))
assert.Assert(c, err, check.IsNil, check.Commentf("error setting up image"))
imageReference := fmt.Sprintf("%s@%s", repoName, digest)
@ -401,8 +401,8 @@ func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *check.C) {
var imageJSON []types.ImageInspect
err = json.Unmarshal([]byte(out), &imageJSON)
assert.NilError(c, err)
c.Assert(imageJSON, checker.HasLen, 1)
c.Assert(imageJSON[0].RepoDigests, checker.HasLen, 1)
assert.Assert(c, imageJSON, checker.HasLen, 1)
assert.Assert(c, imageJSON[0].RepoDigests, checker.HasLen, 1)
assert.Check(c, is.Contains(imageJSON[0].RepoDigests, imageReference))
}
@ -556,7 +556,7 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
// Pull from the registry using the <name>@<digest> reference.
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
c.Assert(exitStatus, checker.Not(check.Equals), 0)
assert.Assert(c, exitStatus, checker.Not(check.Equals), 0)
expectedErrorMsg := fmt.Sprintf("manifest verification failed for digest %s", manifestDigest)
assert.Assert(c, is.Contains(out, expectedErrorMsg))
@ -568,14 +568,14 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *check.C) {
testRequires(c, DaemonIsLinux)
manifestDigest, err := setupImage(c)
c.Assert(err, checker.IsNil, check.Commentf("error setting up image"))
assert.Assert(c, err, checker.IsNil, check.Commentf("error setting up image"))
// Load the target manifest blob.
manifestBlob := s.reg.ReadBlobContents(c, manifestDigest)
var imgManifest schema1.Manifest
err = json.Unmarshal(manifestBlob, &imgManifest)
c.Assert(err, checker.IsNil, check.Commentf("unable to decode image manifest from blob"))
assert.Assert(c, err, checker.IsNil, check.Commentf("unable to decode image manifest from blob"))
// Change a layer in the manifest.
imgManifest.FSLayers[0] = schema1.FSLayer{
@ -588,7 +588,7 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *check.C
defer undo()
alteredManifestBlob, err := json.MarshalIndent(imgManifest, "", " ")
c.Assert(err, checker.IsNil, check.Commentf("unable to encode altered image manifest to JSON"))
assert.Assert(c, err, checker.IsNil, check.Commentf("unable to encode altered image manifest to JSON"))
s.reg.WriteBlobContents(c, manifestDigest, alteredManifestBlob)
@ -598,10 +598,10 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *check.C
// Pull from the registry using the <name>@<digest> reference.
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
c.Assert(exitStatus, checker.Not(check.Equals), 0)
assert.Assert(c, exitStatus, checker.Not(check.Equals), 0)
expectedErrorMsg := fmt.Sprintf("image verification failed for digest %s", manifestDigest)
c.Assert(out, checker.Contains, expectedErrorMsg)
assert.Assert(c, out, checker.Contains, expectedErrorMsg)
}
// TestPullFailsWithAlteredLayer tests that a `docker pull` fails when
@ -610,14 +610,14 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredManifest(c *check.C
func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
testRequires(c, DaemonIsLinux)
manifestDigest, err := setupImage(c)
c.Assert(err, checker.IsNil)
assert.Assert(c, err, checker.IsNil)
// Load the target manifest blob.
manifestBlob := s.reg.ReadBlobContents(c, manifestDigest)
var imgManifest schema2.Manifest
err = json.Unmarshal(manifestBlob, &imgManifest)
c.Assert(err, checker.IsNil)
assert.Assert(c, err, checker.IsNil)
// Next, get the digest of one of the layers from the manifest.
targetLayerDigest := imgManifest.Layers[0].Digest
@ -641,10 +641,10 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
// Pull from the registry using the <name>@<digest> reference.
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
c.Assert(exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a non-zero exit status"))
assert.Assert(c, exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a non-zero exit status"))
expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest)
c.Assert(out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out))
assert.Assert(c, out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out))
}
// TestPullFailsWithAlteredLayer tests that a `docker pull` fails when
@ -653,14 +653,14 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
testRequires(c, DaemonIsLinux)
manifestDigest, err := setupImage(c)
c.Assert(err, checker.IsNil)
assert.Assert(c, err, checker.IsNil)
// Load the target manifest blob.
manifestBlob := s.reg.ReadBlobContents(c, manifestDigest)
var imgManifest schema1.Manifest
err = json.Unmarshal(manifestBlob, &imgManifest)
c.Assert(err, checker.IsNil)
assert.Assert(c, err, checker.IsNil)
// Next, get the digest of one of the layers from the manifest.
targetLayerDigest := imgManifest.FSLayers[0].BlobSum
@ -684,8 +684,8 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
// Pull from the registry using the <name>@<digest> reference.
imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest)
out, exitStatus, _ := dockerCmdWithError("pull", imageReference)
c.Assert(exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a non-zero exit status"))
assert.Assert(c, exitStatus, checker.Not(check.Equals), 0, check.Commentf("expected a non-zero exit status"))
expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest)
c.Assert(out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out))
assert.Assert(c, out, checker.Contains, expectedErrorMsg, check.Commentf("expected error message in output: %s", out))
}

View file

@ -50,7 +50,7 @@ func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
out = inspectField(c, cleanedContainerID, "State.Paused")
// commit should not unpause a paused container
c.Assert(out, checker.Contains, "true")
assert.Assert(c, out, checker.Contains, "true")
}
func (s *DockerSuite) TestCommitNewFile(c *check.C) {
@ -61,7 +61,7 @@ func (s *DockerSuite) TestCommitNewFile(c *check.C) {
out, _ := dockerCmd(c, "run", imageID, "cat", "/foo")
actual := strings.TrimSpace(out)
c.Assert(actual, checker.Equals, "koye")
assert.Assert(c, actual, checker.Equals, "koye")
}
func (s *DockerSuite) TestCommitHardlink(c *check.C) {
@ -71,7 +71,7 @@ func (s *DockerSuite) TestCommitHardlink(c *check.C) {
chunks := strings.Split(strings.TrimSpace(firstOutput), " ")
inode := chunks[0]
chunks = strings.SplitAfterN(strings.TrimSpace(firstOutput), " ", 2)
c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
assert.Assert(c, chunks[1], checker.Contains, chunks[0], check.Commentf("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 *check.C) {
chunks = strings.Split(strings.TrimSpace(secondOutput), " ")
inode = chunks[0]
chunks = strings.SplitAfterN(strings.TrimSpace(secondOutput), " ", 2)
c.Assert(chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
assert.Assert(c, chunks[1], checker.Contains, chunks[0], check.Commentf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:]))
}
func (s *DockerSuite) TestCommitTTY(c *check.C) {
@ -161,7 +161,7 @@ func (s *DockerSuite) TestCommitChangeLabels(c *check.C) {
"test", "test-commit")
imageID = strings.TrimSpace(imageID)
c.Assert(inspectField(c, imageID, "Config.Labels"), checker.Equals, "map[some:label2]")
assert.Assert(c, inspectField(c, imageID, "Config.Labels"), checker.Equals, "map[some:label2]")
// check that container labels didn't change
c.Assert(inspectField(c, "test", "Config.Labels"), checker.Equals, "map[some:label]")
assert.Assert(c, inspectField(c, "test", "Config.Labels"), checker.Equals, "map[some:label]")
}

View file

@ -36,38 +36,38 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
srcPath := containerCpPath(containerID, "/file2")
dstPath := cpPath(tmpDir, "symlinkToFile1")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, dstPath, "file1"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, dstPath, "file1"), checker.IsNil)
// The file should have the contents of "file2" now.
c.Assert(fileContentEquals(c, cpPath(tmpDir, "file1"), "file2\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "file1"), "file2\n"), checker.IsNil)
// Next, copy a file from the container to a symlink to a directory. This
// should copy the file into the symlink target directory.
dstPath = cpPath(tmpDir, "symlinkToDir1")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil)
// The file should have the contents of "file2" now.
c.Assert(fileContentEquals(c, cpPath(tmpDir, "file2"), "file2\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "file2"), "file2\n"), checker.IsNil)
// Next, copy a file from the container to a symlink to a file that does
// not exist (a broken symlink). This should create the target file with
// the contents of the source file.
dstPath = cpPath(tmpDir, "brokenSymlinkToFileX")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, dstPath, "fileX"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, dstPath, "fileX"), checker.IsNil)
// The file should have the contents of "file2" now.
c.Assert(fileContentEquals(c, cpPath(tmpDir, "fileX"), "file2\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "fileX"), "file2\n"), checker.IsNil)
// Next, copy a directory from the container to a symlink to a local
// directory. This should copy the directory into the symlink target
@ -75,13 +75,13 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
srcPath = containerCpPath(containerID, "/dir2")
dstPath = cpPath(tmpDir, "symlinkToDir1")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, dstPath, "dir1"), checker.IsNil)
// The directory should now contain a copy of "dir2".
c.Assert(fileContentEquals(c, cpPath(tmpDir, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil)
// Next, copy a directory from the container to a symlink to a local
// directory that does not exist (a broken symlink). This should create
@ -89,13 +89,13 @@ func (s *DockerSuite) TestCpFromSymlinkDestination(c *check.C) {
// should not modify the symlink.
dstPath = cpPath(tmpDir, "brokenSymlinkToDirX")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, dstPath, "dirX"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, dstPath, "dirX"), checker.IsNil)
// The "dirX" directory should now be a copy of "dir2".
c.Assert(fileContentEquals(c, cpPath(tmpDir, "dirX/file2-1"), "file2-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(tmpDir, "dirX/file2-1"), "file2-1\n"), checker.IsNil)
}
// Possibilities are reduced to the remaining 10 cases:
@ -129,9 +129,9 @@ func (s *DockerSuite) TestCpFromCaseA(c *check.C) {
srcPath := containerCpPath(containerID, "/root/file1")
dstPath := cpPath(tmpDir, "itWorks.txt")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
}
// B. SRC specifies a file and DST (with trailing path separator) doesn't
@ -150,7 +150,7 @@ func (s *DockerSuite) TestCpFromCaseB(c *check.C) {
err := runDockerCp(c, srcPath, dstDir, nil)
assert.ErrorContains(c, err, "")
c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
assert.Assert(c, isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
}
// C. SRC specifies a file and DST exists as a file. This should overwrite
@ -170,11 +170,11 @@ func (s *DockerSuite) TestCpFromCaseC(c *check.C) {
dstPath := cpPath(tmpDir, "file2")
// Ensure the local file starts with different content.
c.Assert(fileContentEquals(c, dstPath, "file2\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file2\n"), checker.IsNil)
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
}
// D. SRC specifies a file and DST exists as a directory. This should place
@ -195,25 +195,25 @@ func (s *DockerSuite) TestCpFromCaseD(c *check.C) {
// Ensure that dstPath doesn't exist.
_, err := os.Stat(dstPath)
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("did not expect dstPath %q to exist", dstPath))
assert.Assert(c, os.IsNotExist(err), checker.True, check.Commentf("did not expect dstPath %q to exist", dstPath))
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
// unable to remove dstDir
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
assert.Assert(c, os.RemoveAll(dstDir), checker.IsNil)
// unable to make dstDir
c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
assert.Assert(c, os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
dstDir = cpPathTrailingSep(tmpDir, "dir1")
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1\n"), checker.IsNil)
}
// E. SRC specifies a directory and DST does not exist. This should create a
@ -231,20 +231,20 @@ func (s *DockerSuite) TestCpFromCaseE(c *check.C) {
dstDir := cpPath(tmpDir, "testDir")
dstPath := filepath.Join(dstDir, "file1-1")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
// unable to remove dstDir
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
assert.Assert(c, os.RemoveAll(dstDir), checker.IsNil)
dstDir = cpPathTrailingSep(tmpDir, "testDir")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
}
// F. SRC specifies a directory and DST exists as a file. This should cause an
@ -266,7 +266,7 @@ func (s *DockerSuite) TestCpFromCaseF(c *check.C) {
err := runDockerCp(c, srcDir, dstFile, nil)
assert.ErrorContains(c, err, "")
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
}
// G. SRC specifies a directory and DST exists as a directory. This should copy
@ -288,23 +288,23 @@ func (s *DockerSuite) TestCpFromCaseG(c *check.C) {
resultDir := filepath.Join(dstDir, "dir1")
dstPath := filepath.Join(resultDir, "file1-1")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
// unable to remove dstDir
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
assert.Assert(c, os.RemoveAll(dstDir), checker.IsNil)
// unable to make dstDir
c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
assert.Assert(c, os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
dstDir = cpPathTrailingSep(tmpDir, "dir2")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
}
// H. SRC specifies a directory's contents only and DST does not exist. This
@ -322,20 +322,20 @@ func (s *DockerSuite) TestCpFromCaseH(c *check.C) {
dstDir := cpPath(tmpDir, "testDir")
dstPath := filepath.Join(dstDir, "file1-1")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
// unable to remove resultDir
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
assert.Assert(c, os.RemoveAll(dstDir), checker.IsNil)
dstDir = cpPathTrailingSep(tmpDir, "testDir")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
}
// I. SRC specifies a directory's contents only and DST exists as a file. This
@ -358,7 +358,7 @@ func (s *DockerSuite) TestCpFromCaseI(c *check.C) {
err := runDockerCp(c, srcDir, dstFile, nil)
assert.ErrorContains(c, err, "")
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
}
// J. SRC specifies a directory's contents only and DST exists as a directory.
@ -380,21 +380,21 @@ func (s *DockerSuite) TestCpFromCaseJ(c *check.C) {
dstDir := cpPath(tmpDir, "dir2")
dstPath := filepath.Join(dstDir, "file1-1")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
// unable to remove dstDir
c.Assert(os.RemoveAll(dstDir), checker.IsNil)
assert.Assert(c, os.RemoveAll(dstDir), checker.IsNil)
// unable to make dstDir
c.Assert(os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
assert.Assert(c, os.MkdirAll(dstDir, os.FileMode(0755)), checker.IsNil)
dstDir = cpPathTrailingSep(tmpDir, "dir2")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
c.Assert(fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, dstPath, "file1-1\n"), checker.IsNil)
}

View file

@ -40,38 +40,38 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
srcPath := cpPath(testVol, "file2")
dstPath := containerCpPath(containerID, "/vol2/symlinkToFile1")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToFile1"), "file1"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "symlinkToFile1"), "file1"), checker.IsNil)
// The file should have the contents of "file2" now.
c.Assert(fileContentEquals(c, cpPath(testVol, "file1"), "file2\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "file1"), "file2\n"), checker.IsNil)
// Next, copy a local file to a symlink to a directory in the container.
// This should copy the file into the symlink target directory.
dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
// The file should have the contents of "file2" now.
c.Assert(fileContentEquals(c, cpPath(testVol, "file2"), "file2\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "file2"), "file2\n"), checker.IsNil)
// Next, copy a file to a symlink to a file that does not exist (a broken
// symlink) in the container. This should create the target file with the
// contents of the source file.
dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToFileX")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToFileX"), "fileX"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToFileX"), "fileX"), checker.IsNil)
// The file should have the contents of "file2" now.
c.Assert(fileContentEquals(c, cpPath(testVol, "fileX"), "file2\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "fileX"), "file2\n"), checker.IsNil)
// Next, copy a local directory to a symlink to a directory in the
// container. This should copy the directory into the symlink target
@ -79,13 +79,13 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
srcPath = cpPath(testVol, "/dir2")
dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
// The directory should now contain a copy of "dir2".
c.Assert(fileContentEquals(c, cpPath(testVol, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "dir1/dir2/file2-1"), "file2-1\n"), checker.IsNil)
// Next, copy a local directory to a symlink to a local directory that does
// not exist (a broken symlink) in the container. This should create the
@ -93,13 +93,13 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
// should not modify the symlink.
dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToDirX")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// The symlink should not have been modified.
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToDirX"), "dirX"), checker.IsNil)
assert.Assert(c, symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToDirX"), "dirX"), checker.IsNil)
// The "dirX" directory should now be a copy of "dir2".
c.Assert(fileContentEquals(c, cpPath(testVol, "dirX/file2-1"), "file2-1\n"), checker.IsNil)
assert.Assert(c, fileContentEquals(c, cpPath(testVol, "dirX/file2-1"), "file2-1\n"), checker.IsNil)
}
// Possibilities are reduced to the remaining 10 cases:
@ -134,9 +134,9 @@ func (s *DockerSuite) TestCpToCaseA(c *check.C) {
srcPath := cpPath(tmpDir, "file1")
dstPath := containerCpPath(containerID, "/root/itWorks.txt")
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
}
// B. SRC specifies a file and DST (with trailing path separator) doesn't
@ -158,7 +158,7 @@ func (s *DockerSuite) TestCpToCaseB(c *check.C) {
err := runDockerCp(c, srcPath, dstDir, nil)
assert.ErrorContains(c, err, "")
c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
assert.Assert(c, isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
}
// C. SRC specifies a file and DST exists as a file. This should overwrite
@ -179,12 +179,12 @@ func (s *DockerSuite) TestCpToCaseC(c *check.C) {
dstPath := containerCpPath(containerID, "/root/file2")
// Ensure the container's file starts with the original content.
c.Assert(containerStartOutputEquals(c, containerID, "file2\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file2\n"), checker.IsNil)
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
// Should now contain file1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
}
// D. SRC specifies a file and DST exists as a directory. This should place
@ -206,12 +206,12 @@ func (s *DockerSuite) TestCpToCaseD(c *check.C) {
dstDir := containerCpPath(containerID, "dir1")
// Ensure that dstPath doesn't exist.
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, ""), checker.IsNil)
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
// Should now contain file1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
@ -224,12 +224,12 @@ func (s *DockerSuite) TestCpToCaseD(c *check.C) {
dstDir = containerCpPathTrailingSep(containerID, "dir1")
// Ensure that dstPath doesn't exist.
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, ""), checker.IsNil)
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
// Should now contain file1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
}
// E. SRC specifies a directory and DST does not exist. This should create a
@ -249,10 +249,10 @@ func (s *DockerSuite) TestCpToCaseE(c *check.C) {
srcDir := cpPath(tmpDir, "dir1")
dstDir := containerCpPath(containerID, "testDir")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
// Should now contain file1-1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
@ -263,10 +263,10 @@ func (s *DockerSuite) TestCpToCaseE(c *check.C) {
dstDir = containerCpPathTrailingSep(containerID, "testDir")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
// Should now contain file1-1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
}
// F. SRC specifies a directory and DST exists as a file. This should cause an
@ -288,7 +288,7 @@ func (s *DockerSuite) TestCpToCaseF(c *check.C) {
err := runDockerCp(c, srcDir, dstFile, nil)
assert.ErrorContains(c, err, "")
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
}
// G. SRC specifies a directory and DST exists as a directory. This should copy
@ -310,12 +310,12 @@ func (s *DockerSuite) TestCpToCaseG(c *check.C) {
dstDir := containerCpPath(containerID, "/root/dir2")
// Ensure that dstPath doesn't exist.
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, ""), checker.IsNil)
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
// Should now contain file1-1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
@ -328,12 +328,12 @@ func (s *DockerSuite) TestCpToCaseG(c *check.C) {
dstDir = containerCpPathTrailingSep(containerID, "/dir2")
// Ensure that dstPath doesn't exist.
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, ""), checker.IsNil)
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
// Should now contain file1-1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
}
// H. SRC specifies a directory's contents only and DST does not exist. This
@ -353,10 +353,10 @@ func (s *DockerSuite) TestCpToCaseH(c *check.C) {
srcDir := cpPathTrailingSep(tmpDir, "dir1") + "."
dstDir := containerCpPath(containerID, "testDir")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
// Should now contain file1-1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
@ -367,10 +367,10 @@ func (s *DockerSuite) TestCpToCaseH(c *check.C) {
dstDir = containerCpPathTrailingSep(containerID, "testDir")
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
// Should now contain file1-1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
}
// I. SRC specifies a directory's contents only and DST exists as a file. This
@ -393,7 +393,7 @@ func (s *DockerSuite) TestCpToCaseI(c *check.C) {
err := runDockerCp(c, srcDir, dstFile, nil)
assert.ErrorContains(c, err, "")
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
}
// J. SRC specifies a directory's contents only and DST exists as a directory.
@ -416,12 +416,12 @@ func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
dstDir := containerCpPath(containerID, "/dir2")
// Ensure that dstPath doesn't exist.
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, ""), checker.IsNil)
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
// Should now contain file1-1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
// Now try again but using a trailing path separator for dstDir.
@ -433,12 +433,12 @@ func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
dstDir = containerCpPathTrailingSep(containerID, "/dir2")
// Ensure that dstPath doesn't exist.
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, ""), checker.IsNil)
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
assert.Assert(c, runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
// Should now contain file1-1's contents.
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
}
// The `docker cp` command should also ensure that you cannot
@ -462,10 +462,10 @@ func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *check.C) {
err := runDockerCp(c, srcPath, dstPath, nil)
assert.ErrorContains(c, err, "")
c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err))
// Ensure that dstPath doesn't exist.
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, ""), checker.IsNil)
}
// The `docker cp` command should also ensure that you
@ -489,8 +489,8 @@ func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *check.C) {
err := runDockerCp(c, srcPath, dstPath, nil)
assert.ErrorContains(c, err, "")
c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrVolumeReadonly error, but got %T: %s", err, err))
assert.Assert(c, isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrVolumeReadonly error, but got %T: %s", err, err))
// Ensure that dstPath doesn't exist.
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
assert.Assert(c, containerStartOutputEquals(c, containerID, ""), checker.IsNil)
}

View file

@ -37,11 +37,11 @@ func (s *DockerSuite) TestCreateArgs(c *check.C) {
}
err := json.Unmarshal([]byte(out), &containers)
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
assert.Assert(c, err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
assert.Equal(c, len(containers), 1)
cont := containers[0]
c.Assert(string(cont.Path), checker.Equals, "command", check.Commentf("Unexpected container path. Expected command, received: %s", cont.Path))
assert.Assert(c, string(cont.Path), checker.Equals, "command", check.Commentf("Unexpected container path. Expected command, received: %s", cont.Path))
b := false
expected := []string{"arg1", "arg2", "arg with space", "-c", "flags"}
@ -68,7 +68,7 @@ func (s *DockerSuite) TestCreateGrowRootfs(c *check.C) {
cleanedContainerID := strings.TrimSpace(out)
inspectOut := inspectField(c, cleanedContainerID, "HostConfig.StorageOpt")
c.Assert(inspectOut, checker.Equals, "map[size:120G]")
assert.Assert(c, inspectOut, checker.Equals, "map[size:120G]")
}
// Make sure we cannot shrink the container's rootfs at creation time.
@ -78,7 +78,7 @@ func (s *DockerSuite) TestCreateShrinkRootfs(c *check.C) {
// Ensure this fails because of the defaultBaseFsSize is 10G
out, _, err := dockerCmdWithError("create", "--storage-opt", "size=5G", "busybox")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "Container size cannot be smaller than")
assert.Assert(c, out, checker.Contains, "Container size cannot be smaller than")
}
// Make sure we can set hostconfig options too
@ -96,12 +96,12 @@ func (s *DockerSuite) TestCreateHostConfig(c *check.C) {
}
err := json.Unmarshal([]byte(out), &containers)
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
assert.Assert(c, err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
assert.Equal(c, len(containers), 1)
cont := containers[0]
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
c.Assert(cont.HostConfig.PublishAllPorts, checker.True, check.Commentf("Expected PublishAllPorts, got false"))
assert.Assert(c, cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
assert.Assert(c, cont.HostConfig.PublishAllPorts, checker.True, check.Commentf("Expected PublishAllPorts, got false"))
}
func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
@ -117,17 +117,17 @@ func (s *DockerSuite) TestCreateWithPortRange(c *check.C) {
}
}
err := json.Unmarshal([]byte(out), &containers)
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
assert.Assert(c, err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
assert.Equal(c, len(containers), 1)
cont := containers[0]
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
c.Assert(cont.HostConfig.PortBindings, checker.HasLen, 4, check.Commentf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
assert.Assert(c, cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
assert.Assert(c, cont.HostConfig.PortBindings, checker.HasLen, 4, check.Commentf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
for k, v := range cont.HostConfig.PortBindings {
c.Assert(v, checker.HasLen, 1, check.Commentf("Expected 1 ports binding, for the port %s but found %s", k, v))
c.Assert(k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
assert.Assert(c, v, checker.HasLen, 1, check.Commentf("Expected 1 ports binding, for the port %s but found %s", k, v))
assert.Assert(c, k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
}
@ -147,16 +147,16 @@ func (s *DockerSuite) TestCreateWithLargePortRange(c *check.C) {
}
err := json.Unmarshal([]byte(out), &containers)
c.Assert(err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
assert.Assert(c, err, check.IsNil, check.Commentf("Error inspecting the container: %s", err))
assert.Equal(c, len(containers), 1)
cont := containers[0]
c.Assert(cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
c.Assert(cont.HostConfig.PortBindings, checker.HasLen, 65535)
assert.Assert(c, cont.HostConfig, check.NotNil, check.Commentf("Expected HostConfig, got none"))
assert.Assert(c, cont.HostConfig.PortBindings, checker.HasLen, 65535)
for k, v := range cont.HostConfig.PortBindings {
c.Assert(v, checker.HasLen, 1)
c.Assert(k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
assert.Assert(c, v, checker.HasLen, 1)
assert.Assert(c, k.Port(), checker.Equals, v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
}
}
@ -179,7 +179,7 @@ func (s *DockerSuite) TestCreateVolumesCreated(c *check.C) {
dockerCmd(c, "create", "--name", name, "-v", prefix+slash+"foo", "busybox")
dir, err := inspectMountSourceField(name, prefix+slash+"foo")
c.Assert(err, check.IsNil, check.Commentf("Error getting volume host path: %q", err))
assert.Assert(c, err, check.IsNil, check.Commentf("Error getting volume host path: %q", err))
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
c.Fatalf("Volume was not created")
@ -295,7 +295,7 @@ func (s *DockerSuite) TestCreateStopSignal(c *check.C) {
dockerCmd(c, "create", "--name", name, "--stop-signal", "9", "busybox")
res := inspectFieldJSON(c, name, "Config.StopSignal")
c.Assert(res, checker.Contains, "9")
assert.Assert(c, res, checker.Contains, "9")
}
@ -317,11 +317,11 @@ func (s *DockerSuite) TestCreateWithInvalidLogOpts(c *check.C) {
name := "test-invalidate-log-opts"
out, _, err := dockerCmdWithError("create", "--name", name, "--log-opt", "invalid=true", "busybox")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "unknown log opt")
assert.Assert(c, out, checker.Contains, "unknown log opt")
assert.Assert(c, is.Contains(out, "unknown log opt"))
out, _ = dockerCmd(c, "ps", "-a")
c.Assert(out, checker.Not(checker.Contains), name)
assert.Assert(c, out, checker.Not(checker.Contains), name)
}
// #20972
@ -354,9 +354,9 @@ exec "$@"`,
out := cli.DockerCmd(c, "create", "--entrypoint=", name, "echo", "foo").Combined()
id := strings.TrimSpace(out)
c.Assert(id, check.Not(check.Equals), "")
assert.Assert(c, id, check.Not(check.Equals), "")
out = cli.DockerCmd(c, "start", "-a", id).Combined()
c.Assert(strings.TrimSpace(out), check.Equals, "foo")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "foo")
}
// #22471
@ -365,11 +365,11 @@ func (s *DockerSuite) TestCreateStopTimeout(c *check.C) {
dockerCmd(c, "create", "--name", name1, "--stop-timeout", "15", "busybox")
res := inspectFieldJSON(c, name1, "Config.StopTimeout")
c.Assert(res, checker.Contains, "15")
assert.Assert(c, res, checker.Contains, "15")
name2 := "test_create_stop_timeout_2"
dockerCmd(c, "create", "--name", name2, "busybox")
res = inspectFieldJSON(c, name2, "Config.StopTimeout")
c.Assert(res, checker.Contains, "null")
assert.Assert(c, res, checker.Contains, "null")
}

View file

@ -130,13 +130,13 @@ func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) {
var format string
for name, shouldRun := range m {
out, err := s.d.Cmd("ps")
c.Assert(err, check.IsNil, check.Commentf("run ps: %v", out))
assert.Assert(c, err, check.IsNil, check.Commentf("run ps: %v", out))
if shouldRun {
format = "%scontainer %q is not running"
} else {
format = "%scontainer %q is running"
}
c.Assert(strings.Contains(out, name), check.Equals, shouldRun, check.Commentf(format, prefix, name))
assert.Assert(c, strings.Contains(out, name), check.Equals, shouldRun, check.Commentf(format, prefix, name))
}
}
@ -216,7 +216,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithInvalidBasesize(c *check.C) {
if newBasesizeBytes < oldBasesizeBytes {
err := s.d.RestartWithError("--storage-opt", fmt.Sprintf("dm.basesize=%d", newBasesizeBytes))
c.Assert(err, check.NotNil, 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, check.NotNil, check.Commentf("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 {
@ -240,12 +240,12 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithIncreasedBasesize(c *check.C) {
}
err := s.d.RestartWithError("--storage-opt", fmt.Sprintf("dm.basesize=%d", newBasesizeBytes))
c.Assert(err, check.IsNil, check.Commentf("we should have been able to start the daemon with increased base device size: %v", err))
assert.Assert(c, err, check.IsNil, check.Commentf("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)
c.Assert(err, check.IsNil, check.Commentf("Error in converting base device size: %v", err))
c.Assert(newBasesize, check.Equals, basesizeAfterRestart, check.Commentf("Basesize passed is not equal to Basesize set"))
assert.Assert(c, err, check.IsNil, check.Commentf("Error in converting base device size: %v", err))
assert.Assert(c, newBasesize, check.Equals, basesizeAfterRestart, check.Commentf("Basesize passed is not equal to Basesize set"))
s.d.Stop(c)
}
@ -434,12 +434,12 @@ func (s *DockerDaemonSuite) TestDaemonIPv6FixedCIDR(c *check.C) {
out = strings.Trim(out, " \r\n'")
ip := net.ParseIP(out)
c.Assert(ip, checker.NotNil, check.Commentf("Container should have a global IPv6 address"))
assert.Assert(c, ip, checker.NotNil, check.Commentf("Container should have a global IPv6 address"))
out, err = s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.IPv6Gateway}}", "ipv6test")
assert.NilError(c, err, out)
c.Assert(strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:2::100", check.Commentf("Container should have a global IPv6 gateway"))
assert.Assert(c, strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:2::100", check.Commentf("Container should have a global IPv6 gateway"))
}
// TestDaemonIPv6FixedCIDRAndMac checks that when the daemon is started with ipv6 fixed CIDR
@ -458,7 +458,7 @@ func (s *DockerDaemonSuite) TestDaemonIPv6FixedCIDRAndMac(c *check.C) {
out, err = s.d.Cmd("inspect", "--format", "{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}", "ipv6test")
assert.NilError(c, err, out)
c.Assert(strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:1::aabb:ccdd:eeff")
assert.Assert(c, strings.Trim(out, " \r\n'"), checker.Equals, "2001:db8:1::aabb:ccdd:eeff")
}
// TestDaemonIPv6HostMode checks that when the running a container with
@ -473,11 +473,11 @@ func (s *DockerDaemonSuite) TestDaemonIPv6HostMode(c *check.C) {
out, err = s.d.Cmd("exec", "hostcnt", "ip", "-6", "addr", "show", "docker0")
assert.NilError(c, err, out)
c.Assert(strings.Trim(out, " \r\n'"), checker.Contains, "2001:db8:2::1")
assert.Assert(c, strings.Trim(out, " \r\n'"), checker.Contains, "2001:db8:2::1")
}
func (s *DockerDaemonSuite) TestDaemonLogLevelWrong(c *check.C) {
c.Assert(s.d.StartWithError("--log-level=bogus"), check.NotNil, check.Commentf("Daemon shouldn't start with wrong log level"))
assert.Assert(c, s.d.StartWithError("--log-level=bogus"), check.NotNil, check.Commentf("Daemon shouldn't start with wrong log level"))
}
func (s *DockerDaemonSuite) TestDaemonLogLevelDebug(c *check.C) {
@ -679,7 +679,7 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) {
containerIP := d.FindContainerIP(c, "test")
ip = net.ParseIP(containerIP)
c.Assert(bridgeIPNet.Contains(ip), check.Equals, true, check.Commentf("Container IP-Address must be in the same subnet range : %s", containerIP))
assert.Assert(c, bridgeIPNet.Contains(ip), check.Equals, true, check.Commentf("Container IP-Address must be in the same subnet range : %s", containerIP))
deleteInterface(c, defaultNetworkBridge)
}
@ -783,7 +783,7 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Implicit(c *check.C) {
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)
c.Assert(strings.Contains(out, expectedMessage), check.Equals, true, check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'", bridgeIP, strings.TrimSpace(out)))
assert.Assert(c, strings.Contains(out, expectedMessage), check.Equals, true, check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'", bridgeIP, strings.TrimSpace(out)))
deleteInterface(c, defaultNetworkBridge)
}
@ -803,7 +803,7 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Explicit(c *check.C) {
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)
c.Assert(strings.Contains(out, expectedMessage), check.Equals, true, check.Commentf("Explicit default gateway should be %s, but default route was '%s'", gatewayIP, strings.TrimSpace(out)))
assert.Assert(c, strings.Contains(out, expectedMessage), check.Equals, true, check.Commentf("Explicit default gateway should be %s, but default route was '%s'", gatewayIP, strings.TrimSpace(out)))
deleteInterface(c, defaultNetworkBridge)
}
@ -844,8 +844,8 @@ func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) {
defer d.Restart(c)
out, err := d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top")
c.Assert(err, check.NotNil, check.Commentf("Running a container must fail with an invalid --ip option"))
c.Assert(strings.Contains(out, "Error starting userland proxy"), check.Equals, true)
assert.Assert(c, err, check.NotNil, check.Commentf("Running a container must fail with an invalid --ip option"))
assert.Assert(c, strings.Contains(out, "Error starting userland proxy"), check.Equals, true)
ifName := "dummy"
createInterface(c, "dummy", ifName, ipStr)
@ -858,7 +858,7 @@ func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) {
result.Assert(c, icmd.Success)
regex := fmt.Sprintf("DNAT.*%s.*dpt:8000", ip.String())
matched, _ := regexp.MatchString(regex, result.Combined())
c.Assert(matched, check.Equals, true, check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
assert.Assert(c, matched, check.Equals, true, check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
}
func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
@ -878,7 +878,7 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) {
result.Assert(c, icmd.Success)
regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
matched, _ := regexp.MatchString(regex, result.Combined())
c.Assert(matched, check.Equals, true, check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
assert.Assert(c, matched, check.Equals, true, check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
// Pinging another container must fail with --icc=false
pingContainers(c, d, true)
@ -911,7 +911,7 @@ func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) {
result.Assert(c, icmd.Success)
regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName)
matched, _ := regexp.MatchString(regex, result.Combined())
c.Assert(matched, check.Equals, true, check.Commentf("iptables output should have contained %q, but was %q", regex, result.Combined()))
assert.Assert(c, matched, check.Equals, true, check.Commentf("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)
@ -1136,7 +1136,7 @@ func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) {
assert.NilError(c, err, out)
out, err = s.d.Cmd("logs", "test")
c.Assert(err, check.NotNil, check.Commentf("Logs should fail with 'none' driver"))
assert.Assert(c, err, check.NotNil, check.Commentf("Logs should fail with 'none' driver"))
expected := `configured logging driver does not support reading`
assert.Assert(c, strings.Contains(out, expected))
}
@ -1151,9 +1151,9 @@ func (s *DockerDaemonSuite) TestDaemonLoggingDriverShouldBeIgnoredForBuild(c *ch
build.WithoutCache,
)
comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", result.Combined(), result.ExitCode, result.Error)
c.Assert(result.Error, check.IsNil, comment)
c.Assert(result.ExitCode, check.Equals, 0, comment)
c.Assert(result.Combined(), checker.Contains, "foo", comment)
assert.Assert(c, result.Error, check.IsNil, comment)
assert.Assert(c, result.ExitCode, check.Equals, 0, comment)
assert.Assert(c, result.Combined(), checker.Contains, "foo", comment)
}
func (s *DockerDaemonSuite) TestDaemonUnixSockCleanedUp(c *check.C) {
@ -1223,7 +1223,7 @@ func (s *DockerDaemonSuite) TestDaemonWithWrongkey(c *check.C) {
}
content, err := s.d.ReadLogFile()
c.Assert(err, checker.IsNil)
assert.Assert(c, err, checker.IsNil)
if !strings.Contains(string(content), "Public Key ID does not match") {
c.Fatalf("Missing KeyID message from daemon logs: %s", string(content))
@ -1569,7 +1569,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithContainerWithRestartPolicyAlway
out, err = s.d.Cmd("ps", "-q")
assert.NilError(c, err, out)
c.Assert(strings.TrimSpace(out), check.Equals, id[:12])
assert.Assert(c, strings.TrimSpace(out), check.Equals, id[:12])
}
func (s *DockerDaemonSuite) TestDaemonWideLogConfig(c *check.C) {
@ -1630,8 +1630,8 @@ func (s *DockerDaemonSuite) TestDaemonRestartRmVolumeInUse(c *check.C) {
s.d.Restart(c)
out, err = s.d.Cmd("volume", "rm", "test")
c.Assert(err, check.NotNil, check.Commentf("should not be able to remove in use volume after daemon restart"))
c.Assert(out, checker.Contains, "in use")
assert.Assert(c, err, check.NotNil, check.Commentf("should not be able to remove in use volume after daemon restart"))
assert.Assert(c, out, checker.Contains, "in use")
}
func (s *DockerDaemonSuite) TestDaemonRestartLocalVolumes(c *check.C) {
@ -1648,7 +1648,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartLocalVolumes(c *check.C) {
// FIXME(vdemeester) should be a unit test
func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) {
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
c.Assert(d.StartWithError("--log-driver=syslog", "--log-opt", "syslog-address=corrupted:42"), check.NotNil)
assert.Assert(c, d.StartWithError("--log-driver=syslog", "--log-opt", "syslog-address=corrupted:42"), check.NotNil)
expected := "syslog-address should be in form proto://address"
icmd.RunCommand("grep", expected, d.LogFileName()).Assert(c, icmd.Success)
}
@ -1656,7 +1656,7 @@ func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) {
// FIXME(vdemeester) should be a unit test
func (s *DockerDaemonSuite) TestDaemonCorruptedFluentdAddress(c *check.C) {
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
c.Assert(d.StartWithError("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), check.NotNil)
assert.Assert(c, d.StartWithError("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), check.NotNil)
expected := "invalid fluentd-address corrupted:c: "
icmd.RunCommand("grep", expected, d.LogFileName()).Assert(c, icmd.Success)
}
@ -1725,9 +1725,9 @@ func (s *DockerDaemonSuite) TestDaemonStartWithDefaultTLSHost(c *check.C) {
assert.NilError(c, err)
conn.Close()
c.Assert(certRequestInfo, checker.NotNil)
c.Assert(certRequestInfo.AcceptableCAs, checker.HasLen, 1)
c.Assert(certRequestInfo.AcceptableCAs[0], checker.DeepEquals, rootCert.RawSubject)
assert.Assert(c, certRequestInfo, checker.NotNil)
assert.Assert(c, certRequestInfo.AcceptableCAs, checker.HasLen, 1)
assert.Assert(c, certRequestInfo.AcceptableCAs[0], checker.DeepEquals, rootCert.RawSubject)
}
func (s *DockerDaemonSuite) TestBridgeIPIsExcludedFromAllocatorPool(c *check.C) {
@ -1749,9 +1749,9 @@ func (s *DockerDaemonSuite) TestBridgeIPIsExcludedFromAllocatorPool(c *check.C)
break
}
ip, err := s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.IPAddress}}'", contName)
c.Assert(err, check.IsNil, check.Commentf("%s", ip))
assert.Assert(c, err, check.IsNil, check.Commentf("%s", ip))
c.Assert(ip, check.Not(check.Equals), bridgeIP)
assert.Assert(c, ip, check.Not(check.Equals), bridgeIP)
cont++
}
}
@ -1763,7 +1763,7 @@ func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *check.C) {
testDir, err := ioutil.TempDir("", "no-space-left-on-device-test")
assert.NilError(c, err)
defer os.RemoveAll(testDir)
c.Assert(mount.MakeRShared(testDir), checker.IsNil)
assert.Assert(c, mount.MakeRShared(testDir), checker.IsNil)
defer mount.Unmount(testDir)
// create a 3MiB image (with a 2MiB ext4 fs) and mount it as graph root
@ -1779,8 +1779,8 @@ func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *check.C) {
// pull a repository large enough to overfill the mounted filesystem
pullOut, err := s.d.Cmd("pull", "debian:stretch")
c.Assert(err, checker.NotNil, check.Commentf("%s", pullOut))
c.Assert(pullOut, checker.Contains, "no space left on device")
assert.Assert(c, err, checker.NotNil, check.Commentf("%s", pullOut))
assert.Assert(c, pullOut, checker.Contains, "no space left on device")
}
// Test daemon restart with container links + auto restart
@ -1854,7 +1854,7 @@ func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *check.C) {
out, err := s.d.Cmd("run", "--name", name, "busybox", "cat", "/proc/self/cgroup")
assert.NilError(c, err)
cgroupPaths := ParseCgroupPaths(string(out))
c.Assert(len(cgroupPaths), checker.Not(checker.Equals), 0, check.Commentf("unexpected output - %q", string(out)))
assert.Assert(c, len(cgroupPaths), checker.Not(checker.Equals), 0, check.Commentf("unexpected output - %q", string(out)))
out, err = s.d.Cmd("inspect", "-f", "{{.Id}}", name)
assert.NilError(c, err)
id := strings.TrimSpace(string(out))
@ -1866,7 +1866,7 @@ func (s *DockerDaemonSuite) TestDaemonCgroupParent(c *check.C) {
break
}
}
c.Assert(found, checker.True, check.Commentf("Cgroup path for container (%s) doesn't found in cgroups file: %s", expectedCgroup, cgroupPaths))
assert.Assert(c, found, checker.True, check.Commentf("Cgroup path for container (%s) doesn't found in cgroups file: %s", expectedCgroup, cgroupPaths))
}
func (s *DockerDaemonSuite) TestDaemonRestartWithLinks(c *check.C) {
@ -1889,7 +1889,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithLinks(c *check.C) {
assert.NilError(c, err, out)
out, err = s.d.Cmd("start", "-a", "test2")
assert.NilError(c, err, out)
c.Assert(strings.Contains(out, "1 packets transmitted, 1 packets received"), check.Equals, true, check.Commentf("%s", out))
assert.Assert(c, strings.Contains(out, "1 packets transmitted, 1 packets received"), check.Equals, true, check.Commentf("%s", out))
}
func (s *DockerDaemonSuite) TestDaemonRestartWithNames(c *check.C) {
@ -1999,14 +1999,14 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) {
id := strings.TrimSpace(out)
// kill the daemon
c.Assert(s.d.Kill(), check.IsNil)
assert.Assert(c, s.d.Kill(), check.IsNil)
// Check if there are mounts with container id visible from the host.
// If not, those mounts exist in container's own mount ns, and so
// the following check for mounts being cleared is pointless.
skipMountCheck := false
mountOut, err := ioutil.ReadFile("/proc/self/mountinfo")
c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
assert.Assert(c, err, check.IsNil, check.Commentf("Output: %s", mountOut))
if !strings.Contains(string(mountOut), id) {
skipMountCheck = true
}
@ -2031,9 +2031,9 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) {
}
// Now, container mounts should be gone.
mountOut, err = ioutil.ReadFile("/proc/self/mountinfo")
c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut))
assert.Assert(c, err, check.IsNil, 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)
c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment)
assert.Assert(c, strings.Contains(string(mountOut), id), check.Equals, false, comment)
}
// TestDaemonRestartWithUnpausedRunningContainer requires live restore of running containers.
@ -2103,7 +2103,7 @@ func (s *DockerDaemonSuite) TestRunLinksChanged(c *check.C) {
out, err = s.d.Cmd("run", "--name=test2", "--link=test:abc", "busybox", "sh", "-c", "ping -c 1 abc")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, "1 packets transmitted, 1 packets received")
assert.Assert(c, out, checker.Contains, "1 packets transmitted, 1 packets received")
out, err = s.d.Cmd("rm", "-f", "test")
assert.NilError(c, err, out)
@ -2112,12 +2112,12 @@ func (s *DockerDaemonSuite) TestRunLinksChanged(c *check.C) {
assert.NilError(c, err, out)
out, err = s.d.Cmd("start", "-a", "test2")
assert.ErrorContains(c, err, "", out)
c.Assert(out, check.Not(checker.Contains), "1 packets transmitted, 1 packets received")
assert.Assert(c, out, check.Not(checker.Contains), "1 packets transmitted, 1 packets received")
s.d.Restart(c)
out, err = s.d.Cmd("start", "-a", "test2")
assert.ErrorContains(c, err, "", out)
c.Assert(out, check.Not(checker.Contains), "1 packets transmitted, 1 packets received")
assert.Assert(c, out, check.Not(checker.Contains), "1 packets transmitted, 1 packets received")
}
func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) {
@ -2145,7 +2145,7 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) {
s.d.Stop(c)
// Wait for io.Copy() before checking output
<-done
c.Assert(b.String(), checker.Contains, infoLog)
assert.Assert(c, b.String(), checker.Contains, infoLog)
b.Reset()
@ -2166,8 +2166,8 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) {
s.d.Stop(c)
// Wait for io.Copy() before checking output
<-done
c.Assert(b.String(), check.Not(check.Equals), "")
c.Assert(b.String(), check.Not(checker.Contains), infoLog)
assert.Assert(c, b.String(), check.Not(check.Equals), "")
assert.Assert(c, b.String(), check.Not(checker.Contains), infoLog)
}
func (s *DockerDaemonSuite) TestDaemonDebugLog(c *check.C) {
@ -2187,7 +2187,7 @@ func (s *DockerDaemonSuite) TestDaemonDebugLog(c *check.C) {
s.d.StartWithLogFile(tty, "--debug")
s.d.Stop(c)
c.Assert(b.String(), checker.Contains, debugLog)
assert.Assert(c, b.String(), checker.Contains, debugLog)
}
func (s *DockerDaemonSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) {
@ -2196,7 +2196,7 @@ func (s *DockerDaemonSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) {
// daemon config file
daemonConfig := `{ "debug" : false }`
configFile, err := ioutil.TempFile("", "test-daemon-discovery-backend-config-reload-config")
c.Assert(err, checker.IsNil, check.Commentf("could not create temp file for config reload"))
assert.Assert(c, err, checker.IsNil, check.Commentf("could not create temp file for config reload"))
configFilePath := configFile.Name()
defer func() {
configFile.Close()
@ -2226,13 +2226,13 @@ func (s *DockerDaemonSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) {
assert.NilError(c, err)
err = s.d.ReloadConfig()
c.Assert(err, checker.IsNil, check.Commentf("error reloading daemon config"))
assert.Assert(c, err, checker.IsNil, check.Commentf("error reloading daemon config"))
out, err := s.d.Cmd("info")
assert.NilError(c, err)
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: consul://consuladdr:consulport/some/path"))
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: 192.168.56.100:0"))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Cluster Store: consul://consuladdr:consulport/some/path"))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Cluster Advertise: 192.168.56.100:0"))
}
// Test for #21956
@ -2245,7 +2245,7 @@ func (s *DockerDaemonSuite) TestDaemonLogOptions(c *check.C) {
out, err = s.d.Cmd("inspect", "--format='{{.HostConfig.LogConfig}}'", id)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, "{json-file map[]}")
assert.Assert(c, out, checker.Contains, "{json-file map[]}")
}
// Test case for #20936, #22443
@ -2256,8 +2256,8 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrency(c *check.C) {
expectedMaxConcurrentDownloads := `level=debug msg="Max Concurrent Downloads: 8"`
content, err := s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentUploads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentDownloads)
}
// Test case for #20936, #22443
@ -2279,8 +2279,8 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFile(c *check.C) {
expectedMaxConcurrentDownloads := `level=debug msg="Max Concurrent Downloads: 8"`
content, err := s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentUploads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentDownloads)
configFile, err = os.Create(configFilePath)
assert.NilError(c, err)
@ -2288,7 +2288,7 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFile(c *check.C) {
fmt.Fprintf(configFile, "%s", daemonConfig)
configFile.Close()
c.Assert(s.d.Signal(unix.SIGHUP), checker.IsNil)
assert.Assert(c, s.d.Signal(unix.SIGHUP), checker.IsNil)
// unix.Kill(s.d.cmd.Process.Pid, unix.SIGHUP)
time.Sleep(3 * time.Second)
@ -2297,8 +2297,8 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFile(c *check.C) {
expectedMaxConcurrentDownloads = `level=debug msg="Reset Max Concurrent Downloads: 9"`
content, err = s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentUploads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentDownloads)
}
// Test case for #20936, #22443
@ -2320,8 +2320,8 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *chec
expectedMaxConcurrentDownloads := `level=debug msg="Max Concurrent Downloads: 3"`
content, err := s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentUploads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentDownloads)
configFile, err = os.Create(configFilePath)
assert.NilError(c, err)
@ -2329,7 +2329,7 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *chec
fmt.Fprintf(configFile, "%s", daemonConfig)
configFile.Close()
c.Assert(s.d.Signal(unix.SIGHUP), checker.IsNil)
assert.Assert(c, s.d.Signal(unix.SIGHUP), checker.IsNil)
// unix.Kill(s.d.cmd.Process.Pid, unix.SIGHUP)
time.Sleep(3 * time.Second)
@ -2338,8 +2338,8 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *chec
expectedMaxConcurrentDownloads = `level=debug msg="Reset Max Concurrent Downloads: 3"`
content, err = s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentUploads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentDownloads)
configFile, err = os.Create(configFilePath)
assert.NilError(c, err)
@ -2347,7 +2347,7 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *chec
fmt.Fprintf(configFile, "%s", daemonConfig)
configFile.Close()
c.Assert(s.d.Signal(unix.SIGHUP), checker.IsNil)
assert.Assert(c, s.d.Signal(unix.SIGHUP), checker.IsNil)
time.Sleep(3 * time.Second)
@ -2355,8 +2355,8 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *chec
expectedMaxConcurrentDownloads = `level=debug msg="Reset Max Concurrent Downloads: 3"`
content, err = s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads)
c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentUploads)
assert.Assert(c, string(content), checker.Contains, expectedMaxConcurrentDownloads)
}
func (s *DockerDaemonSuite) TestBuildOnDisabledBridgeNetworkDaemon(c *check.C) {
@ -2369,8 +2369,8 @@ func (s *DockerDaemonSuite) TestBuildOnDisabledBridgeNetworkDaemon(c *check.C) {
build.WithoutCache,
)
comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", result.Combined(), result.ExitCode, result.Error)
c.Assert(result.Error, check.IsNil, comment)
c.Assert(result.ExitCode, check.Equals, 0, comment)
assert.Assert(c, result.Error, check.IsNil, comment)
assert.Assert(c, result.ExitCode, check.Equals, 0, comment)
}
// Test case for #21976
@ -2381,11 +2381,11 @@ func (s *DockerDaemonSuite) TestDaemonDNSFlagsInHostMode(c *check.C) {
expectedOutput := "nameserver 1.2.3.4"
out, _ := s.d.Cmd("run", "--net=host", "busybox", "cat", "/etc/resolv.conf")
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
expectedOutput = "search example.com"
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
expectedOutput = "options timeout:3"
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
}
func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *check.C) {
@ -2428,7 +2428,7 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *check.C) {
// Run with "vm"
out, err = s.d.Cmd("run", "--rm", "--runtime=vm", "busybox", "ls")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory")
assert.Assert(c, out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory")
// Reset config to only have the default
config = `
@ -2438,7 +2438,7 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *check.C) {
}
`
ioutil.WriteFile(configName, []byte(config), 0644)
c.Assert(s.d.Signal(unix.SIGHUP), checker.IsNil)
assert.Assert(c, s.d.Signal(unix.SIGHUP), checker.IsNil)
// Give daemon time to reload config
<-time.After(1 * time.Second)
@ -2449,12 +2449,12 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *check.C) {
// Run with "oci"
out, err = s.d.Cmd("run", "--rm", "--runtime=oci", "busybox", "ls")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "Unknown runtime specified oci")
assert.Assert(c, out, checker.Contains, "Unknown runtime specified oci")
// Start previously created container with oci
out, err = s.d.Cmd("start", "oci-runtime-ls")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "Unknown runtime specified oci")
assert.Assert(c, out, checker.Contains, "Unknown runtime specified oci")
// Check that we can't override the default runtime
config = `
@ -2467,13 +2467,13 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *check.C) {
}
`
ioutil.WriteFile(configName, []byte(config), 0644)
c.Assert(s.d.Signal(unix.SIGHUP), checker.IsNil)
assert.Assert(c, s.d.Signal(unix.SIGHUP), checker.IsNil)
// Give daemon time to reload config
<-time.After(1 * time.Second)
content, err := s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, `file configuration validation failed: runtime name 'runc' is reserved`)
assert.Assert(c, string(content), checker.Contains, `file configuration validation failed: runtime name 'runc' is reserved`)
// Check that we can select a default runtime
config = `
@ -2493,13 +2493,13 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *check.C) {
}
`
ioutil.WriteFile(configName, []byte(config), 0644)
c.Assert(s.d.Signal(unix.SIGHUP), checker.IsNil)
assert.Assert(c, s.d.Signal(unix.SIGHUP), checker.IsNil)
// Give daemon time to reload config
<-time.After(1 * time.Second)
out, err = s.d.Cmd("run", "--rm", "busybox", "ls")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory")
assert.Assert(c, out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory")
// Run with default runtime explicitly
out, err = s.d.Cmd("run", "--rm", "--runtime=runc", "busybox", "ls")
@ -2524,7 +2524,7 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromCommandLine(c *check.C) {
// Run with "vm"
out, err = s.d.Cmd("run", "--rm", "--runtime=vm", "busybox", "ls")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory")
assert.Assert(c, out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory")
// Start a daemon without any extra runtimes
s.d.Stop(c)
@ -2537,20 +2537,20 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromCommandLine(c *check.C) {
// Run with "oci"
out, err = s.d.Cmd("run", "--rm", "--runtime=oci", "busybox", "ls")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "Unknown runtime specified oci")
assert.Assert(c, out, checker.Contains, "Unknown runtime specified oci")
// Start previously created container with oci
out, err = s.d.Cmd("start", "oci-runtime-ls")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "Unknown runtime specified oci")
assert.Assert(c, out, checker.Contains, "Unknown runtime specified oci")
// Check that we can't override the default runtime
s.d.Stop(c)
c.Assert(s.d.StartWithError("--add-runtime", "runc=my-runc"), checker.NotNil)
assert.Assert(c, s.d.StartWithError("--add-runtime", "runc=my-runc"), checker.NotNil)
content, err := s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, `runtime name 'runc' is reserved`)
assert.Assert(c, string(content), checker.Contains, `runtime name 'runc' is reserved`)
// Check that we can select a default runtime
s.d.Stop(c)
@ -2558,7 +2558,7 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromCommandLine(c *check.C) {
out, err = s.d.Cmd("run", "--rm", "busybox", "ls")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory")
assert.Assert(c, out, checker.Contains, "/usr/local/bin/vm-manager: no such file or directory")
// Run with default runtime explicitly
out, err = s.d.Cmd("run", "--rm", "--runtime=runc", "busybox", "ls")
@ -2570,23 +2570,23 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithAutoRemoveContainer(c *check.C)
// top1 will exist after daemon restarts
out, err := s.d.Cmd("run", "-d", "--name", "top1", "busybox:latest", "top")
c.Assert(err, checker.IsNil, check.Commentf("run top1: %v", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("run top1: %v", out))
// top2 will be removed after daemon restarts
out, err = s.d.Cmd("run", "-d", "--rm", "--name", "top2", "busybox:latest", "top")
c.Assert(err, checker.IsNil, check.Commentf("run top2: %v", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("run top2: %v", out))
out, err = s.d.Cmd("ps")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "top1", check.Commentf("top1 should be running"))
c.Assert(out, checker.Contains, "top2", check.Commentf("top2 should be running"))
assert.Assert(c, out, checker.Contains, "top1", check.Commentf("top1 should be running"))
assert.Assert(c, out, checker.Contains, "top2", check.Commentf("top2 should be running"))
// now restart daemon gracefully
s.d.Restart(c)
out, err = s.d.Cmd("ps", "-a")
assert.NilError(c, err, "out: %v", out)
c.Assert(out, checker.Contains, "top1", check.Commentf("top1 should exist after daemon restarts"))
c.Assert(out, checker.Not(checker.Contains), "top2", check.Commentf("top2 should be removed after daemon restarts"))
assert.Assert(c, out, checker.Contains, "top1", check.Commentf("top1 should exist after daemon restarts"))
assert.Assert(c, out, checker.Not(checker.Contains), "top2", check.Commentf("top2 should be removed after daemon restarts"))
}
func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
@ -2613,7 +2613,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
errMsg1, err := s.d.Cmd("inspect", "-f", "{{.State.Error}}", containerName)
errMsg1 = strings.TrimSpace(errMsg1)
assert.NilError(c, err)
c.Assert(errMsg1, checker.Contains, "executable file not found")
assert.Assert(c, errMsg1, checker.Contains, "executable file not found")
// now restart daemon
s.d.Restart(c)
@ -2656,8 +2656,8 @@ func (s *DockerDaemonSuite) TestDaemonWithUserlandProxyPath(c *check.C) {
s.d.Restart(c, "--userland-proxy-path", "/does/not/exist")
out, err = s.d.Cmd("run", "-p", "5000:5000", "busybox:latest", "true")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "driver failed programming external connectivity on endpoint")
c.Assert(out, checker.Contains, "/does/not/exist: no such file or directory")
assert.Assert(c, out, checker.Contains, "driver failed programming external connectivity on endpoint")
assert.Assert(c, out, checker.Contains, "/does/not/exist: no such file or directory")
}
// Test case for #22471
@ -2668,7 +2668,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownTimeout(c *check.C) {
_, err := s.d.Cmd("run", "-d", "busybox", "top")
assert.NilError(c, err)
c.Assert(s.d.Signal(unix.SIGINT), checker.IsNil)
assert.Assert(c, s.d.Signal(unix.SIGINT), checker.IsNil)
select {
case <-s.d.Wait:
@ -2678,7 +2678,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownTimeout(c *check.C) {
expectedMessage := `level=debug msg="daemon configured with a 3 seconds minimum shutdown timeout"`
content, err := s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, expectedMessage)
assert.Assert(c, string(content), checker.Contains, expectedMessage)
}
// Test case for #22471
@ -2702,7 +2702,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownTimeoutWithConfigFile(c *check.C)
fmt.Fprintf(configFile, "%s", daemonConfig)
configFile.Close()
c.Assert(s.d.Signal(unix.SIGHUP), checker.IsNil)
assert.Assert(c, s.d.Signal(unix.SIGHUP), checker.IsNil)
select {
case <-s.d.Wait:
@ -2712,7 +2712,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownTimeoutWithConfigFile(c *check.C)
expectedMessage := `level=debug msg="Reset Shutdown Timeout: 5"`
content, err := s.d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, expectedMessage)
assert.Assert(c, string(content), checker.Contains, expectedMessage)
}
// Test case for 29342
@ -2727,18 +2727,18 @@ func (s *DockerDaemonSuite) TestExecWithUserAfterLiveRestore(c *check.C) {
// Wait for shell command to be completed
_, err = s.d.Cmd("exec", "top", "sh", "-c", `for i in $(seq 1 5); do if [ -e /adduser_end ]; then rm -f /adduser_end && break; else sleep 1 && false; fi; done`)
c.Assert(err, check.IsNil, check.Commentf("Timeout waiting for shell command to be completed"))
assert.Assert(c, err, check.IsNil, check.Commentf("Timeout waiting for shell command to be completed"))
out1, err := s.d.Cmd("exec", "-u", "test", "top", "id")
// uid=100(test) gid=101(test) groups=101(test)
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out1))
assert.Assert(c, err, check.IsNil, check.Commentf("Output: %s", out1))
// restart daemon.
s.d.Restart(c, "--live-restore")
out2, err := s.d.Cmd("exec", "-u", "test", "top", "id")
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out2))
c.Assert(out2, check.Equals, out1, check.Commentf("Output: before restart '%s', after restart '%s'", out1, out2))
assert.Assert(c, err, check.IsNil, check.Commentf("Output: %s", out2))
assert.Assert(c, out2, check.Equals, out1, check.Commentf("Output: before restart '%s', after restart '%s'", out1, out2))
out, err = s.d.Cmd("stop", "top")
assert.NilError(c, err, "Output: %s", out)
@ -2790,7 +2790,7 @@ func (s *DockerDaemonSuite) TestRestartPolicyWithLiveRestore(c *check.C) {
StartedAt time.Time
}
out, err = s.d.Cmd("inspect", "-f", "{{json .State}}", id)
c.Assert(err, checker.IsNil, check.Commentf("output: %s", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("output: %s", out))
var origState state
err = json.Unmarshal([]byte(strings.TrimSpace(out)), &origState)
@ -2816,7 +2816,7 @@ func (s *DockerDaemonSuite) TestRestartPolicyWithLiveRestore(c *check.C) {
}
out, err := s.d.Cmd("inspect", "-f", "{{json .State}}", id)
c.Assert(err, checker.IsNil, check.Commentf("output: %s", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("output: %s", out))
var newState state
err = json.Unmarshal([]byte(strings.TrimSpace(out)), &newState)
@ -2845,23 +2845,23 @@ func (s *DockerDaemonSuite) TestShmSize(c *check.C) {
name := "shm1"
out, err := s.d.Cmd("run", "--name", name, "busybox", "mount")
assert.NilError(c, err, "Output: %s", out)
c.Assert(pattern.MatchString(out), checker.True)
assert.Assert(c, pattern.MatchString(out), checker.True)
out, err = s.d.Cmd("inspect", "--format", "{{.HostConfig.ShmSize}}", name)
assert.NilError(c, err, "Output: %s", out)
c.Assert(strings.TrimSpace(out), check.Equals, fmt.Sprintf("%v", size))
assert.Assert(c, strings.TrimSpace(out), check.Equals, fmt.Sprintf("%v", size))
}
func (s *DockerDaemonSuite) TestShmSizeReload(c *check.C) {
testRequires(c, DaemonIsLinux)
configPath, err := ioutil.TempDir("", "test-daemon-shm-size-reload-config")
c.Assert(err, checker.IsNil, check.Commentf("could not create temp file for config reload"))
assert.Assert(c, err, checker.IsNil, check.Commentf("could not create temp file for config reload"))
defer os.RemoveAll(configPath) // clean up
configFile := filepath.Join(configPath, "config.json")
size := 67108864 * 2
configData := []byte(fmt.Sprintf(`{"default-shm-size": "%dM"}`, size/1024/1024))
c.Assert(ioutil.WriteFile(configFile, configData, 0666), checker.IsNil, check.Commentf("could not write temp file for config reload"))
assert.Assert(c, ioutil.WriteFile(configFile, configData, 0666), checker.IsNil, check.Commentf("could not write temp file for config reload"))
pattern := regexp.MustCompile(fmt.Sprintf("shm on /dev/shm type tmpfs(.*)size=%dk", size/1024))
s.d.StartWithBusybox(c, "--config-file", configFile)
@ -2869,26 +2869,26 @@ func (s *DockerDaemonSuite) TestShmSizeReload(c *check.C) {
name := "shm1"
out, err := s.d.Cmd("run", "--name", name, "busybox", "mount")
assert.NilError(c, err, "Output: %s", out)
c.Assert(pattern.MatchString(out), checker.True)
assert.Assert(c, pattern.MatchString(out), checker.True)
out, err = s.d.Cmd("inspect", "--format", "{{.HostConfig.ShmSize}}", name)
assert.NilError(c, err, "Output: %s", out)
c.Assert(strings.TrimSpace(out), check.Equals, fmt.Sprintf("%v", size))
assert.Assert(c, strings.TrimSpace(out), check.Equals, fmt.Sprintf("%v", size))
size = 67108864 * 3
configData = []byte(fmt.Sprintf(`{"default-shm-size": "%dM"}`, size/1024/1024))
c.Assert(ioutil.WriteFile(configFile, configData, 0666), checker.IsNil, check.Commentf("could not write temp file for config reload"))
assert.Assert(c, ioutil.WriteFile(configFile, configData, 0666), checker.IsNil, check.Commentf("could not write temp file for config reload"))
pattern = regexp.MustCompile(fmt.Sprintf("shm on /dev/shm type tmpfs(.*)size=%dk", size/1024))
err = s.d.ReloadConfig()
c.Assert(err, checker.IsNil, check.Commentf("error reloading daemon config"))
assert.Assert(c, err, checker.IsNil, check.Commentf("error reloading daemon config"))
name = "shm2"
out, err = s.d.Cmd("run", "--name", name, "busybox", "mount")
assert.NilError(c, err, "Output: %s", out)
c.Assert(pattern.MatchString(out), checker.True)
assert.Assert(c, pattern.MatchString(out), checker.True)
out, err = s.d.Cmd("inspect", "--format", "{{.HostConfig.ShmSize}}", name)
assert.NilError(c, err, "Output: %s", out)
c.Assert(strings.TrimSpace(out), check.Equals, fmt.Sprintf("%v", size))
assert.Assert(c, strings.TrimSpace(out), check.Equals, fmt.Sprintf("%v", size))
}
func testDaemonStartIpcMode(c *check.C, from, mode string, valid bool) {

View file

@ -287,8 +287,8 @@ func (s *DockerExternalVolumeSuite) TestVolumeCLICreateOptionConflict(c *check.C
dockerCmd(c, "volume", "create", "test")
out, _, err := dockerCmdWithError("volume", "create", "test", "--driver", volumePluginName)
c.Assert(err, check.NotNil, check.Commentf("volume create exception name already in use with another driver"))
c.Assert(out, checker.Contains, "must be unique")
assert.Assert(c, err, check.NotNil, check.Commentf("volume create exception name already in use with another driver"))
assert.Assert(c, out, checker.Contains, "must be unique")
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Driver }}", "test")
_, _, err = dockerCmdWithError("volume", "create", "test", "--driver", strings.TrimSpace(out))
@ -300,7 +300,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *check.C) {
out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, s.Server.URL)
assert.Assert(c, out, checker.Contains, s.Server.URL)
_, err = s.d.Cmd("volume", "rm", "external-volume-test")
assert.NilError(c, err)
@ -308,13 +308,13 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverNamed(c *check.C) {
p := hostVolumePath("external-volume-test")
_, err = os.Lstat(p)
assert.ErrorContains(c, err, "")
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("Expected volume path in host to not exist: %s, %v\n", p, err))
assert.Assert(c, os.IsNotExist(err), checker.True, check.Commentf("Expected volume path in host to not exist: %s, %v\n", p, err))
c.Assert(s.ec.activations, checker.Equals, 1)
c.Assert(s.ec.creations, checker.Equals, 1)
c.Assert(s.ec.removals, checker.Equals, 1)
c.Assert(s.ec.mounts, checker.Equals, 1)
c.Assert(s.ec.unmounts, checker.Equals, 1)
assert.Assert(c, s.ec.activations, checker.Equals, 1)
assert.Assert(c, s.ec.creations, checker.Equals, 1)
assert.Assert(c, s.ec.removals, checker.Equals, 1)
assert.Assert(c, s.ec.mounts, checker.Equals, 1)
assert.Assert(c, s.ec.unmounts, checker.Equals, 1)
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnnamed(c *check.C) {
@ -322,13 +322,13 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnnamed(c *check.C)
out, err := s.d.Cmd("run", "--rm", "--name", "test-data", "-v", "/tmp/external-volume-test", "--volume-driver", volumePluginName, "busybox:latest", "cat", "/tmp/external-volume-test/test")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, s.Server.URL)
assert.Assert(c, out, checker.Contains, s.Server.URL)
c.Assert(s.ec.activations, checker.Equals, 1)
c.Assert(s.ec.creations, checker.Equals, 1)
c.Assert(s.ec.removals, checker.Equals, 1)
c.Assert(s.ec.mounts, checker.Equals, 1)
c.Assert(s.ec.unmounts, checker.Equals, 1)
assert.Assert(c, s.ec.activations, checker.Equals, 1)
assert.Assert(c, s.ec.creations, checker.Equals, 1)
assert.Assert(c, s.ec.removals, checker.Equals, 1)
assert.Assert(c, s.ec.mounts, checker.Equals, 1)
assert.Assert(c, s.ec.unmounts, checker.Equals, 1)
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverVolumesFrom(c *check.C) {
@ -343,11 +343,11 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverVolumesFrom(c *check
out, err = s.d.Cmd("rm", "-fv", "vol-test1")
assert.NilError(c, err, out)
c.Assert(s.ec.activations, checker.Equals, 1)
c.Assert(s.ec.creations, checker.Equals, 1)
c.Assert(s.ec.removals, checker.Equals, 1)
c.Assert(s.ec.mounts, checker.Equals, 2)
c.Assert(s.ec.unmounts, checker.Equals, 2)
assert.Assert(c, s.ec.activations, checker.Equals, 1)
assert.Assert(c, s.ec.creations, checker.Equals, 1)
assert.Assert(c, s.ec.removals, checker.Equals, 1)
assert.Assert(c, s.ec.mounts, checker.Equals, 2)
assert.Assert(c, s.ec.unmounts, checker.Equals, 2)
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverDeleteContainer(c *check.C) {
@ -359,11 +359,11 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverDeleteContainer(c *c
out, err = s.d.Cmd("rm", "-fv", "vol-test1")
assert.NilError(c, err, out)
c.Assert(s.ec.activations, checker.Equals, 1)
c.Assert(s.ec.creations, checker.Equals, 1)
c.Assert(s.ec.removals, checker.Equals, 1)
c.Assert(s.ec.mounts, checker.Equals, 1)
c.Assert(s.ec.unmounts, checker.Equals, 1)
assert.Assert(c, s.ec.activations, checker.Equals, 1)
assert.Assert(c, s.ec.creations, checker.Equals, 1)
assert.Assert(c, s.ec.removals, checker.Equals, 1)
assert.Assert(c, s.ec.mounts, checker.Equals, 1)
assert.Assert(c, s.ec.unmounts, checker.Equals, 1)
}
func hostVolumePath(name string) string {
@ -382,10 +382,10 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c *
cmd1 := exec.Command(dockerBinary, "volume", "create", "-d", "down-driver")
cmd2 := exec.Command(dockerBinary, "volume", "create")
c.Assert(cmd1.Start(), checker.IsNil)
assert.Assert(c, cmd1.Start(), checker.IsNil)
defer cmd1.Process.Kill()
time.Sleep(100 * time.Millisecond) // ensure API has been called
c.Assert(cmd2.Start(), checker.IsNil)
assert.Assert(c, cmd2.Start(), checker.IsNil)
go func() {
cmd1.Wait()
@ -437,11 +437,11 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverRetryNotImmediatelyE
_, err := s.d.Cmd("volume", "rm", "external-volume-test")
assert.NilError(c, err)
c.Assert(p.ec.activations, checker.Equals, 1)
c.Assert(p.ec.creations, checker.Equals, 1)
c.Assert(p.ec.removals, checker.Equals, 1)
c.Assert(p.ec.mounts, checker.Equals, 1)
c.Assert(p.ec.unmounts, checker.Equals, 1)
assert.Assert(c, p.ec.activations, checker.Equals, 1)
assert.Assert(c, p.ec.creations, checker.Equals, 1)
assert.Assert(c, p.ec.removals, checker.Equals, 1)
assert.Assert(c, p.ec.mounts, checker.Equals, 1)
assert.Assert(c, p.ec.unmounts, checker.Equals, 1)
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c *check.C) {
@ -453,31 +453,31 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c
Driver string
}
out := inspectFieldJSON(c, "testing", "Mounts")
c.Assert(json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil)
c.Assert(len(mounts), checker.Equals, 1, check.Commentf("%s", out))
c.Assert(mounts[0].Name, checker.Equals, "foo")
c.Assert(mounts[0].Driver, checker.Equals, volumePluginName)
assert.Assert(c, json.NewDecoder(strings.NewReader(out)).Decode(&mounts), checker.IsNil)
assert.Assert(c, len(mounts), checker.Equals, 1, check.Commentf("%s", out))
assert.Assert(c, mounts[0].Name, checker.Equals, "foo")
assert.Assert(c, mounts[0].Driver, checker.Equals, volumePluginName)
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverList(c *check.C) {
dockerCmd(c, "volume", "create", "-d", volumePluginName, "abc3")
out, _ := dockerCmd(c, "volume", "ls")
ls := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(ls), check.Equals, 2, check.Commentf("\n%s", out))
assert.Assert(c, len(ls), check.Equals, 2, check.Commentf("\n%s", out))
vol := strings.Fields(ls[len(ls)-1])
c.Assert(len(vol), check.Equals, 2, check.Commentf("%v", vol))
c.Assert(vol[0], check.Equals, volumePluginName)
c.Assert(vol[1], check.Equals, "abc3")
assert.Assert(c, len(vol), check.Equals, 2, check.Commentf("%v", vol))
assert.Assert(c, vol[0], check.Equals, volumePluginName)
assert.Assert(c, vol[1], check.Equals, "abc3")
c.Assert(s.ec.lists, check.Equals, 1)
assert.Assert(c, s.ec.lists, check.Equals, 1)
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *check.C) {
out, _, err := dockerCmdWithError("volume", "inspect", "dummy")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "No such volume")
c.Assert(s.ec.gets, check.Equals, 1)
assert.Assert(c, out, checker.Contains, "No such volume")
assert.Assert(c, s.ec.gets, check.Equals, 1)
dockerCmd(c, "volume", "create", "test", "-d", volumePluginName)
out, _ = dockerCmd(c, "volume", "inspect", "test")
@ -487,10 +487,10 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *check.C) {
}
var st []vol
c.Assert(json.Unmarshal([]byte(out), &st), checker.IsNil)
c.Assert(st, checker.HasLen, 1)
c.Assert(st[0].Status, checker.HasLen, 1, check.Commentf("%v", st[0]))
c.Assert(st[0].Status["Hello"], checker.Equals, "world", check.Commentf("%v", st[0].Status))
assert.Assert(c, json.Unmarshal([]byte(out), &st), checker.IsNil)
assert.Assert(c, st, checker.HasLen, 1)
assert.Assert(c, st[0].Status, checker.HasLen, 1, check.Commentf("%v", st[0]))
assert.Assert(c, st[0].Status["Hello"], checker.Equals, "world", check.Commentf("%v", st[0].Status))
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c *check.C) {
@ -500,8 +500,8 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c
dockerCmd(c, "run", "--name=test", "-v", "abc1:/foo", "busybox", "true")
var mounts []types.MountPoint
inspectFieldAndUnmarshall(c, "test", "Mounts", &mounts)
c.Assert(mounts, checker.HasLen, 1)
c.Assert(mounts[0].Driver, checker.Equals, volumePluginName)
assert.Assert(c, mounts, checker.HasLen, 1)
assert.Assert(c, mounts[0].Driver, checker.Equals, volumePluginName)
}
// Ensures that the daemon handles when the plugin responds to a `Get` request with a null volume and a null error.
@ -514,7 +514,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGetEmptyResponse(c *
out, err = s.d.Cmd("volume", "inspect", "abc2")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "No such volume")
assert.Assert(c, out, checker.Contains, "No such volume")
}
// Ensure only cached paths are used in volume list to prevent N+1 calls to `VolumeDriver.Path`
@ -523,15 +523,15 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGetEmptyResponse(c *
// available because the volume is not even mounted. Consider removing this test.
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverPathCalls(c *check.C) {
s.d.Start(c)
c.Assert(s.ec.paths, checker.Equals, 0)
assert.Assert(c, s.ec.paths, checker.Equals, 0)
out, err := s.d.Cmd("volume", "create", "test", "--driver=test-external-volume-driver")
assert.NilError(c, err, out)
c.Assert(s.ec.paths, checker.Equals, 0)
assert.Assert(c, s.ec.paths, checker.Equals, 0)
out, err = s.d.Cmd("volume", "ls")
assert.NilError(c, err, out)
c.Assert(s.ec.paths, checker.Equals, 0)
assert.Assert(c, s.ec.paths, checker.Equals, 0)
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverMountID(c *check.C) {
@ -545,12 +545,12 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverMountID(c *check.C)
// Check that VolumeDriver.Capabilities gets called, and only called once
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverCapabilities(c *check.C) {
s.d.Start(c)
c.Assert(s.ec.caps, checker.Equals, 0)
assert.Assert(c, s.ec.caps, checker.Equals, 0)
for i := 0; i < 3; i++ {
out, err := s.d.Cmd("volume", "create", "-d", volumePluginName, fmt.Sprintf("test%d", i))
assert.NilError(c, err, out)
c.Assert(s.ec.caps, checker.Equals, 1)
assert.Assert(c, s.ec.caps, checker.Equals, 1)
out, err = s.d.Cmd("volume", "inspect", "--format={{.Scope}}", fmt.Sprintf("test%d", i))
assert.NilError(c, err)
assert.Equal(c, strings.TrimSpace(out), volume.GlobalScope)
@ -569,7 +569,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *c
out, err = s.d.Cmd("volume", "create", "-d", "local", "--name", "test")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "must be unique")
assert.Assert(c, out, checker.Contains, "must be unique")
// simulate out of band volume deletion on plugin level
delete(p.vols, "test")
@ -583,11 +583,11 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *c
var vs []types.Volume
err = json.Unmarshal([]byte(out), &vs)
assert.NilError(c, err)
c.Assert(vs, checker.HasLen, 1)
c.Assert(vs[0].Driver, checker.Equals, driverName)
c.Assert(vs[0].Options, checker.NotNil)
c.Assert(vs[0].Options["foo"], checker.Equals, "bar")
c.Assert(vs[0].Driver, checker.Equals, driverName)
assert.Assert(c, vs, checker.HasLen, 1)
assert.Assert(c, vs[0].Driver, checker.Equals, driverName)
assert.Assert(c, vs[0].Options, checker.NotNil)
assert.Assert(c, vs[0].Options["foo"], checker.Equals, "bar")
assert.Assert(c, vs[0].Driver, checker.Equals, driverName)
// simulate out of band volume deletion on plugin level
delete(p.vols, "test")
@ -601,9 +601,9 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *c
vs = nil
err = json.Unmarshal([]byte(out), &vs)
assert.NilError(c, err)
c.Assert(vs, checker.HasLen, 1)
c.Assert(vs[0].Options, checker.HasLen, 0)
c.Assert(vs[0].Driver, checker.Equals, "local")
assert.Assert(c, vs, checker.HasLen, 1)
assert.Assert(c, vs[0].Options, checker.HasLen, 0)
assert.Assert(c, vs[0].Driver, checker.Equals, "local")
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnMountFail(c *check.C) {
@ -611,9 +611,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")
c.Assert(s.ec.unmounts, checker.Equals, 0, check.Commentf("%s", out))
assert.Assert(c, s.ec.unmounts, checker.Equals, 0, check.Commentf("%s", out))
out, _ = s.d.Cmd("run", "-w", "/foo", "-v", "testumount:/foo", "busybox", "true")
c.Assert(s.ec.unmounts, checker.Equals, 0, check.Commentf("%s", out))
assert.Assert(c, s.ec.unmounts, checker.Equals, 0, check.Commentf("%s", out))
}
func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnCp(c *check.C) {
@ -621,12 +621,12 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverUnmountOnCp(c *check
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")
c.Assert(s.ec.mounts, checker.Equals, 1, check.Commentf("%s", out))
assert.Assert(c, s.ec.mounts, checker.Equals, 1, check.Commentf("%s", out))
out, _ = s.d.Cmd("cp", "test:/test", "/tmp/test")
c.Assert(s.ec.mounts, checker.Equals, 2, check.Commentf("%s", out))
c.Assert(s.ec.unmounts, checker.Equals, 1, check.Commentf("%s", out))
assert.Assert(c, s.ec.mounts, checker.Equals, 2, check.Commentf("%s", out))
assert.Assert(c, s.ec.unmounts, checker.Equals, 1, check.Commentf("%s", out))
out, _ = s.d.Cmd("kill", "test")
c.Assert(s.ec.unmounts, checker.Equals, 2, check.Commentf("%s", out))
assert.Assert(c, s.ec.unmounts, checker.Equals, 2, check.Commentf("%s", out))
}

View file

@ -20,7 +20,7 @@ func waitForHealthStatus(c *check.C, name string, prev string, expected string)
if out == expected {
return
}
c.Assert(out, checker.Equals, prev)
assert.Assert(c, out, checker.Equals, prev)
if out != prev {
return
}
@ -32,7 +32,7 @@ func getHealth(c *check.C, name string) *types.Health {
out, _ := dockerCmd(c, "inspect", "--format={{json .State.Health}}", name)
var health types.Health
err := json.Unmarshal([]byte(out), &health)
c.Assert(err, checker.Equals, nil)
assert.Assert(c, err, checker.Equals, nil)
return &health
}
@ -54,12 +54,12 @@ func (s *DockerSuite) TestHealth(c *check.C) {
cid, _ := dockerCmd(c, "create", "--name", name, imageName)
out, _ := dockerCmd(c, "ps", "-a", "--format={{.ID}} {{.Status}}")
out = RemoveOutputForExistingElements(out, existingContainers)
c.Assert(out, checker.Equals, cid[:12]+" Created\n")
assert.Assert(c, out, checker.Equals, cid[:12]+" Created\n")
// Inspect the options
out, _ = dockerCmd(c, "inspect",
"--format=timeout={{.Config.Healthcheck.Timeout}} interval={{.Config.Healthcheck.Interval}} retries={{.Config.Healthcheck.Retries}} test={{.Config.Healthcheck.Test}}", name)
c.Assert(out, checker.Equals, "timeout=30s interval=1s retries=0 test=[CMD-SHELL cat /status]\n")
assert.Assert(c, out, checker.Equals, "timeout=30s interval=1s retries=0 test=[CMD-SHELL cat /status]\n")
// Start
dockerCmd(c, "start", name)
@ -71,7 +71,7 @@ func (s *DockerSuite) TestHealth(c *check.C) {
// Inspect the status
out, _ = dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name)
c.Assert(out, checker.Equals, "unhealthy\n")
assert.Assert(c, out, checker.Equals, "unhealthy\n")
// Make it healthy again
dockerCmd(c, "exec", name, "touch", "/status")
@ -83,7 +83,7 @@ func (s *DockerSuite) TestHealth(c *check.C) {
// Disable the check from the CLI
dockerCmd(c, "create", "--name=noh", "--no-healthcheck", imageName)
out, _ = dockerCmd(c, "inspect", "--format={{.Config.Healthcheck.Test}}", "noh")
c.Assert(out, checker.Equals, "[NONE]\n")
assert.Assert(c, out, checker.Equals, "[NONE]\n")
dockerCmd(c, "rm", "noh")
// Disable the check with a new build
@ -91,7 +91,7 @@ func (s *DockerSuite) TestHealth(c *check.C) {
HEALTHCHECK NONE`))
out, _ = dockerCmd(c, "inspect", "--format={{.Config.Healthcheck.Test}}", "no_healthcheck")
c.Assert(out, checker.Equals, "[NONE]\n")
assert.Assert(c, out, checker.Equals, "[NONE]\n")
// Enable the checks from the CLI
_, _ = dockerCmd(c, "run", "-d", "--name=fatal_healthcheck",
@ -101,11 +101,11 @@ func (s *DockerSuite) TestHealth(c *check.C) {
"no_healthcheck")
waitForHealthStatus(c, "fatal_healthcheck", "starting", "healthy")
health := getHealth(c, "fatal_healthcheck")
c.Assert(health.Status, checker.Equals, "healthy")
c.Assert(health.FailingStreak, checker.Equals, 0)
assert.Assert(c, health.Status, checker.Equals, "healthy")
assert.Assert(c, health.FailingStreak, checker.Equals, 0)
last := health.Log[len(health.Log)-1]
c.Assert(last.ExitCode, checker.Equals, 0)
c.Assert(last.Output, checker.Equals, "OK\n")
assert.Assert(c, last.ExitCode, checker.Equals, 0)
assert.Assert(c, last.Output, checker.Equals, "OK\n")
// Fail the check
dockerCmd(c, "exec", "fatal_healthcheck", "rm", "/status")
@ -113,8 +113,8 @@ func (s *DockerSuite) TestHealth(c *check.C) {
failsStr, _ := dockerCmd(c, "inspect", "--format={{.State.Health.FailingStreak}}", "fatal_healthcheck")
fails, err := strconv.Atoi(strings.TrimSpace(failsStr))
c.Assert(err, check.IsNil)
c.Assert(fails >= 3, checker.Equals, true)
assert.Assert(c, err, check.IsNil)
assert.Assert(c, fails >= 3, checker.Equals, true)
dockerCmd(c, "rm", "-f", "fatal_healthcheck")
// Check timeout
@ -125,9 +125,9 @@ func (s *DockerSuite) TestHealth(c *check.C) {
waitForHealthStatus(c, "test", "starting", "unhealthy")
health = getHealth(c, "test")
last = health.Log[len(health.Log)-1]
c.Assert(health.Status, checker.Equals, "unhealthy")
c.Assert(last.ExitCode, checker.Equals, -1)
c.Assert(last.Output, checker.Equals, "Health check exceeded timeout (1s)")
assert.Assert(c, health.Status, checker.Equals, "unhealthy")
assert.Assert(c, last.ExitCode, checker.Equals, -1)
assert.Assert(c, last.Output, checker.Equals, "Health check exceeded timeout (1s)")
dockerCmd(c, "rm", "-f", "test")
// Check JSON-format
@ -139,7 +139,7 @@ func (s *DockerSuite) TestHealth(c *check.C) {
CMD ["cat", "/my status"]`))
out, _ = dockerCmd(c, "inspect",
"--format={{.Config.Healthcheck.Test}}", imageName)
c.Assert(out, checker.Equals, "[CMD cat /my status]\n")
assert.Assert(c, out, checker.Equals, "[CMD cat /my status]\n")
}

View file

@ -50,7 +50,7 @@ LABEL label.Z="Z"`))
for i := 0; i < 26; i++ {
echoValue := fmt.Sprintf("LABEL label.%s=%s", expectedValues[i], expectedValues[i])
actualValue := actualValues[i]
c.Assert(actualValue, checker.Contains, echoValue)
assert.Assert(c, actualValue, checker.Contains, echoValue)
}
}
@ -61,7 +61,7 @@ func (s *DockerSuite) TestHistoryExistentImage(c *check.C) {
func (s *DockerSuite) TestHistoryNonExistentImage(c *check.C) {
_, _, err := dockerCmdWithError("history", "testHistoryNonExistentImage")
c.Assert(err, checker.NotNil, check.Commentf("history on a non-existent image should fail."))
assert.Assert(c, err, checker.NotNil, check.Commentf("history on a non-existent image should fail."))
}
func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
@ -80,7 +80,7 @@ func (s *DockerSuite) TestHistoryImageWithComment(c *check.C) {
out, _ := dockerCmd(c, "history", name)
outputTabs := strings.Fields(strings.Split(out, "\n")[1])
actualValue := outputTabs[len(outputTabs)-1]
c.Assert(actualValue, checker.Contains, comment)
assert.Assert(c, actualValue, checker.Contains, comment)
}
func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
@ -97,7 +97,7 @@ func (s *DockerSuite) TestHistoryHumanOptionFalse(c *check.C) {
sizeString := lines[i][startIndex:endIndex]
_, err := strconv.Atoi(strings.TrimSpace(sizeString))
c.Assert(err, checker.IsNil, check.Commentf("The size '%s' was not an Integer", sizeString))
assert.Assert(c, err, checker.IsNil, check.Commentf("The size '%s' was not an Integer", sizeString))
}
}
@ -114,6 +114,6 @@ func (s *DockerSuite) TestHistoryHumanOptionTrue(c *check.C) {
endIndex = len(lines[i])
}
sizeString := lines[i][startIndex:endIndex]
c.Assert(strings.TrimSpace(sizeString), checker.Matches, humanSizeRegexRaw, check.Commentf("The size '%s' was not in human format", sizeString))
assert.Assert(c, strings.TrimSpace(sizeString), checker.Matches, humanSizeRegexRaw, check.Commentf("The size '%s' was not in human format", sizeString))
}
}

View file

@ -21,7 +21,7 @@ import (
func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) {
imagesOut, _ := dockerCmd(c, "images")
c.Assert(imagesOut, checker.Contains, "busybox")
assert.Assert(c, imagesOut, checker.Contains, "busybox")
}
func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *check.C) {
@ -31,21 +31,21 @@ func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *check.C) {
dockerCmd(c, "tag", "busybox", name+":v2")
imagesOut, _ := dockerCmd(c, "images", name+":v1")
c.Assert(imagesOut, checker.Contains, name)
c.Assert(imagesOut, checker.Contains, "v1")
c.Assert(imagesOut, checker.Not(checker.Contains), "v2")
c.Assert(imagesOut, checker.Not(checker.Contains), "v1v1")
assert.Assert(c, imagesOut, checker.Contains, name)
assert.Assert(c, imagesOut, checker.Contains, "v1")
assert.Assert(c, imagesOut, checker.Not(checker.Contains), "v2")
assert.Assert(c, imagesOut, checker.Not(checker.Contains), "v1v1")
imagesOut, _ = dockerCmd(c, "images", name)
c.Assert(imagesOut, checker.Contains, name)
c.Assert(imagesOut, checker.Contains, "v1")
c.Assert(imagesOut, checker.Contains, "v1v1")
c.Assert(imagesOut, checker.Contains, "v2")
assert.Assert(c, imagesOut, checker.Contains, name)
assert.Assert(c, imagesOut, checker.Contains, "v1")
assert.Assert(c, imagesOut, checker.Contains, "v1v1")
assert.Assert(c, imagesOut, checker.Contains, "v2")
}
func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) {
imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent")
c.Assert(imagesOut, checker.Not(checker.Contains), "busybox")
assert.Assert(c, imagesOut, checker.Not(checker.Contains), "busybox")
}
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
@ -63,15 +63,15 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
imgs := strings.Split(out, "\n")
c.Assert(imgs[0], checker.Equals, id3, check.Commentf("First image must be %s, got %s", id3, imgs[0]))
c.Assert(imgs[1], checker.Equals, id2, check.Commentf("First image must be %s, got %s", id2, imgs[1]))
c.Assert(imgs[2], checker.Equals, id1, check.Commentf("First image must be %s, got %s", id1, imgs[2]))
assert.Assert(c, imgs[0], checker.Equals, id3, check.Commentf("First image must be %s, got %s", id3, imgs[0]))
assert.Assert(c, imgs[1], checker.Equals, id2, check.Commentf("First image must be %s, got %s", id2, imgs[1]))
assert.Assert(c, imgs[2], checker.Equals, id1, check.Commentf("First image must be %s, got %s", id1, imgs[2]))
}
func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *check.C) {
out, _, err := dockerCmdWithError("images", "-f", "FOO=123")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Invalid filter")
assert.Assert(c, out, checker.Contains, "Invalid filter")
}
func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) {
@ -92,9 +92,9 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) {
out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
out = strings.TrimSpace(out)
c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image1ID))
c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image2ID))
c.Assert(out, check.Not(check.Matches), fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image3ID))
assert.Assert(c, out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image1ID))
assert.Assert(c, out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image2ID))
assert.Assert(c, out, check.Not(check.Matches), fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image3ID))
out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too")
out = strings.TrimSpace(out)
@ -128,34 +128,34 @@ LABEL number=3`))
expected := []string{imageID3, imageID2}
out, _ := dockerCmd(c, "images", "-f", "since=image:1", "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Assert(c, assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "since="+imageID1, "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Assert(c, assertImageList(out, expected), checker.Equals, true, check.Commentf("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")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Assert(c, assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "since="+imageID2, "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Assert(c, assertImageList(out, expected), checker.Equals, true, check.Commentf("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")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Assert(c, assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "before="+imageID3, "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Assert(c, assertImageList(out, expected), checker.Equals, true, check.Commentf("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")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Assert(c, assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "before="+imageID2, "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
assert.Assert(c, assertImageList(out, expected), checker.Equals, true, check.Commentf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
}
func assertImageList(out string, expected []string) bool {
@ -239,15 +239,15 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
// Expect one dangling image
c.Assert(strings.Count(out, imageID), checker.Equals, 1)
assert.Assert(c, strings.Count(out, imageID), checker.Equals, 1)
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=false")
//dangling=false would not include dangling images
c.Assert(out, checker.Not(checker.Contains), imageID)
assert.Assert(c, out, checker.Not(checker.Contains), imageID)
out, _ = dockerCmd(c, "images")
//docker images still include dangling images
c.Assert(out, checker.Contains, imageID)
assert.Assert(c, out, checker.Contains, imageID)
}
@ -255,7 +255,7 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) {
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) {
out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Invalid filter")
assert.Assert(c, out, checker.Contains, "Invalid filter")
}
func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) {
@ -276,9 +276,9 @@ func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) {
out, _ := dockerCmd(c, "images")
// images shouldn't show non-heads images
c.Assert(out, checker.Not(checker.Contains), intermediate)
assert.Assert(c, out, checker.Not(checker.Contains), intermediate)
// images should contain final built images
c.Assert(out, checker.Contains, stringid.TruncateID(id))
assert.Assert(c, out, checker.Contains, stringid.TruncateID(id))
}
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) {
@ -293,7 +293,7 @@ func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) {
out, _ := dockerCmd(c, "images")
// images should contain images built from scratch
c.Assert(out, checker.Contains, stringid.TruncateID(id))
assert.Assert(c, out, checker.Contains, stringid.TruncateID(id))
}
// For W2W - equivalent to TestImagesEnsureImagesFromScratchShown but Windows
@ -309,7 +309,7 @@ func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *check.C) {
out, _ := dockerCmd(c, "images")
// images should contain images built from busybox
c.Assert(out, checker.Contains, stringid.TruncateID(id))
assert.Assert(c, out, checker.Contains, stringid.TruncateID(id))
}
// #18181
@ -317,13 +317,13 @@ func (s *DockerSuite) TestImagesFilterNameWithPort(c *check.C) {
tag := "a.b.c.d:5000/hello"
dockerCmd(c, "tag", "busybox", tag)
out, _ := dockerCmd(c, "images", tag)
c.Assert(out, checker.Contains, tag)
assert.Assert(c, out, checker.Contains, tag)
out, _ = dockerCmd(c, "images", tag+":latest")
c.Assert(out, checker.Contains, tag)
assert.Assert(c, out, checker.Contains, tag)
out, _ = dockerCmd(c, "images", tag+":no-such-tag")
c.Assert(out, checker.Not(checker.Contains), tag)
assert.Assert(c, out, checker.Not(checker.Contains), tag)
}
func (s *DockerSuite) TestImagesFormat(c *check.C) {

View file

@ -36,7 +36,7 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
func (s *DockerSuite) TestImportBadURL(c *check.C) {
out, _, err := dockerCmdWithError("import", "http://nourl/bad")
c.Assert(err, checker.NotNil, check.Commentf("import was supposed to fail but didn't"))
assert.Assert(c, err, checker.NotNil, check.Commentf("import was supposed to fail but didn't"))
// Depending on your system you can get either of these errors
if !strings.Contains(out, "dial tcp") &&
!strings.Contains(out, "ApplyLayer exit status 1 stdout: stderr: archive/tar: invalid tar header") &&
@ -50,7 +50,7 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to create temporary file"))
defer os.Remove(temporaryFile.Name())
icmd.RunCmd(icmd.Cmd{
@ -71,7 +71,7 @@ func (s *DockerSuite) TestImportGzipped(c *check.C) {
dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to create temporary file"))
defer os.Remove(temporaryFile.Name())
w := gzip.NewWriter(temporaryFile)
@ -79,7 +79,7 @@ func (s *DockerSuite) TestImportGzipped(c *check.C) {
Command: []string{dockerBinary, "export", "test-import"},
Stdout: w,
}).Assert(c, icmd.Success)
c.Assert(w.Close(), checker.IsNil, check.Commentf("failed to close gzip writer"))
assert.Assert(c, w.Close(), checker.IsNil, check.Commentf("failed to close gzip writer"))
temporaryFile.Close()
out, _ := dockerCmd(c, "import", temporaryFile.Name())
assert.Assert(c, strings.Count(out, "\n") == 1, "display is expected 1 '\\n' but didn't")
@ -94,7 +94,7 @@ func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
dockerCmd(c, "run", "--name", "test-import", "busybox", "true")
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to create temporary file"))
defer os.Remove(temporaryFile.Name())
icmd.RunCmd(icmd.Cmd{
@ -110,11 +110,11 @@ func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
out, _ = dockerCmd(c, "history", image)
split := strings.Split(out, "\n")
c.Assert(split, checker.HasLen, 3, check.Commentf("expected 3 lines from image history"))
assert.Assert(c, split, checker.HasLen, 3, check.Commentf("expected 3 lines from image history"))
r := regexp.MustCompile("[\\s]{2,}")
split = r.Split(split[1], -1)
c.Assert(message, checker.Equals, split[3], check.Commentf("didn't get expected value in commit message"))
assert.Assert(c, message, checker.Equals, split[3], check.Commentf("didn't get expected value in commit message"))
out, _ = dockerCmd(c, "run", "--rm", image, "true")
assert.Equal(c, out, "", "command output should've been nothing")
@ -122,7 +122,7 @@ func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
_, _, err := dockerCmdWithError("import", "example.com/myImage.tar")
c.Assert(err, checker.NotNil, check.Commentf("import non-existing file must failed"))
assert.Assert(c, err, checker.NotNil, check.Commentf("import non-existing file must failed"))
}
func (s *DockerSuite) TestImportWithQuotedChanges(c *check.C) {
@ -130,7 +130,7 @@ func (s *DockerSuite) TestImportWithQuotedChanges(c *check.C) {
cli.DockerCmd(c, "run", "--name", "test-import", "busybox", "true")
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to create temporary file"))
defer os.Remove(temporaryFile.Name())
cli.Docker(cli.Args("export", "test-import"), cli.WithStdout(bufio.NewWriter(temporaryFile))).Assert(c, icmd.Success)

View file

@ -53,14 +53,14 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
}
for _, linePrefix := range stringsToCheck {
c.Assert(out, checker.Contains, linePrefix, check.Commentf("couldn't find string %v in output", linePrefix))
assert.Assert(c, out, checker.Contains, linePrefix, check.Commentf("couldn't find string %v in output", linePrefix))
}
}
// TestInfoFormat tests `docker info --format`
func (s *DockerSuite) TestInfoFormat(c *check.C) {
out, status := dockerCmd(c, "info", "--format", "{{json .}}")
c.Assert(status, checker.Equals, 0)
assert.Assert(c, status, checker.Equals, 0)
var m map[string]interface{}
err := json.Unmarshal([]byte(out), &m)
assert.NilError(c, err)
@ -81,8 +81,8 @@ func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) {
out, err := d.Cmd("info")
assert.NilError(c, err)
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s\n", discoveryAdvertise))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s\n", discoveryAdvertise))
}
// TestInfoDiscoveryInvalidAdvertise verifies that a daemon run with
@ -124,8 +124,8 @@ func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
out, err := d.Cmd("info")
assert.NilError(c, err)
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s:2375\n", ip.String()))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Cluster Store: %s\n", discoveryBackend))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Cluster Advertise: %s:2375\n", ip.String()))
}
func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
@ -135,10 +135,10 @@ func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
dockerCmd(c, "run", "-d", "busybox", "top")
out, _ := dockerCmd(c, "info")
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]+1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]))
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]+1))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))
}
func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
@ -152,10 +152,10 @@ func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
dockerCmd(c, "pause", cleanedContainerID)
out, _ = dockerCmd(c, "info")
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]))
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]+1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]+1))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]))
}
func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
@ -169,10 +169,10 @@ func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
dockerCmd(c, "stop", cleanedContainerID)
out, _ = dockerCmd(c, "info")
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]))
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]))
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]+1))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Containers: %d\n", existing["Containers"]+1))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Running: %d\n", existing["ContainersRunning"]))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Paused: %d\n", existing["ContainersPaused"]))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]+1))
}
func (s *DockerSuite) TestInfoDebug(c *check.C) {
@ -184,13 +184,13 @@ func (s *DockerSuite) TestInfoDebug(c *check.C) {
out, err := d.Cmd("--debug", "info")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "Debug Mode (client): true\n")
c.Assert(out, checker.Contains, "Debug Mode (server): true\n")
c.Assert(out, checker.Contains, "File Descriptors")
c.Assert(out, checker.Contains, "Goroutines")
c.Assert(out, checker.Contains, "System Time")
c.Assert(out, checker.Contains, "EventsListeners")
c.Assert(out, checker.Contains, "Docker Root Dir")
assert.Assert(c, out, checker.Contains, "Debug Mode (client): true\n")
assert.Assert(c, out, checker.Contains, "Debug Mode (server): true\n")
assert.Assert(c, out, checker.Contains, "File Descriptors")
assert.Assert(c, out, checker.Contains, "Goroutines")
assert.Assert(c, out, checker.Contains, "System Time")
assert.Assert(c, out, checker.Contains, "EventsListeners")
assert.Assert(c, out, checker.Contains, "Docker Root Dir")
}
func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
@ -205,9 +205,9 @@ func (s *DockerSuite) TestInsecureRegistries(c *check.C) {
out, err := d.Cmd("info")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "Insecure Registries:\n")
c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryHost))
c.Assert(out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR))
assert.Assert(c, out, checker.Contains, "Insecure Registries:\n")
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" %s\n", registryHost))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" %s\n", registryCIDR))
}
func (s *DockerDaemonSuite) TestRegistryMirrors(c *check.C) {
@ -219,9 +219,9 @@ func (s *DockerDaemonSuite) TestRegistryMirrors(c *check.C) {
out, err := s.d.Cmd("info")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "Registry Mirrors:\n")
c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror1))
c.Assert(out, checker.Contains, fmt.Sprintf(" %s", registryMirror2))
assert.Assert(c, out, checker.Contains, "Registry Mirrors:\n")
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" %s", registryMirror1))
assert.Assert(c, out, checker.Contains, fmt.Sprintf(" %s", registryMirror2))
}
func existingContainerStates(c *check.C) map[string]int {

View file

@ -11,5 +11,5 @@ func (s *DockerSuite) TestInfoSecurityOptions(c *check.C) {
testRequires(c, testEnv.IsLocalDaemon, seccompEnabled, Apparmor, DaemonIsLinux)
out, _ := dockerCmd(c, "info")
c.Assert(out, checker.Contains, "Security Options:\n apparmor\n seccomp\n Profile: default\n")
assert.Assert(c, out, checker.Contains, "Security Options:\n apparmor\n seccomp\n Profile: default\n")
}

View file

@ -33,13 +33,13 @@ func (s *DockerSuite) TestInspectImage(c *check.C) {
imageTestID := "sha256:11f64303f0f7ffdc71f001788132bca5346831939a956e3e975c93267d89a16d"
id := inspectField(c, imageTest, "Id")
c.Assert(id, checker.Equals, imageTestID)
assert.Assert(c, id, checker.Equals, imageTestID)
}
func (s *DockerSuite) TestInspectInt64(c *check.C) {
dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory")
c.Assert(inspectOut, checker.Equals, "314572800")
assert.Assert(c, inspectOut, checker.Equals, "314572800")
}
func (s *DockerSuite) TestInspectDefault(c *check.C) {
@ -50,7 +50,7 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) {
containerID := strings.TrimSpace(out)
inspectOut := inspectField(c, "busybox", "Id")
c.Assert(strings.TrimSpace(inspectOut), checker.Equals, containerID)
assert.Assert(c, strings.TrimSpace(inspectOut), checker.Equals, containerID)
}
func (s *DockerSuite) TestInspectStatus(c *check.C) {
@ -58,23 +58,23 @@ func (s *DockerSuite) TestInspectStatus(c *check.C) {
out = strings.TrimSpace(out)
inspectOut := inspectField(c, out, "State.Status")
c.Assert(inspectOut, checker.Equals, "running")
assert.Assert(c, inspectOut, checker.Equals, "running")
// Windows does not support pause/unpause on Windows Server Containers.
// (RS1 does for Hyper-V Containers, but production CI is not setup for that)
if testEnv.OSType != "windows" {
dockerCmd(c, "pause", out)
inspectOut = inspectField(c, out, "State.Status")
c.Assert(inspectOut, checker.Equals, "paused")
assert.Assert(c, inspectOut, checker.Equals, "paused")
dockerCmd(c, "unpause", out)
inspectOut = inspectField(c, out, "State.Status")
c.Assert(inspectOut, checker.Equals, "running")
assert.Assert(c, inspectOut, checker.Equals, "running")
}
dockerCmd(c, "stop", out)
inspectOut = inspectField(c, out, "State.Status")
c.Assert(inspectOut, checker.Equals, "exited")
assert.Assert(c, inspectOut, checker.Equals, "exited")
}
@ -109,7 +109,7 @@ func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
out, _ := dockerCmd(c, "inspect", "--type=image", "busybox")
// not an image JSON
c.Assert(out, checker.Not(checker.Contains), "State")
assert.Assert(c, out, checker.Not(checker.Contains), "State")
}
func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
@ -119,9 +119,9 @@ func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
c.Assert(err, checker.NotNil, check.Commentf("%d", exitCode))
c.Assert(exitCode, checker.Equals, 1, check.Commentf("%s", err))
c.Assert(out, checker.Contains, "not a valid value for --type")
assert.Assert(c, err, checker.NotNil, check.Commentf("%d", exitCode))
assert.Assert(c, exitCode, checker.Equals, 1, check.Commentf("%s", err))
assert.Assert(c, out, checker.Contains, "not a valid value for --type")
}
func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
@ -130,14 +130,14 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
out := inspectField(c, imageTest, "Size")
size, err := strconv.Atoi(out)
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect size of the image: %s, %v", out, err))
assert.Assert(c, err, checker.IsNil, check.Commentf("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)
out, _ = dockerCmd(c, "inspect", formatStr, imageTest)
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
assert.NilError(c, err)
c.Assert(result, checker.Equals, true)
assert.Assert(c, result, checker.Equals, true)
}
func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
@ -152,14 +152,14 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
out = inspectField(c, id, "State.ExitCode")
exitCode, err := strconv.Atoi(out)
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err))
assert.Assert(c, err, checker.IsNil, check.Commentf("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)
out, _ = dockerCmd(c, "inspect", formatStr, id)
inspectResult, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
assert.NilError(c, err)
c.Assert(inspectResult, checker.Equals, true)
assert.Assert(c, inspectResult, checker.Equals, true)
}
func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
@ -172,12 +172,12 @@ func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
deviceID := inspectField(c, imageTest, "GraphDriver.Data.DeviceId")
_, err := strconv.Atoi(deviceID)
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
deviceSize := inspectField(c, imageTest, "GraphDriver.Data.DeviceSize")
_, err = strconv.ParseUint(deviceSize, 10, 64)
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
}
func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
@ -194,15 +194,15 @@ func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
deviceID := inspectField(c, out, "GraphDriver.Data.DeviceId")
c.Assert(imageDeviceID, checker.Not(checker.Equals), deviceID)
assert.Assert(c, imageDeviceID, checker.Not(checker.Equals), deviceID)
_, err := strconv.Atoi(deviceID)
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
deviceSize := inspectField(c, out, "GraphDriver.Data.DeviceSize")
_, err = strconv.ParseUint(deviceSize, 10, 64)
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
}
func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
@ -223,18 +223,18 @@ func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
assert.NilError(c, err)
// check that there is only one mountpoint
c.Assert(mp, check.HasLen, 1)
assert.Assert(c, mp, check.HasLen, 1)
m := mp[0]
c.Assert(m.Name, checker.Equals, "")
c.Assert(m.Driver, checker.Equals, "")
c.Assert(m.Source, checker.Equals, prefix+slash+"data")
c.Assert(m.Destination, checker.Equals, prefix+slash+"data")
assert.Assert(c, m.Name, checker.Equals, "")
assert.Assert(c, m.Driver, checker.Equals, "")
assert.Assert(c, m.Source, checker.Equals, prefix+slash+"data")
assert.Assert(c, m.Destination, checker.Equals, prefix+slash+"data")
if testEnv.OSType != "windows" { // Windows does not set mode
c.Assert(m.Mode, checker.Equals, "ro"+modifier)
assert.Assert(c, m.Mode, checker.Equals, "ro"+modifier)
}
c.Assert(m.RW, checker.Equals, false)
assert.Assert(c, m.RW, checker.Equals, false)
}
func (s *DockerSuite) TestInspectNamedMountPoint(c *check.C) {
@ -249,15 +249,15 @@ func (s *DockerSuite) TestInspectNamedMountPoint(c *check.C) {
assert.NilError(c, err)
// check that there is only one mountpoint
c.Assert(mp, checker.HasLen, 1)
assert.Assert(c, mp, checker.HasLen, 1)
m := mp[0]
c.Assert(m.Name, checker.Equals, "data")
c.Assert(m.Driver, checker.Equals, "local")
c.Assert(m.Source, checker.Not(checker.Equals), "")
c.Assert(m.Destination, checker.Equals, prefix+slash+"data")
c.Assert(m.RW, checker.Equals, true)
assert.Assert(c, m.Name, checker.Equals, "data")
assert.Assert(c, m.Driver, checker.Equals, "local")
assert.Assert(c, m.Source, checker.Not(checker.Equals), "")
assert.Assert(c, m.Destination, checker.Equals, prefix+slash+"data")
assert.Assert(c, m.RW, checker.Equals, true)
}
// #14947
@ -289,10 +289,10 @@ func (s *DockerSuite) TestInspectLogConfigNoType(c *check.C) {
out := inspectFieldJSON(c, "test", "HostConfig.LogConfig")
err := json.NewDecoder(strings.NewReader(out)).Decode(&logConfig)
c.Assert(err, checker.IsNil, check.Commentf("%v", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("%v", out))
c.Assert(logConfig.Type, checker.Equals, "json-file")
c.Assert(logConfig.Config["max-file"], checker.Equals, "42", check.Commentf("%v", logConfig))
assert.Assert(c, logConfig.Type, checker.Equals, "json-file")
assert.Assert(c, logConfig.Config["max-file"], checker.Equals, "42", check.Commentf("%v", logConfig))
}
func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
@ -304,7 +304,7 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}"
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
c.Assert(strings.TrimSpace(out), check.Equals, "<nil>,<nil>", check.Commentf("Expected not to display size info: %s", out))
assert.Assert(c, strings.TrimSpace(out), check.Equals, "<nil>,<nil>", check.Commentf("Expected not to display size info: %s", out))
}
func (s *DockerSuite) TestInspectSizeFlagContainer(c *check.C) {
@ -314,8 +314,8 @@ func (s *DockerSuite) TestInspectSizeFlagContainer(c *check.C) {
out, _ := dockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox")
sz := strings.Split(out, ",")
c.Assert(strings.TrimSpace(sz[0]), check.Not(check.Equals), "<nil>")
c.Assert(strings.TrimSpace(sz[1]), check.Not(check.Equals), "<nil>")
assert.Assert(c, strings.TrimSpace(sz[0]), check.Not(check.Equals), "<nil>")
assert.Assert(c, strings.TrimSpace(sz[1]), check.Not(check.Equals), "<nil>")
}
func (s *DockerSuite) TestInspectTemplateError(c *check.C) {
@ -324,12 +324,12 @@ func (s *DockerSuite) TestInspectTemplateError(c *check.C) {
runSleepingContainer(c, "--name=container1", "-d")
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "container1")
c.Assert(err, check.Not(check.IsNil))
c.Assert(out, checker.Contains, "Template parsing error")
assert.Assert(c, err, check.Not(check.IsNil))
assert.Assert(c, out, checker.Contains, "Template parsing error")
out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox")
c.Assert(err, check.Not(check.IsNil))
c.Assert(out, checker.Contains, "Template parsing error")
assert.Assert(c, err, check.Not(check.IsNil))
assert.Assert(c, out, checker.Contains, "Template parsing error")
}
func (s *DockerSuite) TestInspectJSONFields(c *check.C) {
@ -345,10 +345,10 @@ func (s *DockerSuite) TestInspectByPrefix(c *check.C) {
assert.Assert(c, strings.HasPrefix(id, "sha256:"))
id2 := inspectField(c, id[:12], "Id")
c.Assert(id, checker.Equals, id2)
assert.Assert(c, id, checker.Equals, id2)
id3 := inspectField(c, strings.TrimPrefix(id, "sha256:")[:12], "Id")
c.Assert(id, checker.Equals, id3)
assert.Assert(c, id, checker.Equals, id3)
}
func (s *DockerSuite) TestInspectStopWhenNotFound(c *check.C) {
@ -356,18 +356,18 @@ func (s *DockerSuite) TestInspectStopWhenNotFound(c *check.C) {
runSleepingContainer(c, "--name=busybox2", "-d")
result := dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "busybox1", "busybox2", "missing")
c.Assert(result.Error, checker.Not(check.IsNil))
c.Assert(result.Stdout(), checker.Contains, "busybox1")
c.Assert(result.Stdout(), checker.Contains, "busybox2")
c.Assert(result.Stderr(), checker.Contains, "Error: No such container: missing")
assert.Assert(c, result.Error, checker.Not(check.IsNil))
assert.Assert(c, result.Stdout(), checker.Contains, "busybox1")
assert.Assert(c, result.Stdout(), checker.Contains, "busybox2")
assert.Assert(c, result.Stderr(), checker.Contains, "Error: No such container: missing")
// test inspect would not fast fail
result = dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "missing", "busybox1", "busybox2")
c.Assert(result.Error, checker.Not(check.IsNil))
c.Assert(result.Stdout(), checker.Contains, "busybox1")
c.Assert(result.Stdout(), checker.Contains, "busybox2")
c.Assert(result.Stderr(), checker.Contains, "Error: No such container: missing")
assert.Assert(c, result.Error, checker.Not(check.IsNil))
assert.Assert(c, result.Stdout(), checker.Contains, "busybox1")
assert.Assert(c, result.Stdout(), checker.Contains, "busybox2")
assert.Assert(c, result.Stderr(), checker.Contains, "Error: No such container: missing")
}
func (s *DockerSuite) TestInspectHistory(c *check.C) {
@ -375,7 +375,7 @@ func (s *DockerSuite) TestInspectHistory(c *check.C) {
dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg")
out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "test comment")
assert.Assert(c, out, checker.Contains, "test comment")
}
func (s *DockerSuite) TestInspectContainerNetworkDefault(c *check.C) {
@ -385,7 +385,7 @@ func (s *DockerSuite) TestInspectContainerNetworkDefault(c *check.C) {
dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top")
netOut, _ := dockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge")
out := inspectField(c, contName, "NetworkSettings.Networks")
c.Assert(out, checker.Contains, "bridge")
assert.Assert(c, out, checker.Contains, "bridge")
out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID")
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
}
@ -396,7 +396,7 @@ func (s *DockerSuite) TestInspectContainerNetworkCustom(c *check.C) {
netOut, _ := dockerCmd(c, "network", "create", "net1")
dockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top")
out := inspectField(c, "container1", "NetworkSettings.Networks")
c.Assert(out, checker.Contains, "net1")
assert.Assert(c, out, checker.Contains, "net1")
out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID")
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
}
@ -416,9 +416,9 @@ func (s *DockerSuite) TestInspectAmpersand(c *check.C) {
name := "test"
out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env")
c.Assert(out, checker.Contains, `soanni&rtr`)
assert.Assert(c, out, checker.Contains, `soanni&rtr`)
out, _ = dockerCmd(c, "inspect", name)
c.Assert(out, checker.Contains, `soanni&rtr`)
assert.Assert(c, out, checker.Contains, `soanni&rtr`)
}
func (s *DockerSuite) TestInspectPlugin(c *check.C) {
@ -448,7 +448,7 @@ func (s *DockerSuite) TestInspectPlugin(c *check.C) {
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
assert.NilError(c, err)
c.Assert(out, checker.Contains, pNameWithTag)
assert.Assert(c, out, checker.Contains, pNameWithTag)
}
// Test case for 29185
@ -456,6 +456,6 @@ func (s *DockerSuite) TestInspectUnknownObject(c *check.C) {
// This test should work on both Windows and Linux
out, _, err := dockerCmdWithError("inspect", "foobar")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Error: No such object: foobar")
assert.Assert(c, out, checker.Contains, "Error: No such object: foobar")
assert.ErrorContains(c, err, "Error: No such object: foobar")
}

View file

@ -18,7 +18,7 @@ func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) {
_, 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
c.Assert(exitCode, checker.Equals, 1, check.Commentf("error: %v", err))
assert.Assert(c, exitCode, checker.Equals, 1, check.Commentf("error: %v", err))
}
// Test for appropriate error when calling --link with an invalid target container
@ -27,11 +27,11 @@ func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) {
out, _, err := dockerCmdWithError("run", "--link", "bogus:alias", "busybox", "true")
// an invalid container target should produce an error
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("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
c.Assert(strings.ToLower(out), checker.Contains, "could not get container")
assert.Assert(c, strings.ToLower(out), checker.Contains, "could not get container")
}
func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) {
@ -148,12 +148,12 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) {
out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top")
idTwo := strings.TrimSpace(out)
c.Assert(waitRun(idTwo), checker.IsNil)
assert.Assert(c, waitRun(idTwo), checker.IsNil)
readContainerFileWithExec(c, idOne, "/etc/hosts")
contentTwo := readContainerFileWithExec(c, idTwo, "/etc/hosts")
// Host is not present in updated hosts file
c.Assert(string(contentTwo), checker.Contains, "onetwo")
assert.Assert(c, string(contentTwo), checker.Contains, "onetwo")
}
func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
@ -169,33 +169,33 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
getIP := func(hosts []byte, hostname string) string {
re := regexp.MustCompile(fmt.Sprintf(`(\S*)\t%s`, regexp.QuoteMeta(hostname)))
matches := re.FindSubmatch(hosts)
c.Assert(matches, checker.NotNil, check.Commentf("Hostname %s have no matches in hosts", hostname))
assert.Assert(c, matches, checker.NotNil, check.Commentf("Hostname %s have no matches in hosts", hostname))
return string(matches[1])
}
ip := getIP(content, "one")
c.Assert(ip, checker.Equals, realIP)
assert.Assert(c, ip, checker.Equals, realIP)
ip = getIP(content, "onetwo")
c.Assert(ip, checker.Equals, realIP)
assert.Assert(c, ip, checker.Equals, realIP)
dockerCmd(c, "restart", "one")
realIP = inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress")
content = readContainerFileWithExec(c, id, "/etc/hosts")
ip = getIP(content, "one")
c.Assert(ip, checker.Equals, realIP)
assert.Assert(c, ip, checker.Equals, realIP)
ip = getIP(content, "onetwo")
c.Assert(ip, checker.Equals, realIP)
assert.Assert(c, ip, checker.Equals, realIP)
}
func (s *DockerSuite) TestLinksEnvs(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
out, _ := dockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env")
c.Assert(out, checker.Contains, "FIRST_ENV_e1=\n")
c.Assert(out, checker.Contains, "FIRST_ENV_e2=v2")
c.Assert(out, checker.Contains, "FIRST_ENV_e3=v3=v3")
assert.Assert(c, out, checker.Contains, "FIRST_ENV_e1=\n")
assert.Assert(c, out, checker.Contains, "FIRST_ENV_e2=v2")
assert.Assert(c, out, checker.Contains, "FIRST_ENV_e3=v3=v3")
}
func (s *DockerSuite) TestLinkShortDefinition(c *check.C) {
@ -203,15 +203,15 @@ func (s *DockerSuite) TestLinkShortDefinition(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top")
cid := strings.TrimSpace(out)
c.Assert(waitRun(cid), checker.IsNil)
assert.Assert(c, waitRun(cid), checker.IsNil)
out, _ = dockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top")
cid2 := strings.TrimSpace(out)
c.Assert(waitRun(cid2), checker.IsNil)
assert.Assert(c, waitRun(cid2), checker.IsNil)
links := inspectFieldJSON(c, cid2, "HostConfig.Links")
c.Assert(links, checker.Equals, "[\"/shortlinkdef:/link2/shortlinkdef\"]")
assert.Assert(c, links, checker.Equals, "[\"/shortlinkdef:/link2/shortlinkdef\"]")
}
func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {
@ -220,16 +220,16 @@ func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {
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
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
// Running container linking to a container with --net host should have failed
c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error())
}
func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
// /etc/hosts should be a regular file
c.Assert(out, checker.Matches, "^-.+\n")
assert.Assert(c, out, checker.Matches, "^-.+\n")
}
func (s *DockerSuite) TestLinksMultipleWithSameName(c *check.C) {

View file

@ -19,7 +19,7 @@ const stringCheckPS = "PID USER"
// stop the tests.
func dockerCmdWithFail(c *check.C, args ...string) (string, int) {
out, status, err := dockerCmdWithError(args...)
c.Assert(err, check.NotNil, check.Commentf("%v", out))
assert.Assert(c, err, check.NotNil, check.Commentf("%v", out))
return out, status
}
@ -27,70 +27,70 @@ func (s *DockerSuite) TestNetHostnameWithNetHost(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ps")
c.Assert(out, checker.Contains, stringCheckPS)
assert.Assert(c, out, checker.Contains, stringCheckPS)
}
func (s *DockerSuite) TestNetHostname(c *check.C) {
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-h=name", "busybox", "ps")
c.Assert(out, checker.Contains, stringCheckPS)
assert.Assert(c, out, checker.Contains, stringCheckPS)
out, _ = dockerCmd(c, "run", "-h=name", "--net=bridge", "busybox", "ps")
c.Assert(out, checker.Contains, stringCheckPS)
assert.Assert(c, out, checker.Contains, stringCheckPS)
out, _ = dockerCmd(c, "run", "-h=name", "--net=none", "busybox", "ps")
c.Assert(out, checker.Contains, stringCheckPS)
assert.Assert(c, out, checker.Contains, stringCheckPS)
out, _ = dockerCmdWithFail(c, "run", "-h=name", "--net=container:other", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkHostname.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictNetworkHostname.Error())
out, _ = dockerCmdWithFail(c, "run", "--net=container", "busybox", "ps")
c.Assert(out, checker.Contains, "invalid container format container:<name|id>")
assert.Assert(c, out, checker.Contains, "invalid container format container:<name|id>")
out, _ = dockerCmdWithFail(c, "run", "--net=weird", "busybox", "ps")
c.Assert(strings.ToLower(out), checker.Contains, "not found")
assert.Assert(c, strings.ToLower(out), checker.Contains, "not found")
}
func (s *DockerSuite) TestConflictContainerNetworkAndLinks(c *check.C) {
testRequires(c, DaemonIsLinux)
out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--link=zip:zap", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndLinks.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictContainerNetworkAndLinks.Error())
}
func (s *DockerSuite) TestConflictContainerNetworkHostAndLinks(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmdWithFail(c, "run", "--net=host", "--link=zip:zap", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictHostNetworkAndLinks.Error())
}
func (s *DockerSuite) TestConflictNetworkModeNetHostAndOptions(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmdWithFail(c, "run", "--net=host", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndMac.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictContainerNetworkAndMac.Error())
}
func (s *DockerSuite) TestConflictNetworkModeAndOptions(c *check.C) {
testRequires(c, DaemonIsLinux)
out, _ := dockerCmdWithFail(c, "run", "--net=container:other", "--dns=8.8.8.8", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkAndDNS.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictNetworkAndDNS.Error())
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--add-host=name:8.8.8.8", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkHosts.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictNetworkHosts.Error())
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--mac-address=92:d0:c6:0a:29:33", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictContainerNetworkAndMac.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictContainerNetworkAndMac.Error())
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "-P", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkPublishPorts.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictNetworkPublishPorts.Error())
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "-p", "8080", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkPublishPorts.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictNetworkPublishPorts.Error())
out, _ = dockerCmdWithFail(c, "run", "--net=container:other", "--expose", "8000-9000", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictNetworkExposePorts.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictNetworkExposePorts.Error())
}

View file

@ -64,7 +64,7 @@ func (s *DockerNetworkSuite) TearDownTest(c *check.C) {
func (s *DockerNetworkSuite) SetUpSuite(c *check.C) {
mux := http.NewServeMux()
s.server = httptest.NewServer(mux)
c.Assert(s.server, check.NotNil, check.Commentf("Failed to start an HTTP Server"))
assert.Assert(c, s.server, check.NotNil, check.Commentf("Failed to start an HTTP Server"))
setupRemoteNetworkDrivers(c, mux, s.server.URL, dummyNetworkDriver, dummyIPAMDriver)
}
@ -304,7 +304,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkCreateHostBind(c *check.C) {
id := strings.TrimSpace(out)
assert.NilError(c, waitRun(id))
out, _ = dockerCmd(c, "ps")
c.Assert(out, checker.Contains, "192.168.10.1:5000->5000/tcp")
assert.Assert(c, out, checker.Contains, "192.168.10.1:5000->5000/tcp")
}
func (s *DockerNetworkSuite) TestDockerNetworkRmPredefined(c *check.C) {
@ -360,7 +360,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkLsFilter(c *check.C) {
out, _ = dockerCmd(c, "network", "ls", "-f", "label=nonexistent")
outArr := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
assert.Assert(c, len(outArr), check.Equals, 1, check.Commentf("%s\n", out))
out, _ = dockerCmd(c, "network", "ls", "-f", "driver=null")
assertNwList(c, out, []string{"none"})
@ -390,7 +390,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkCreateLabel(c *check.C) {
out, _, err := dockerCmdWithError("network", "inspect", "--format={{ .Labels."+testLabel+" }}", testNet)
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), check.Equals, testValue)
assert.Assert(c, strings.TrimSpace(out), check.Equals, testValue)
dockerCmd(c, "network", "rm", testNet)
assertNwNotAvailable(c, testNet)
@ -416,9 +416,9 @@ func (s *DockerSuite) TestDockerNetworkDeleteMultiple(c *check.C) {
// 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.
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
// testDelMulti2 should fail due to network has active endpoints
c.Assert(out, checker.Contains, "has active endpoints")
assert.Assert(c, out, checker.Contains, "has active endpoints")
assertNwNotAvailable(c, "testDelMulti0")
assertNwNotAvailable(c, "testDelMulti1")
// testDelMulti2 can't be deleted, so it should exist
@ -433,7 +433,7 @@ func (s *DockerSuite) TestDockerNetworkInspect(c *check.C) {
assert.Equal(c, len(networkResources), 1)
out, _ = dockerCmd(c, "network", "inspect", "--format={{ .Name }}", "host")
c.Assert(strings.TrimSpace(out), check.Equals, "host")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "host")
}
func (s *DockerSuite) TestDockerNetworkInspectWithID(c *check.C) {
@ -441,10 +441,10 @@ func (s *DockerSuite) TestDockerNetworkInspectWithID(c *check.C) {
networkID := strings.TrimSpace(out)
assertNwIsAvailable(c, "test2")
out, _ = dockerCmd(c, "network", "inspect", "--format={{ .Id }}", "test2")
c.Assert(strings.TrimSpace(out), check.Equals, networkID)
assert.Assert(c, strings.TrimSpace(out), check.Equals, networkID)
out, _ = dockerCmd(c, "network", "inspect", "--format={{ .ID }}", "test2")
c.Assert(strings.TrimSpace(out), check.Equals, networkID)
assert.Assert(c, strings.TrimSpace(out), check.Equals, networkID)
}
func (s *DockerSuite) TestDockerInspectMultipleNetwork(c *check.C) {
@ -505,7 +505,7 @@ func (s *DockerSuite) TestDockerInspectNetworkWithContainerName(c *check.C) {
}()
out, _ := dockerCmd(c, "run", "-d", "--name", "testNetInspect1", "--net", "brNetForInspect", "busybox", "top")
c.Assert(waitRun("testNetInspect1"), check.IsNil)
assert.Assert(c, waitRun("testNetInspect1"), check.IsNil)
containerID := strings.TrimSpace(out)
defer func() {
// we don't stop container by name, because we'll rename it later
@ -530,7 +530,7 @@ func (s *DockerSuite) TestDockerInspectNetworkWithContainerName(c *check.C) {
var newNetRes []types.NetworkResource
err = json.Unmarshal([]byte(out), &newNetRes)
assert.NilError(c, err)
c.Assert(newNetRes, checker.HasLen, 1)
assert.Assert(c, newNetRes, checker.HasLen, 1)
container1, ok := newNetRes[0].Containers[containerID]
assert.Assert(c, ok)
assert.Equal(c, container1.Name, newName)
@ -541,12 +541,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnect(c *check.C) {
assertNwIsAvailable(c, "test")
nr := getNwResource(c, "test")
c.Assert(nr.Name, checker.Equals, "test")
c.Assert(len(nr.Containers), checker.Equals, 0)
assert.Assert(c, nr.Name, checker.Equals, "test")
assert.Assert(c, len(nr.Containers), checker.Equals, 0)
// run a container
out, _ := dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
c.Assert(waitRun("test"), check.IsNil)
assert.Assert(c, waitRun("test"), check.IsNil)
containerID := strings.TrimSpace(out)
// connect the container to the test network
@ -554,35 +554,35 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnect(c *check.C) {
// inspect the network to make sure container is connected
nr = getNetworkResource(c, nr.ID)
c.Assert(len(nr.Containers), checker.Equals, 1)
assert.Assert(c, len(nr.Containers), checker.Equals, 1)
// check if container IP matches network inspect
ip, _, err := net.ParseCIDR(nr.Containers[containerID].IPv4Address)
assert.NilError(c, err)
containerIP := findContainerIP(c, "test", "test")
c.Assert(ip.String(), checker.Equals, containerIP)
assert.Assert(c, ip.String(), checker.Equals, containerIP)
// disconnect container from the network
dockerCmd(c, "network", "disconnect", "test", containerID)
nr = getNwResource(c, "test")
c.Assert(nr.Name, checker.Equals, "test")
c.Assert(len(nr.Containers), checker.Equals, 0)
assert.Assert(c, nr.Name, checker.Equals, "test")
assert.Assert(c, len(nr.Containers), checker.Equals, 0)
// run another container
out, _ = dockerCmd(c, "run", "-d", "--net", "test", "--name", "test2", "busybox", "top")
c.Assert(waitRun("test2"), check.IsNil)
assert.Assert(c, waitRun("test2"), check.IsNil)
containerID = strings.TrimSpace(out)
nr = getNwResource(c, "test")
c.Assert(nr.Name, checker.Equals, "test")
c.Assert(len(nr.Containers), checker.Equals, 1)
assert.Assert(c, nr.Name, checker.Equals, "test")
assert.Assert(c, len(nr.Containers), checker.Equals, 1)
// force disconnect the container to the test network
dockerCmd(c, "network", "disconnect", "-f", "test", containerID)
nr = getNwResource(c, "test")
c.Assert(nr.Name, checker.Equals, "test")
c.Assert(len(nr.Containers), checker.Equals, 0)
assert.Assert(c, nr.Name, checker.Equals, "test")
assert.Assert(c, len(nr.Containers), checker.Equals, 0)
dockerCmd(c, "network", "rm", "test")
assertNwNotAvailable(c, "test")
@ -637,8 +637,8 @@ func (s *DockerNetworkSuite) TestDockerNetworkCustomIPAM(c *check.C) {
// Verify expected network ipam fields are there
nr := getNetworkResource(c, "br0")
c.Assert(nr.Driver, checker.Equals, "bridge")
c.Assert(nr.IPAM.Driver, checker.Equals, dummyIPAMDriver)
assert.Assert(c, nr.Driver, checker.Equals, "bridge")
assert.Assert(c, nr.IPAM.Driver, checker.Equals, dummyIPAMDriver)
// remove network and exercise remote ipam driver
dockerCmd(c, "network", "rm", "br0")
@ -654,8 +654,8 @@ func (s *DockerNetworkSuite) TestDockerNetworkIPAMOptions(c *check.C) {
// Verify expected network ipam options
nr := getNetworkResource(c, "br0")
opts := nr.IPAM.Options
c.Assert(opts["opt1"], checker.Equals, "drv1")
c.Assert(opts["opt2"], checker.Equals, "drv2")
assert.Assert(c, opts["opt1"], checker.Equals, "drv1")
assert.Assert(c, opts["opt2"], checker.Equals, "drv2")
}
func (s *DockerNetworkSuite) TestDockerNetworkNullIPAMDriver(c *check.C) {
@ -668,36 +668,36 @@ func (s *DockerNetworkSuite) TestDockerNetworkNullIPAMDriver(c *check.C) {
// Verify the inspect data contains the default subnet provided by the null
// ipam driver and no gateway, as the null ipam driver does not provide one
nr := getNetworkResource(c, "test000")
c.Assert(nr.IPAM.Driver, checker.Equals, "null")
c.Assert(len(nr.IPAM.Config), checker.Equals, 1)
c.Assert(nr.IPAM.Config[0].Subnet, checker.Equals, "0.0.0.0/0")
c.Assert(nr.IPAM.Config[0].Gateway, checker.Equals, "")
assert.Assert(c, nr.IPAM.Driver, checker.Equals, "null")
assert.Assert(c, len(nr.IPAM.Config), checker.Equals, 1)
assert.Assert(c, nr.IPAM.Config[0].Subnet, checker.Equals, "0.0.0.0/0")
assert.Assert(c, nr.IPAM.Config[0].Gateway, checker.Equals, "")
}
func (s *DockerNetworkSuite) TestDockerNetworkInspectDefault(c *check.C) {
nr := getNetworkResource(c, "none")
c.Assert(nr.Driver, checker.Equals, "null")
c.Assert(nr.Scope, checker.Equals, "local")
c.Assert(nr.Internal, checker.Equals, false)
c.Assert(nr.EnableIPv6, checker.Equals, false)
c.Assert(nr.IPAM.Driver, checker.Equals, "default")
c.Assert(len(nr.IPAM.Config), checker.Equals, 0)
assert.Assert(c, nr.Driver, checker.Equals, "null")
assert.Assert(c, nr.Scope, checker.Equals, "local")
assert.Assert(c, nr.Internal, checker.Equals, false)
assert.Assert(c, nr.EnableIPv6, checker.Equals, false)
assert.Assert(c, nr.IPAM.Driver, checker.Equals, "default")
assert.Assert(c, len(nr.IPAM.Config), checker.Equals, 0)
nr = getNetworkResource(c, "host")
c.Assert(nr.Driver, checker.Equals, "host")
c.Assert(nr.Scope, checker.Equals, "local")
c.Assert(nr.Internal, checker.Equals, false)
c.Assert(nr.EnableIPv6, checker.Equals, false)
c.Assert(nr.IPAM.Driver, checker.Equals, "default")
c.Assert(len(nr.IPAM.Config), checker.Equals, 0)
assert.Assert(c, nr.Driver, checker.Equals, "host")
assert.Assert(c, nr.Scope, checker.Equals, "local")
assert.Assert(c, nr.Internal, checker.Equals, false)
assert.Assert(c, nr.EnableIPv6, checker.Equals, false)
assert.Assert(c, nr.IPAM.Driver, checker.Equals, "default")
assert.Assert(c, len(nr.IPAM.Config), checker.Equals, 0)
nr = getNetworkResource(c, "bridge")
c.Assert(nr.Driver, checker.Equals, "bridge")
c.Assert(nr.Scope, checker.Equals, "local")
c.Assert(nr.Internal, checker.Equals, false)
c.Assert(nr.EnableIPv6, checker.Equals, false)
c.Assert(nr.IPAM.Driver, checker.Equals, "default")
c.Assert(len(nr.IPAM.Config), checker.Equals, 1)
assert.Assert(c, nr.Driver, checker.Equals, "bridge")
assert.Assert(c, nr.Scope, checker.Equals, "local")
assert.Assert(c, nr.Internal, checker.Equals, false)
assert.Assert(c, nr.EnableIPv6, checker.Equals, false)
assert.Assert(c, nr.IPAM.Driver, checker.Equals, "default")
assert.Assert(c, len(nr.IPAM.Config), checker.Equals, 1)
}
func (s *DockerNetworkSuite) TestDockerNetworkInspectCustomUnspecified(c *check.C) {
@ -706,12 +706,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkInspectCustomUnspecified(c *check.
assertNwIsAvailable(c, "test01")
nr := getNetworkResource(c, "test01")
c.Assert(nr.Driver, checker.Equals, "bridge")
c.Assert(nr.Scope, checker.Equals, "local")
c.Assert(nr.Internal, checker.Equals, false)
c.Assert(nr.EnableIPv6, checker.Equals, false)
c.Assert(nr.IPAM.Driver, checker.Equals, "default")
c.Assert(len(nr.IPAM.Config), checker.Equals, 1)
assert.Assert(c, nr.Driver, checker.Equals, "bridge")
assert.Assert(c, nr.Scope, checker.Equals, "local")
assert.Assert(c, nr.Internal, checker.Equals, false)
assert.Assert(c, nr.EnableIPv6, checker.Equals, false)
assert.Assert(c, nr.IPAM.Driver, checker.Equals, "default")
assert.Assert(c, len(nr.IPAM.Config), checker.Equals, 1)
dockerCmd(c, "network", "rm", "test01")
assertNwNotAvailable(c, "test01")
@ -722,15 +722,15 @@ func (s *DockerNetworkSuite) TestDockerNetworkInspectCustomSpecified(c *check.C)
assertNwIsAvailable(c, "br0")
nr := getNetworkResource(c, "br0")
c.Assert(nr.Driver, checker.Equals, "bridge")
c.Assert(nr.Scope, checker.Equals, "local")
c.Assert(nr.Internal, checker.Equals, false)
c.Assert(nr.EnableIPv6, checker.Equals, true)
c.Assert(nr.IPAM.Driver, checker.Equals, "default")
c.Assert(len(nr.IPAM.Config), checker.Equals, 2)
c.Assert(nr.IPAM.Config[0].Subnet, checker.Equals, "172.28.0.0/16")
c.Assert(nr.IPAM.Config[0].IPRange, checker.Equals, "172.28.5.0/24")
c.Assert(nr.IPAM.Config[0].Gateway, checker.Equals, "172.28.5.254")
assert.Assert(c, nr.Driver, checker.Equals, "bridge")
assert.Assert(c, nr.Scope, checker.Equals, "local")
assert.Assert(c, nr.Internal, checker.Equals, false)
assert.Assert(c, nr.EnableIPv6, checker.Equals, true)
assert.Assert(c, nr.IPAM.Driver, checker.Equals, "default")
assert.Assert(c, len(nr.IPAM.Config), checker.Equals, 2)
assert.Assert(c, nr.IPAM.Config[0].Subnet, checker.Equals, "172.28.0.0/16")
assert.Assert(c, nr.IPAM.Config[0].IPRange, checker.Equals, "172.28.5.0/24")
assert.Assert(c, nr.IPAM.Config[0].Gateway, checker.Equals, "172.28.5.254")
assert.Equal(c, nr.Internal, false)
dockerCmd(c, "network", "rm", "br0")
assertNwNotAvailable(c, "br0")
@ -765,11 +765,11 @@ func (s *DockerNetworkSuite) TestDockerNetworkDriverOptions(c *check.C) {
dockerCmd(c, "network", "create", "-d", dummyNetworkDriver, "-o", "opt1=drv1", "-o", "opt2=drv2", "testopt")
assertNwIsAvailable(c, "testopt")
gopts := remoteDriverNetworkRequest.Options[netlabel.GenericData]
c.Assert(gopts, checker.NotNil)
assert.Assert(c, gopts, checker.NotNil)
opts, ok := gopts.(map[string]interface{})
c.Assert(ok, checker.Equals, true)
c.Assert(opts["opt1"], checker.Equals, "drv1")
c.Assert(opts["opt2"], checker.Equals, "drv2")
assert.Assert(c, ok, checker.Equals, true)
assert.Assert(c, opts["opt1"], checker.Equals, "drv1")
assert.Assert(c, opts["opt2"], checker.Equals, "drv2")
dockerCmd(c, "network", "rm", "testopt")
assertNwNotAvailable(c, "testopt")
@ -788,9 +788,9 @@ func (s *DockerNetworkSuite) TestDockerPluginV2NetworkDriver(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, npName)
c.Assert(out, checker.Contains, npTag)
c.Assert(out, checker.Contains, "true")
assert.Assert(c, out, checker.Contains, npName)
assert.Assert(c, out, checker.Contains, npTag)
assert.Assert(c, out, checker.Contains, "true")
dockerCmd(c, "network", "create", "-d", npNameWithTag, "v2net")
assertNwIsAvailable(c, "v2net")
@ -826,14 +826,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)
c.Assert(string(hosts), checker.Equals, string(hostsPost), check.Commentf("Unexpected %s change on second container creation", hostsFile))
assert.Assert(c, string(hosts), checker.Equals, string(hostsPost), check.Commentf("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)
c.Assert(string(hosts), checker.Equals, string(hostsPost), check.Commentf("Unexpected %s change on second container creation", hostsFile))
assert.Assert(c, string(hosts), checker.Equals, string(hostsPost), check.Commentf("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)
@ -848,7 +848,7 @@ func (s *DockerDaemonSuite) TestDockerNetworkNoDiscoveryDefaultBridgeNetwork(c *
hostsPost, err = s.d.Cmd("exec", cid1, "cat", hostsFile)
assert.NilError(c, err)
c.Assert(string(hosts), checker.Equals, string(hostsPost), check.Commentf("Unexpected %s change on second network connection", hostsFile))
assert.Assert(c, string(hosts), checker.Equals, string(hostsPost), check.Commentf("Unexpected %s change on second network connection", hostsFile))
}
func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {
@ -871,7 +871,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {
// verify first container etc/hosts file has not changed
hosts1post := readContainerFileWithExec(c, cid1, hostsFile)
c.Assert(string(hosts1), checker.Equals, string(hosts1post), check.Commentf("Unexpected %s change on anonymous container creation", hostsFile))
assert.Assert(c, string(hosts1), checker.Equals, string(hosts1post), check.Commentf("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)
@ -881,7 +881,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {
hosts2 := readContainerFileWithExec(c, cid2, hostsFile)
hosts1post = readContainerFileWithExec(c, cid1, hostsFile)
c.Assert(string(hosts1), checker.Equals, string(hosts1post), check.Commentf("Unexpected %s change on container connect", hostsFile))
assert.Assert(c, string(hosts1), checker.Equals, string(hosts1post), check.Commentf("Unexpected %s change on container connect", hostsFile))
// start a named container
cName := "AnyName"
out, _ = dockerCmd(c, "run", "-d", "--net", cstmBridgeNw, "--name", cName, "busybox", "top")
@ -894,9 +894,9 @@ func (s *DockerNetworkSuite) TestDockerNetworkAnonymousEndpoint(c *check.C) {
// Stop named container and verify first two containers' etc/hosts file hasn't changed
dockerCmd(c, "stop", cid3)
hosts1post = readContainerFileWithExec(c, cid1, hostsFile)
c.Assert(string(hosts1), checker.Equals, string(hosts1post), check.Commentf("Unexpected %s change on name container creation", hostsFile))
assert.Assert(c, string(hosts1), checker.Equals, string(hosts1post), check.Commentf("Unexpected %s change on name container creation", hostsFile))
hosts2post := readContainerFileWithExec(c, cid2, hostsFile)
c.Assert(string(hosts2), checker.Equals, string(hosts2post), check.Commentf("Unexpected %s change on name container creation", hostsFile))
assert.Assert(c, string(hosts2), checker.Equals, string(hosts2post), check.Commentf("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, "")
@ -952,9 +952,9 @@ func (s *DockerNetworkSuite) TestDockerNetworkOverlayPortMapping(c *check.C) {
unpPort2 := fmt.Sprintf("%d/tcp", port2)
out, _ := dockerCmd(c, "ps", "-n=1")
// Missing unpublished ports in docker ps output
c.Assert(out, checker.Contains, unpPort1)
assert.Assert(c, out, checker.Contains, unpPort1)
// Missing unpublished ports in docker ps output
c.Assert(out, checker.Contains, unpPort2)
assert.Assert(c, out, checker.Contains, unpPort2)
}
func (s *DockerNetworkSuite) TestDockerNetworkDriverUngracefulRestart(c *check.C) {
@ -974,7 +974,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkDriverUngracefulRestart(c *check.C
assert.NilError(c, err)
// Kill daemon and restart
c.Assert(s.d.Kill(), checker.IsNil)
assert.Assert(c, s.d.Kill(), checker.IsNil)
server.Close()
@ -1010,7 +1010,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMacInspect(c *check.C) {
dockerCmd(c, "run", "-d", "--net", nwn, "--name", ctn, "busybox", "top")
mac := inspectField(c, ctn, "NetworkSettings.Networks."+nwn+".MacAddress")
c.Assert(mac, checker.Equals, "a0:b1:c2:d3:e4:f5")
assert.Assert(c, mac, checker.Equals, "a0:b1:c2:d3:e4:f5")
}
func (s *DockerSuite) TestInspectAPIMultipleNetworks(c *check.C) {
@ -1034,11 +1034,11 @@ func (s *DockerSuite) TestInspectAPIMultipleNetworks(c *check.C) {
var inspect121 types.ContainerJSON
err = json.Unmarshal(body, &inspect121)
assert.NilError(c, err)
c.Assert(inspect121.NetworkSettings.Networks, checker.HasLen, 3)
assert.Assert(c, inspect121.NetworkSettings.Networks, checker.HasLen, 3)
bridge := inspect121.NetworkSettings.Networks["bridge"]
c.Assert(bridge.IPAddress, checker.Equals, versionedIP)
c.Assert(bridge.IPAddress, checker.Equals, inspect121.NetworkSettings.IPAddress)
assert.Assert(c, bridge.IPAddress, checker.Equals, versionedIP)
assert.Assert(c, bridge.IPAddress, checker.Equals, inspect121.NetworkSettings.IPAddress)
}
func connectContainerToNetworks(c *check.C, d *daemon.Daemon, cName string, nws []string) {
@ -1060,7 +1060,7 @@ func verifyContainerIsConnectedToNetworks(c *check.C, d *daemon.Daemon, cName st
for _, nw := range nws {
out, err := d.Cmd("inspect", "-f", fmt.Sprintf("{{.NetworkSettings.Networks.%s}}", nw), cName)
assert.NilError(c, err, out)
c.Assert(out, checker.Not(checker.Equals), "<no value>\n")
assert.Assert(c, out, checker.Not(checker.Equals), "<no value>\n")
}
}
@ -1094,7 +1094,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMultipleNetworksUngracefulDaemonRe
verifyContainerIsConnectedToNetworks(c, s.d, cName, nwList)
// Kill daemon and restart
c.Assert(s.d.Kill(), checker.IsNil)
assert.Assert(c, s.d.Kill(), checker.IsNil)
s.d.Restart(c)
// Restart container
@ -1107,7 +1107,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMultipleNetworksUngracefulDaemonRe
func (s *DockerNetworkSuite) TestDockerNetworkRunNetByID(c *check.C) {
out, _ := dockerCmd(c, "network", "create", "one")
containerOut, _, err := dockerCmdWithError("run", "-d", "--net", strings.TrimSpace(out), "busybox", "top")
c.Assert(err, checker.IsNil, check.Commentf(containerOut))
assert.Assert(c, err, checker.IsNil, check.Commentf(containerOut))
}
func (s *DockerNetworkSuite) TestDockerNetworkHostModeUngracefulDaemonRestart(c *check.C) {
@ -1126,7 +1126,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkHostModeUngracefulDaemonRestart(c
}
// Kill daemon ungracefully and restart
c.Assert(s.d.Kill(), checker.IsNil)
assert.Assert(c, s.d.Kill(), checker.IsNil)
s.d.Restart(c)
// make sure all the containers are up and running
@ -1138,35 +1138,35 @@ func (s *DockerNetworkSuite) TestDockerNetworkHostModeUngracefulDaemonRestart(c
func (s *DockerNetworkSuite) TestDockerNetworkConnectToHostFromOtherNetwork(c *check.C) {
dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
c.Assert(waitRun("container1"), check.IsNil)
assert.Assert(c, waitRun("container1"), check.IsNil)
dockerCmd(c, "network", "disconnect", "bridge", "container1")
out, _, err := dockerCmdWithError("network", "connect", "host", "container1")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetwork.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictHostNetwork.Error())
}
func (s *DockerNetworkSuite) TestDockerNetworkDisconnectFromHost(c *check.C) {
dockerCmd(c, "run", "-d", "--name", "container1", "--net=host", "busybox", "top")
c.Assert(waitRun("container1"), check.IsNil)
assert.Assert(c, waitRun("container1"), check.IsNil)
out, _, err := dockerCmdWithError("network", "disconnect", "host", "container1")
c.Assert(err, checker.NotNil, check.Commentf("Should err out disconnect from host"))
c.Assert(out, checker.Contains, runconfig.ErrConflictHostNetwork.Error())
assert.Assert(c, err, checker.NotNil, check.Commentf("Should err out disconnect from host"))
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictHostNetwork.Error())
}
func (s *DockerNetworkSuite) TestDockerNetworkConnectWithPortMapping(c *check.C) {
testRequires(c, NotArm)
dockerCmd(c, "network", "create", "test1")
dockerCmd(c, "run", "-d", "--name", "c1", "-p", "5000:5000", "busybox", "top")
c.Assert(waitRun("c1"), check.IsNil)
assert.Assert(c, waitRun("c1"), check.IsNil)
dockerCmd(c, "network", "connect", "test1", "c1")
}
func verifyPortMap(c *check.C, container, port, originalMapping string, mustBeEqual bool) {
currentMapping, _ := dockerCmd(c, "port", container, port)
if mustBeEqual {
c.Assert(currentMapping, checker.Equals, originalMapping)
assert.Assert(c, currentMapping, checker.Equals, originalMapping)
} else {
c.Assert(currentMapping, checker.Not(checker.Equals), originalMapping)
assert.Assert(c, currentMapping, checker.Not(checker.Equals), originalMapping)
}
}
@ -1181,7 +1181,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectWithPortMapping(c
dockerCmd(c, "network", "create", "ccc")
dockerCmd(c, "run", "-d", "--name", cnt, "-p", "9000:90", "-p", "70", "busybox", "top")
c.Assert(waitRun(cnt), check.IsNil)
assert.Assert(c, waitRun(cnt), check.IsNil)
curPortMap, _ := dockerCmd(c, "port", cnt, "70")
curExplPortMap, _ := dockerCmd(c, "port", cnt, "90")
@ -1211,29 +1211,29 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectWithMac(c *check.C) {
macAddress := "02:42:ac:11:00:02"
dockerCmd(c, "network", "create", "mynetwork")
dockerCmd(c, "run", "--name=test", "-d", "--mac-address", macAddress, "busybox", "top")
c.Assert(waitRun("test"), check.IsNil)
assert.Assert(c, waitRun("test"), check.IsNil)
mac1 := inspectField(c, "test", "NetworkSettings.Networks.bridge.MacAddress")
c.Assert(strings.TrimSpace(mac1), checker.Equals, macAddress)
assert.Assert(c, strings.TrimSpace(mac1), checker.Equals, macAddress)
dockerCmd(c, "network", "connect", "mynetwork", "test")
mac2 := inspectField(c, "test", "NetworkSettings.Networks.mynetwork.MacAddress")
c.Assert(strings.TrimSpace(mac2), checker.Not(checker.Equals), strings.TrimSpace(mac1))
assert.Assert(c, strings.TrimSpace(mac2), checker.Not(checker.Equals), strings.TrimSpace(mac1))
}
func (s *DockerNetworkSuite) TestDockerNetworkInspectCreatedContainer(c *check.C) {
dockerCmd(c, "create", "--name", "test", "busybox")
networks := inspectField(c, "test", "NetworkSettings.Networks")
c.Assert(networks, checker.Contains, "bridge", check.Commentf("Should return 'bridge' network"))
assert.Assert(c, networks, checker.Contains, "bridge", check.Commentf("Should return 'bridge' network"))
}
func (s *DockerNetworkSuite) TestDockerNetworkRestartWithMultipleNetworks(c *check.C) {
dockerCmd(c, "network", "create", "test")
dockerCmd(c, "run", "--name=foo", "-d", "busybox", "top")
c.Assert(waitRun("foo"), checker.IsNil)
assert.Assert(c, waitRun("foo"), checker.IsNil)
dockerCmd(c, "network", "connect", "test", "foo")
dockerCmd(c, "restart", "foo")
networks := inspectField(c, "foo", "NetworkSettings.Networks")
c.Assert(networks, checker.Contains, "bridge", check.Commentf("Should contain 'bridge' network"))
c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' network"))
assert.Assert(c, networks, checker.Contains, "bridge", check.Commentf("Should contain 'bridge' network"))
assert.Assert(c, networks, checker.Contains, "test", check.Commentf("Should contain 'test' network"))
}
func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectToStoppedContainer(c *check.C) {
@ -1242,16 +1242,16 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectToStoppedContaine
dockerCmd(c, "create", "--name=foo", "busybox", "top")
dockerCmd(c, "network", "connect", "test", "foo")
networks := inspectField(c, "foo", "NetworkSettings.Networks")
c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' network"))
assert.Assert(c, networks, checker.Contains, "test", check.Commentf("Should contain 'test' network"))
// Restart docker daemon to test the config has persisted to disk
s.d.Restart(c)
networks = inspectField(c, "foo", "NetworkSettings.Networks")
c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' network"))
assert.Assert(c, networks, checker.Contains, "test", check.Commentf("Should contain 'test' network"))
// start the container and test if we can ping it from another container in the same network
dockerCmd(c, "start", "foo")
c.Assert(waitRun("foo"), checker.IsNil)
assert.Assert(c, waitRun("foo"), checker.IsNil)
ip := inspectField(c, "foo", "NetworkSettings.Networks.test.IPAddress")
ip = strings.TrimSpace(ip)
dockerCmd(c, "run", "--net=test", "busybox", "sh", "-c", fmt.Sprintf("ping -c 1 %s", ip))
@ -1261,12 +1261,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectDisconnectToStoppedContaine
// Test disconnect
dockerCmd(c, "network", "disconnect", "test", "foo")
networks = inspectField(c, "foo", "NetworkSettings.Networks")
c.Assert(networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network"))
assert.Assert(c, networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network"))
// Restart docker daemon to test the config has persisted to disk
s.d.Restart(c)
networks = inspectField(c, "foo", "NetworkSettings.Networks")
c.Assert(networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network"))
assert.Assert(c, networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network"))
}
@ -1274,7 +1274,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkDisconnectContainerNonexistingNetw
dockerCmd(c, "network", "create", "test")
dockerCmd(c, "run", "--net=test", "-d", "--name=foo", "busybox", "top")
networks := inspectField(c, "foo", "NetworkSettings.Networks")
c.Assert(networks, checker.Contains, "test", check.Commentf("Should contain 'test' network"))
assert.Assert(c, networks, checker.Contains, "test", check.Commentf("Should contain 'test' network"))
// Stop container and remove network
dockerCmd(c, "stop", "foo")
@ -1283,7 +1283,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkDisconnectContainerNonexistingNetw
// Test disconnecting stopped container from nonexisting network
dockerCmd(c, "network", "disconnect", "-f", "test", "foo")
networks = inspectField(c, "foo", "NetworkSettings.Networks")
c.Assert(networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network"))
assert.Assert(c, networks, checker.Not(checker.Contains), "test", check.Commentf("Should not contain 'test' network"))
}
func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIP(c *check.C) {
@ -1296,7 +1296,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIP(c *check.C) {
// run a container on first network specifying the ip addresses
dockerCmd(c, "run", "-d", "--name", "c0", "--net=n0", "--ip", "172.28.99.88", "--ip6", "2001:db8:1234::9988", "busybox", "top")
c.Assert(waitRun("c0"), check.IsNil)
assert.Assert(c, waitRun("c0"), check.IsNil)
verifyIPAddressConfig(c, "c0", "n0", "172.28.99.88", "2001:db8:1234::9988")
verifyIPAddresses(c, "c0", "n0", "172.28.99.88", "2001:db8:1234::9988")
@ -1317,8 +1317,8 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIP(c *check.C) {
// 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")
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndIP.Error())
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Contains, runconfig.ErrUnsupportedNetworkAndIP.Error())
}
@ -1336,7 +1336,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectPreferredIPStoppedContainer
// start the container, verify config has not changed and ip addresses are assigned
dockerCmd(c, "start", "c0")
c.Assert(waitRun("c0"), check.IsNil)
assert.Assert(c, waitRun("c0"), check.IsNil)
verifyIPAddressConfig(c, "c0", "n0", "172.30.55.44", "2001:db8:abcd::5544")
verifyIPAddresses(c, "c0", "n0", "172.30.55.44", "2001:db8:abcd::5544")
@ -1356,12 +1356,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkUnsupportedRequiredIP(c *check.C)
assertNwIsAvailable(c, "n0")
out, _, err := dockerCmdWithError("run", "-d", "--ip", "172.28.99.88", "--net", "n0", "busybox", "top")
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkNoSubnetAndIP.Error())
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Contains, runconfig.ErrUnsupportedNetworkNoSubnetAndIP.Error())
out, _, err = dockerCmdWithError("run", "-d", "--ip6", "2001:db8:1234::9988", "--net", "n0", "busybox", "top")
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkNoSubnetAndIP.Error())
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Contains, runconfig.ErrUnsupportedNetworkNoSubnetAndIP.Error())
dockerCmd(c, "network", "rm", "n0")
assertNwNotAvailable(c, "n0")
@ -1369,28 +1369,28 @@ func (s *DockerNetworkSuite) TestDockerNetworkUnsupportedRequiredIP(c *check.C)
func checkUnsupportedNetworkAndIP(c *check.C, nwMode string) {
out, _, err := dockerCmdWithError("run", "-d", "--net", nwMode, "--ip", "172.28.99.88", "--ip6", "2001:db8:1234::9988", "busybox", "top")
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndIP.Error())
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Contains, runconfig.ErrUnsupportedNetworkAndIP.Error())
}
func verifyIPAddressConfig(c *check.C, cName, nwname, ipv4, ipv6 string) {
if ipv4 != "" {
out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAMConfig.IPv4Address", nwname))
c.Assert(strings.TrimSpace(out), check.Equals, ipv4)
assert.Assert(c, strings.TrimSpace(out), check.Equals, ipv4)
}
if ipv6 != "" {
out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAMConfig.IPv6Address", nwname))
c.Assert(strings.TrimSpace(out), check.Equals, ipv6)
assert.Assert(c, strings.TrimSpace(out), check.Equals, ipv6)
}
}
func verifyIPAddresses(c *check.C, cName, nwname, ipv4, ipv6 string) {
out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAddress", nwname))
c.Assert(strings.TrimSpace(out), check.Equals, ipv4)
assert.Assert(c, strings.TrimSpace(out), check.Equals, ipv4)
out = inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.GlobalIPv6Address", nwname))
c.Assert(strings.TrimSpace(out), check.Equals, ipv6)
assert.Assert(c, strings.TrimSpace(out), check.Equals, ipv6)
}
func (s *DockerNetworkSuite) TestDockerNetworkConnectLinkLocalIP(c *check.C) {
@ -1406,13 +1406,13 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectLinkLocalIP(c *check.C) {
// run two containers with link-local ip on the test network
dockerCmd(c, "run", "-d", "--name", "c0", "--net=n0", "--link-local-ip", "169.254.7.7", "--link-local-ip", "fe80::254:77", "busybox", "top")
c.Assert(waitRun("c0"), check.IsNil)
assert.Assert(c, waitRun("c0"), check.IsNil)
dockerCmd(c, "run", "-d", "--name", "c1", "--net=n0", "--link-local-ip", "169.254.8.8", "--link-local-ip", "fe80::254:88", "busybox", "top")
c.Assert(waitRun("c1"), check.IsNil)
assert.Assert(c, waitRun("c1"), check.IsNil)
// run a container on the default network and connect it to the test network specifying a link-local address
dockerCmd(c, "run", "-d", "--name", "c2", "busybox", "top")
c.Assert(waitRun("c2"), check.IsNil)
assert.Assert(c, waitRun("c2"), check.IsNil)
dockerCmd(c, "network", "connect", "--link-local-ip", "169.254.9.9", "n0", "c2")
// verify the three containers can ping each other via the link-local addresses
@ -1446,13 +1446,13 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectLink(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "foo2")
dockerCmd(c, "run", "-d", "--net=foo1", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
// run a container in a user-defined network with a link for an existing container
// and a link for a container that doesn't exist
dockerCmd(c, "run", "-d", "--net=foo1", "--name=second", "--link=first:FirstInFoo1",
"--link=third:bar", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// ping to first and its alias FirstInFoo1 must succeed
_, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
@ -1494,11 +1494,11 @@ func (s *DockerNetworkSuite) TestDockerNetworkDisconnectDefault(c *check.C) {
dockerCmd(c, "network", "disconnect", "bridge", containerName)
dockerCmd(c, "start", containerName)
c.Assert(waitRun(containerName), checker.IsNil)
assert.Assert(c, waitRun(containerName), checker.IsNil)
networks := inspectField(c, containerName, "NetworkSettings.Networks")
c.Assert(networks, checker.Contains, netWorkName1, check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName1)))
c.Assert(networks, checker.Contains, netWorkName2, check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName2)))
c.Assert(networks, checker.Not(checker.Contains), "bridge", check.Commentf("Should not contain 'bridge' network"))
assert.Assert(c, networks, checker.Contains, netWorkName1, check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName1)))
assert.Assert(c, networks, checker.Contains, netWorkName2, check.Commentf(fmt.Sprintf("Should contain '%s' network", netWorkName2)))
assert.Assert(c, networks, checker.Not(checker.Contains), "bridge", check.Commentf("Should not contain 'bridge' network"))
}
func (s *DockerNetworkSuite) TestDockerNetworkConnectWithAliasOnDefaultNetworks(c *check.C) {
@ -1510,7 +1510,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectWithAliasOnDefaultNetworks(
for _, net := range defaults {
res, _, err := dockerCmdWithError("network", "connect", "--alias", "alias"+net, net, containerID)
assert.ErrorContains(c, err, "")
c.Assert(res, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error())
assert.Assert(c, res, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error())
}
}
@ -1520,10 +1520,10 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectAlias(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "net2")
cid, _ := dockerCmd(c, "run", "-d", "--net=net1", "--name=first", "--net-alias=foo", "busybox:glibc", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
dockerCmd(c, "run", "-d", "--net=net1", "--name=second", "busybox:glibc", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// ping first container and its alias
_, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
@ -1560,13 +1560,13 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectDisconnectAlias(c *check.C) {
// verify the alias option is rejected when running on predefined network
out, _, err := dockerCmdWithError("run", "--rm", "--name=any", "--net-alias=any", "busybox:glibc", "top")
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error())
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error())
// verify the alias option is rejected when connecting to predefined network
out, _, err = dockerCmdWithError("network", "connect", "--alias=any", "bridge", "first")
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error())
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error())
}
func (s *DockerSuite) TestUserDefinedNetworkConnectivity(c *check.C) {
@ -1574,10 +1574,10 @@ func (s *DockerSuite) TestUserDefinedNetworkConnectivity(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "br.net1")
dockerCmd(c, "run", "-d", "--net=br.net1", "--name=c1.net1", "busybox:glibc", "top")
c.Assert(waitRun("c1.net1"), check.IsNil)
assert.Assert(c, waitRun("c1.net1"), check.IsNil)
dockerCmd(c, "run", "-d", "--net=br.net1", "--name=c2.net1", "busybox:glibc", "top")
c.Assert(waitRun("c2.net1"), check.IsNil)
assert.Assert(c, waitRun("c2.net1"), check.IsNil)
// ping first container by its unqualified name
_, _, err := dockerCmdWithError("exec", "c2.net1", "ping", "-c", "1", "c1.net1")
@ -1602,7 +1602,7 @@ func (s *DockerSuite) TestEmbeddedDNSInvalidInput(c *check.C) {
func (s *DockerSuite) TestDockerNetworkConnectFailsNoInspectChange(c *check.C) {
dockerCmd(c, "run", "-d", "--name=bb", "busybox", "top")
c.Assert(waitRun("bb"), check.IsNil)
assert.Assert(c, waitRun("bb"), check.IsNil)
defer dockerCmd(c, "stop", "bb")
ns0 := inspectField(c, "bb", "NetworkSettings.Networks.bridge")
@ -1612,22 +1612,22 @@ func (s *DockerSuite) TestDockerNetworkConnectFailsNoInspectChange(c *check.C) {
assert.ErrorContains(c, err, "")
ns1 := inspectField(c, "bb", "NetworkSettings.Networks.bridge")
c.Assert(ns1, check.Equals, ns0)
assert.Assert(c, ns1, check.Equals, ns0)
}
func (s *DockerSuite) TestDockerNetworkInternalMode(c *check.C) {
dockerCmd(c, "network", "create", "--driver=bridge", "--internal", "internal")
assertNwIsAvailable(c, "internal")
nr := getNetworkResource(c, "internal")
c.Assert(nr.Internal, checker.True)
assert.Assert(c, nr.Internal, checker.True)
dockerCmd(c, "run", "-d", "--net=internal", "--name=first", "busybox:glibc", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
dockerCmd(c, "run", "-d", "--net=internal", "--name=second", "busybox:glibc", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
out, _, err := dockerCmdWithError("exec", "first", "ping", "-W", "4", "-c", "1", "8.8.8.8")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "100% packet loss")
assert.Assert(c, out, checker.Contains, "100% packet loss")
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
assert.NilError(c, err)
}
@ -1717,13 +1717,13 @@ func (s *DockerDaemonSuite) TestDaemonRestartRestoreBridgeNetwork(t *check.C) {
func (s *DockerNetworkSuite) TestDockerNetworkFlagAlias(c *check.C) {
dockerCmd(c, "network", "create", "user")
output, status := dockerCmd(c, "run", "--rm", "--network=user", "--network-alias=foo", "busybox", "true")
c.Assert(status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output))
assert.Assert(c, status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output))
output, status, _ = dockerCmdWithError("run", "--rm", "--net=user", "--network=user", "busybox", "true")
c.Assert(status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output))
assert.Assert(c, status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output))
output, status, _ = dockerCmdWithError("run", "--rm", "--network=user", "--net-alias=foo", "--network-alias=bar", "busybox", "true")
c.Assert(status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output))
assert.Assert(c, status, checker.Equals, 0, check.Commentf("unexpected status code %d (%s)", status, output))
}
func (s *DockerNetworkSuite) TestDockerNetworkValidateIP(c *check.C) {
@ -1733,7 +1733,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkValidateIP(c *check.C) {
_, _, err = dockerCmdWithError("run", "-d", "--name", "mynet0", "--net=mynet", "--ip", "172.28.99.88", "--ip6", "2001:db8:1234::9988", "busybox", "top")
assert.NilError(c, err)
c.Assert(waitRun("mynet0"), check.IsNil)
assert.Assert(c, waitRun("mynet0"), check.IsNil)
verifyIPAddressConfig(c, "mynet0", "mynet", "172.28.99.88", "2001:db8:1234::9988")
verifyIPAddresses(c, "mynet0", "mynet", "172.28.99.88", "2001:db8:1234::9988")

View file

@ -36,8 +36,8 @@ func (ps *DockerPluginSuite) TestPluginBasicOps(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, plugin)
c.Assert(out, checker.Contains, "true")
assert.Assert(c, out, checker.Contains, plugin)
assert.Assert(c, out, checker.Contains, "true")
id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", plugin)
id = strings.TrimSpace(id)
@ -45,14 +45,14 @@ func (ps *DockerPluginSuite) TestPluginBasicOps(c *check.C) {
out, _, err = dockerCmdWithError("plugin", "remove", plugin)
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "is enabled")
assert.Assert(c, out, checker.Contains, "is enabled")
_, _, err = dockerCmdWithError("plugin", "disable", plugin)
assert.NilError(c, err)
out, _, err = dockerCmdWithError("plugin", "remove", plugin)
assert.NilError(c, err)
c.Assert(out, checker.Contains, plugin)
assert.Assert(c, out, checker.Contains, plugin)
_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id))
if !os.IsNotExist(err) {
@ -67,11 +67,11 @@ func (ps *DockerPluginSuite) TestPluginForceRemove(c *check.C) {
assert.NilError(c, err)
out, _, _ := dockerCmdWithError("plugin", "remove", pNameWithTag)
c.Assert(out, checker.Contains, "is enabled")
assert.Assert(c, out, checker.Contains, "is enabled")
out, _, err = dockerCmdWithError("plugin", "remove", "--force", pNameWithTag)
assert.NilError(c, err)
c.Assert(out, checker.Contains, pNameWithTag)
assert.Assert(c, out, checker.Contains, pNameWithTag)
}
func (s *DockerSuite) TestPluginActive(c *check.C) {
@ -84,7 +84,7 @@ func (s *DockerSuite) TestPluginActive(c *check.C) {
assert.NilError(c, err)
out, _, _ := dockerCmdWithError("plugin", "disable", pNameWithTag)
c.Assert(out, checker.Contains, "in use")
assert.Assert(c, out, checker.Contains, "in use")
_, _, err = dockerCmdWithError("volume", "rm", "testvol1")
assert.NilError(c, err)
@ -94,7 +94,7 @@ func (s *DockerSuite) TestPluginActive(c *check.C) {
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
assert.NilError(c, err)
c.Assert(out, checker.Contains, pNameWithTag)
assert.Assert(c, out, checker.Contains, pNameWithTag)
}
func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) {
@ -108,20 +108,20 @@ func (s *DockerSuite) TestPluginActiveNetwork(c *check.C) {
nID := strings.TrimSpace(out)
out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
c.Assert(out, checker.Contains, "is in use")
assert.Assert(c, out, checker.Contains, "is in use")
_, _, err = dockerCmdWithError("network", "rm", nID)
assert.NilError(c, err)
out, _, _ = dockerCmdWithError("plugin", "remove", npNameWithTag)
c.Assert(out, checker.Contains, "is enabled")
assert.Assert(c, out, checker.Contains, "is enabled")
_, _, err = dockerCmdWithError("plugin", "disable", npNameWithTag)
assert.NilError(c, err)
out, _, err = dockerCmdWithError("plugin", "remove", npNameWithTag)
assert.NilError(c, err)
c.Assert(out, checker.Contains, npNameWithTag)
assert.Assert(c, out, checker.Contains, npNameWithTag)
}
func (ps *DockerPluginSuite) TestPluginInstallDisable(c *check.C) {
@ -129,30 +129,30 @@ func (ps *DockerPluginSuite) TestPluginInstallDisable(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, pName)
out, _, err = dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "false")
assert.Assert(c, out, checker.Contains, "false")
out, _, err = dockerCmdWithError("plugin", "enable", pName)
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, pName)
out, _, err = dockerCmdWithError("plugin", "disable", pName)
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, pName)
out, _, err = dockerCmdWithError("plugin", "remove", pName)
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, pName)
}
func (s *DockerSuite) TestPluginInstallDisableVolumeLs(c *check.C) {
testRequires(c, DaemonIsLinux, IsAmd64, Network)
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", "--disable", pName)
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, pName)
dockerCmd(c, "volume", "ls")
}
@ -180,31 +180,31 @@ func (ps *DockerPluginSuite) TestPluginSet(c *check.C) {
{Name: "pdev2", Settable: []string{"path"}}, // Device without Path is invalid.
}
})
c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to create test plugin"))
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
assert.Assert(c, strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
dockerCmd(c, "plugin", "set", name, "DEBUG=1")
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", name)
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
assert.Assert(c, strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
c.Assert(strings.TrimSpace(env), checker.Contains, mntSrc)
assert.Assert(c, strings.TrimSpace(env), checker.Contains, mntSrc)
dockerCmd(c, "plugin", "set", name, "pmount1.source=bar")
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{with $mount := index .Settings.Mounts 0}}{{$mount.Source}}{{end}}", name)
c.Assert(strings.TrimSpace(env), checker.Contains, "bar")
assert.Assert(c, strings.TrimSpace(env), checker.Contains, "bar")
out, _, err := dockerCmdWithError("plugin", "set", name, "pmount2.source=bar2")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Plugin config has no mount source")
assert.Assert(c, out, checker.Contains, "Plugin config has no mount source")
out, _, err = dockerCmdWithError("plugin", "set", name, "pdev2.path=/dev/bar2")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Plugin config has no device path")
assert.Assert(c, out, checker.Contains, "Plugin config has no device path")
}
@ -218,10 +218,10 @@ func (ps *DockerPluginSuite) TestPluginInstallArgs(c *check.C) {
})
out, _ := dockerCmd(c, "plugin", "install", "--grant-all-permissions", "--disable", pName, "DEBUG=1")
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, pName)
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", pName)
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
assert.Assert(c, strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
}
func (ps *DockerPluginSuite) TestPluginInstallImage(c *check.C) {
@ -235,7 +235,7 @@ func (ps *DockerPluginSuite) TestPluginInstallImage(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "install", repoName)
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`)
assert.Assert(c, out, checker.Contains, `Encountered remote "application/vnd.docker.container.image.v1+json"(image) when fetching`)
}
func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *check.C) {
@ -243,18 +243,18 @@ func (ps *DockerPluginSuite) TestPluginEnableDisableNegative(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pName)
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, pName)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, pName)
out, _, err = dockerCmdWithError("plugin", "enable", pName)
assert.ErrorContains(c, err, "")
c.Assert(strings.TrimSpace(out), checker.Contains, "already enabled")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "already enabled")
_, _, err = dockerCmdWithError("plugin", "disable", pName)
assert.NilError(c, err)
out, _, err = dockerCmdWithError("plugin", "disable", pName)
assert.ErrorContains(c, err, "")
c.Assert(strings.TrimSpace(out), checker.Contains, "already disabled")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "already disabled")
_, _, err = dockerCmdWithError("plugin", "remove", pName)
assert.NilError(c, err)
@ -275,21 +275,21 @@ func (ps *DockerPluginSuite) TestPluginCreate(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "create", name, temp)
assert.NilError(c, err)
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
out, _, err = dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
out, _, err = dockerCmdWithError("plugin", "create", name, temp)
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "already exist")
assert.Assert(c, out, checker.Contains, "already exist")
out, _, err = dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
// The output will consists of one HEADER line and one line of foo/bar-driver
c.Assert(len(strings.Split(strings.TrimSpace(out), "\n")), checker.Equals, 2)
assert.Assert(c, len(strings.Split(strings.TrimSpace(out), "\n")), checker.Equals, 2)
}
func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
@ -300,8 +300,8 @@ func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, pNameWithTag)
c.Assert(out, checker.Contains, "true")
assert.Assert(c, out, checker.Contains, pNameWithTag)
assert.Assert(c, out, checker.Contains, "true")
// Find the ID first
out, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", pNameWithTag)
@ -334,7 +334,7 @@ func (ps *DockerPluginSuite) TestPluginInspect(c *check.C) {
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
assert.NilError(c, err)
c.Assert(out, checker.Contains, pNameWithTag)
assert.Assert(c, out, checker.Contains, pNameWithTag)
// After remove nothing should be found
_, _, err = dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", id[:5])
@ -348,7 +348,7 @@ func (s *DockerSuite) TestPluginInspectOnWindows(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "inspect", "foobar")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "plugins are not supported on this platform")
assert.Assert(c, out, checker.Contains, "plugins are not supported on this platform")
assert.ErrorContains(c, err, "plugins are not supported on this platform")
}
@ -363,7 +363,7 @@ func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
})
cancel()
c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to create test plugin"))
// Find ID first
id, _, err := dockerCmdWithError("plugin", "inspect", "-f", "{{.Id}}", name)
@ -373,32 +373,32 @@ func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
// List current state
out, _, err := dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, name)
c.Assert(out, checker.Contains, "false")
assert.Assert(c, out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, "false")
env, _ := dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
assert.Assert(c, strings.TrimSpace(env), checker.Equals, "[DEBUG=0]")
dockerCmd(c, "plugin", "set", id[:5], "DEBUG=1")
env, _ = dockerCmd(c, "plugin", "inspect", "-f", "{{.Settings.Env}}", id[:5])
c.Assert(strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
assert.Assert(c, strings.TrimSpace(env), checker.Equals, "[DEBUG=1]")
// Enable
_, _, err = dockerCmdWithError("plugin", "enable", id[:5])
assert.NilError(c, err)
out, _, err = dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, name)
c.Assert(out, checker.Contains, "true")
assert.Assert(c, out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, "true")
// Disable
_, _, err = dockerCmdWithError("plugin", "disable", id[:5])
assert.NilError(c, err)
out, _, err = dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, name)
c.Assert(out, checker.Contains, "false")
assert.Assert(c, out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, "false")
// Remove
_, _, err = dockerCmdWithError("plugin", "remove", id[:5])
@ -406,7 +406,7 @@ func (ps *DockerPluginSuite) TestPluginIDPrefix(c *check.C) {
// List returns none
out, _, err = dockerCmdWithError("plugin", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Not(checker.Contains), name)
assert.Assert(c, out, checker.Not(checker.Contains), name)
}
func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *check.C) {
@ -425,7 +425,7 @@ func (ps *DockerPluginSuite) TestPluginListDefaultFormat(c *check.C) {
err = plugin.Create(ctx, client, name, func(cfg *plugin.Config) {
cfg.Description = "test plugin"
})
c.Assert(err, checker.IsNil, check.Commentf("failed to create test plugin"))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to create test plugin"))
out, _ := dockerCmd(c, "plugin", "inspect", "--format", "{{.ID}}", name)
id := strings.TrimSpace(out)
@ -437,7 +437,7 @@ description: test plugin
enabled: false`, id, name)
out, _ = dockerCmd(c, "--config", config, "plugin", "ls", "--no-trunc")
c.Assert(strings.TrimSpace(out), checker.Contains, expectedOutput)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, expectedOutput)
}
func (s *DockerSuite) TestPluginUpgrade(c *check.C) {
@ -451,14 +451,14 @@ func (s *DockerSuite) TestPluginUpgrade(c *check.C) {
out, _, err := dockerCmdWithError("plugin", "upgrade", "--grant-all-permissions", plugin, pluginV2)
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "disabled before upgrading")
assert.Assert(c, out, checker.Contains, "disabled before upgrading")
out, _ = dockerCmd(c, "plugin", "inspect", "--format={{.ID}}", plugin)
id := strings.TrimSpace(out)
// make sure "v2" does not exists
_, err = os.Stat(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "plugins", id, "rootfs", "v2"))
c.Assert(os.IsNotExist(err), checker.True, check.Commentf("%s", out))
assert.Assert(c, os.IsNotExist(err), checker.True, check.Commentf("%s", out))
dockerCmd(c, "plugin", "disable", "-f", plugin)
dockerCmd(c, "plugin", "upgrade", "--grant-all-permissions", "--skip-remote-check", plugin, pluginV2)
@ -480,7 +480,7 @@ func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) {
name := "cpuguy83/docker-metrics-plugin-test:latest"
r := cli.Docker(cli.Args("plugin", "install", "--grant-all-permissions", name), cli.Daemon(d))
c.Assert(r.Error, checker.IsNil, check.Commentf(r.Combined()))
assert.Assert(c, r.Error, checker.IsNil, check.Commentf(r.Combined()))
// plugin lisens on localhost:19393 and proxies the metrics
resp, err := http.Get("http://localhost:19393/metrics")
@ -490,5 +490,5 @@ func (s *DockerSuite) TestPluginMetricsCollector(c *check.C) {
b, err := ioutil.ReadAll(resp.Body)
assert.NilError(c, err)
// check that a known metric is there... don't expect this metric to change over time.. probably safe
c.Assert(string(b), checker.Contains, "container_actions")
assert.Assert(c, string(b), checker.Contains, "container_actions")
}

View file

@ -105,7 +105,7 @@ func (s *DockerSuite) TestPortList(c *check.C) {
"-p", "9090-9092:80",
"busybox", "top")
// Exhausted port range did not return an error
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
for i := 0; i < 3; i++ {
dockerCmd(c, "rm", "-f", IDs[i])
@ -121,7 +121,7 @@ func (s *DockerSuite) TestPortList(c *check.C) {
"-p", invalidRange,
"busybox", "top")
// Port range should have returned an error
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
}
// test host range:container range spec.
@ -224,9 +224,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
unpPort2 := fmt.Sprintf("%d/tcp", port2)
out, _ := dockerCmd(c, "ps", "-n=1")
// Missing unpublished ports in docker ps output
c.Assert(out, checker.Contains, unpPort1)
assert.Assert(c, out, checker.Contains, unpPort1)
// Missing unpublished ports in docker ps output
c.Assert(out, checker.Contains, unpPort2)
assert.Assert(c, out, checker.Contains, unpPort2)
// Run the container forcing to publish the exposed ports
dockerCmd(c, "run", "-d", "-P", expose1, expose2, "busybox", "sleep", "5")
@ -236,9 +236,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
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
c.Assert(expBndRegx1.MatchString(out), checker.Equals, true, check.Commentf("out: %s; unpPort1: %s", out, unpPort1))
assert.Assert(c, expBndRegx1.MatchString(out), checker.Equals, true, check.Commentf("out: %s; unpPort1: %s", out, unpPort1))
// Cannot find expected port binding port (0.0.0.0:xxxxx->unpPort2) in docker ps output
c.Assert(expBndRegx2.MatchString(out), checker.Equals, true, check.Commentf("out: %s; unpPort2: %s", out, unpPort2))
assert.Assert(c, expBndRegx2.MatchString(out), checker.Equals, true, check.Commentf("out: %s; unpPort2: %s", out, unpPort2))
// Run the container specifying explicit port bindings for the exposed ports
offset := 10000
@ -252,9 +252,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
expBnd2 := fmt.Sprintf("0.0.0.0:%d->%s", offset+port2, unpPort2)
out, _ = dockerCmd(c, "ps", "-n=1")
// Cannot find expected port binding (expBnd1) in docker ps output
c.Assert(out, checker.Contains, expBnd1)
assert.Assert(c, out, checker.Contains, expBnd1)
// Cannot find expected port binding (expBnd2) in docker ps output
c.Assert(out, checker.Contains, expBnd2)
assert.Assert(c, out, checker.Contains, expBnd2)
// Remove container now otherwise it will interfere with next test
stopRemoveContainer(id, c)
@ -266,9 +266,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
// Check docker ps o/p for last created container reports the specified port mappings
out, _ = dockerCmd(c, "ps", "-n=1")
// Cannot find expected port binding (expBnd1) in docker ps output
c.Assert(out, checker.Contains, expBnd1)
assert.Assert(c, out, checker.Contains, expBnd1)
// Cannot find expected port binding (expBnd2) in docker ps output
c.Assert(out, checker.Contains, expBnd2)
assert.Assert(c, out, checker.Contains, expBnd2)
// Remove container now otherwise it will interfere with next test
stopRemoveContainer(id, c)
@ -278,9 +278,9 @@ func (s *DockerSuite) TestUnpublishedPortsInPsOutput(c *check.C) {
// Check docker ps o/p for last created container reports the specified unpublished port and port mapping
out, _ = dockerCmd(c, "ps", "-n=1")
// Missing unpublished exposed ports (unpPort1) in docker ps output
c.Assert(out, checker.Contains, unpPort1)
assert.Assert(c, out, checker.Contains, unpPort1)
// Missing port binding (expBnd2) in docker ps output
c.Assert(out, checker.Contains, expBnd2)
assert.Assert(c, out, checker.Contains, expBnd2)
}
func (s *DockerSuite) TestPortHostBinding(c *check.C) {
@ -302,7 +302,7 @@ func (s *DockerSuite) TestPortHostBinding(c *check.C) {
out, _, err = dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "9876")
// Port is still bound after the Container is removed
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
}
func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
@ -314,7 +314,7 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
out, _ = dockerCmd(c, "port", firstID, "80")
_, exposedPort, err := net.SplitHostPort(out)
c.Assert(err, checker.IsNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("out: %s", out))
dockerCmd(c, "run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
@ -324,25 +324,25 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
out, _, err = dockerCmdWithError("run", "--net=host", "busybox",
"nc", "localhost", strings.TrimSpace(exposedPort))
// Port is still bound after the Container is removed
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
}
func (s *DockerSuite) TestPortBindingOnSandbox(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace)
dockerCmd(c, "network", "create", "--internal", "-d", "bridge", "internal-net")
nr := getNetworkResource(c, "internal-net")
c.Assert(nr.Internal, checker.Equals, true)
assert.Assert(c, nr.Internal, checker.Equals, true)
dockerCmd(c, "run", "--net", "internal-net", "-d", "--name", "c1",
"-p", "8080:8080", "busybox", "nc", "-l", "-p", "8080")
c.Assert(waitRun("c1"), check.IsNil)
assert.Assert(c, waitRun("c1"), check.IsNil)
_, _, err := dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "8080")
c.Assert(err, check.NotNil, check.Commentf("Port mapping on internal network is expected to fail"))
assert.Assert(c, err, check.NotNil, check.Commentf("Port mapping on internal network is expected to fail"))
// Connect container to another normal bridge network
dockerCmd(c, "network", "create", "-d", "bridge", "foo-net")
dockerCmd(c, "network", "connect", "foo-net", "c1")
_, _, err = dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "8080")
c.Assert(err, check.IsNil, check.Commentf("Port mapping on the new network is expected to succeed"))
assert.Assert(c, err, check.IsNil, check.Commentf("Port mapping on the new network is expected to succeed"))
}

View file

@ -92,23 +92,23 @@ func (s *DockerDaemonSuite) TestPruneImageDangling(c *check.C) {
out, err := s.d.Cmd("images", "-q", "--no-trunc")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, id)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id)
out, err = s.d.Cmd("image", "prune", "--force")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id)
out, err = s.d.Cmd("images", "-q", "--no-trunc")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, id)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id)
out, err = s.d.Cmd("image", "prune", "--force", "--all")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, id)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id)
out, err = s.d.Cmd("images", "-q", "--no-trunc")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id)
}
func (s *DockerSuite) TestPruneContainerUntil(c *check.C) {
@ -123,12 +123,12 @@ func (s *DockerSuite) TestPruneContainerUntil(c *check.C) {
cli.WaitExited(c, id2, 5*time.Second)
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "until="+until).Combined()
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
}
func (s *DockerSuite) TestPruneContainerLabel(c *check.C) {
@ -158,53 +158,53 @@ func (s *DockerSuite) TestPruneContainerLabel(c *check.C) {
// With config.json only, prune based on label=foobar
out = cli.DockerCmd(c, "--config", d, "container", "prune", "--force").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
c.Assert(strings.TrimSpace(out), checker.Contains, id4)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id3)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id4)
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "label=foo").Combined()
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id3)
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id3)
out = cli.DockerCmd(c, "container", "prune", "--force", "--filter", "label!=bar").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id3)
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id3)
// With config.json label=foobar and CLI label!=foobar, CLI label!=foobar supersede
out = cli.DockerCmd(c, "--config", d, "container", "prune", "--force", "--filter", "label!=foobar").Combined()
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc").Combined()
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
}
func (s *DockerSuite) TestPruneVolumeLabel(c *check.C) {
out, _ := dockerCmd(c, "volume", "create", "--label", "foo")
id1 := strings.TrimSpace(out)
c.Assert(id1, checker.Not(checker.Equals), "")
assert.Assert(c, id1, checker.Not(checker.Equals), "")
out, _ = dockerCmd(c, "volume", "create", "--label", "bar")
id2 := strings.TrimSpace(out)
c.Assert(id2, checker.Not(checker.Equals), "")
assert.Assert(c, id2, checker.Not(checker.Equals), "")
out, _ = dockerCmd(c, "volume", "create")
id3 := strings.TrimSpace(out)
c.Assert(id3, checker.Not(checker.Equals), "")
assert.Assert(c, id3, checker.Not(checker.Equals), "")
out, _ = dockerCmd(c, "volume", "create", "--label", "foobar")
id4 := strings.TrimSpace(out)
c.Assert(id4, checker.Not(checker.Equals), "")
assert.Assert(c, id4, checker.Not(checker.Equals), "")
// Add a config file of label=foobar, that will have no impact if cli is label!=foobar
config := `{"pruneFilters": ["label=foobar"]}`
@ -216,35 +216,35 @@ func (s *DockerSuite) TestPruneVolumeLabel(c *check.C) {
// With config.json only, prune based on label=foobar
out, _ = dockerCmd(c, "--config", d, "volume", "prune", "--force")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
c.Assert(strings.TrimSpace(out), checker.Contains, id4)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id3)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id4)
out, _ = dockerCmd(c, "volume", "prune", "--force", "--filter", "label=foo")
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id3)
out, _ = dockerCmd(c, "volume", "ls", "--format", "{{.Name}}")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id3)
out, _ = dockerCmd(c, "volume", "prune", "--force", "--filter", "label!=bar")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
c.Assert(strings.TrimSpace(out), checker.Contains, id3)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id3)
out, _ = dockerCmd(c, "volume", "ls", "--format", "{{.Name}}")
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id3)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id3)
// With config.json label=foobar and CLI label!=foobar, CLI label!=foobar supersede
out, _ = dockerCmd(c, "--config", d, "volume", "prune", "--force", "--filter", "label!=foobar")
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
out, _ = dockerCmd(c, "volume", "ls", "--format", "{{.Name}}")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
}
func (s *DockerSuite) TestPruneNetworkLabel(c *check.C) {
@ -253,19 +253,19 @@ func (s *DockerSuite) TestPruneNetworkLabel(c *check.C) {
dockerCmd(c, "network", "create", "n3")
out, _ := dockerCmd(c, "network", "prune", "--force", "--filter", "label=foo")
c.Assert(strings.TrimSpace(out), checker.Contains, "n1")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n2")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n3")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "n1")
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), "n2")
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), "n3")
out, _ = dockerCmd(c, "network", "prune", "--force", "--filter", "label!=bar")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n1")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n2")
c.Assert(strings.TrimSpace(out), checker.Contains, "n3")
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), "n1")
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), "n2")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "n3")
out, _ = dockerCmd(c, "network", "prune", "--force")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n1")
c.Assert(strings.TrimSpace(out), checker.Contains, "n2")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), "n3")
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), "n1")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "n2")
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), "n3")
}
func (s *DockerDaemonSuite) TestPruneImageLabel(c *check.C) {
@ -280,7 +280,7 @@ func (s *DockerDaemonSuite) TestPruneImageLabel(c *check.C) {
id1 := strings.TrimSpace(result.Combined())
out, err := s.d.Cmd("images", "-q", "--no-trunc")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id1)
result = cli.BuildCmd(c, "test2", cli.Daemon(s.d),
build.WithDockerfile(`FROM busybox
@ -291,20 +291,20 @@ func (s *DockerDaemonSuite) TestPruneImageLabel(c *check.C) {
id2 := strings.TrimSpace(result.Combined())
out, err = s.d.Cmd("images", "-q", "--no-trunc")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
out, err = s.d.Cmd("image", "prune", "--force", "--all", "--filter", "label=foo=bar")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
out, err = s.d.Cmd("image", "prune", "--force", "--all", "--filter", "label!=bar=foo")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id2)
out, err = s.d.Cmd("image", "prune", "--force", "--all", "--filter", "label=bar=foo")
assert.NilError(c, err)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
}

View file

@ -35,89 +35,89 @@ func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
fourthID := strings.TrimSpace(out)
// make sure the second is running
c.Assert(waitRun(secondID), checker.IsNil)
assert.Assert(c, waitRun(secondID), checker.IsNil)
// make sure third one is not running
dockerCmd(c, "wait", thirdID)
// make sure the forth is running
c.Assert(waitRun(fourthID), checker.IsNil)
assert.Assert(c, waitRun(fourthID), checker.IsNil)
// all
out, _ = dockerCmd(c, "ps", "-a")
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, thirdID, secondID, firstID}), checker.Equals, true, check.Commentf("ALL: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, thirdID, secondID, firstID}), checker.Equals, true, check.Commentf("ALL: Container list is not in the correct order: \n%s", out))
// running
out, _ = dockerCmd(c, "ps")
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, secondID, firstID}), checker.Equals, true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), []string{fourthID, secondID, firstID}), checker.Equals, true, check.Commentf("RUNNING: Container list is not in the correct order: \n%s", out))
// limit
out, _ = dockerCmd(c, "ps", "-n=2", "-a")
expected := []string{fourthID, thirdID}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-n=2")
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("LIMIT: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter & ALL: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "since="+thirdID)
expected = []string{fourthID}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "before="+thirdID)
expected = []string{secondID, firstID}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter & ALL: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "since="+firstID, "-n=2")
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, LIMIT: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
out, _ = dockerCmd(c, "ps", "-f", "before="+fourthID, "-n=1")
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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}
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT & ALL: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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")
c.Assert(assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("SINCE filter, BEFORE filter, LIMIT: Container list is not in the correct order: \n%s", out))
assert.Assert(c, assertContainerList(RemoveOutputForExistingElements(out, existingContainers), expected), checker.Equals, true, check.Commentf("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 *check.C) {
sizeIndex := strings.Index(lines[0], "SIZE")
idIndex := strings.Index(lines[0], "CONTAINER ID")
foundID := lines[1][idIndex : idIndex+12]
c.Assert(foundID, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s", id[:12], foundID))
assert.Assert(c, foundID, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s", id[:12], foundID))
expectedSize := fmt.Sprintf("%dB", 2+baseBytes)
foundSize := lines[1][sizeIndex:]
c.Assert(foundSize, checker.Contains, expectedSize, check.Commentf("Expected size %q, got %q", expectedSize, foundSize))
assert.Assert(c, foundSize, checker.Contains, expectedSize, check.Commentf("Expected size %q, got %q", expectedSize, foundSize))
}
func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
@ -196,11 +196,11 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
// filter containers by exited
out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=exited").Combined()
containerOut := strings.TrimSpace(out)
c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, firstID)
assert.Assert(c, RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, firstID)
out = cli.DockerCmd(c, "ps", "-a", "--no-trunc", "-q", "--filter=status=running").Combined()
containerOut = strings.TrimSpace(out)
c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, secondID)
assert.Assert(c, RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, secondID)
result := cli.Docker(cli.Args("ps", "-a", "-q", "--filter=status=rubbish"), cli.WithTimeout(time.Second*60))
err := "Invalid filter 'status=rubbish'"
@ -222,7 +222,7 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
out = cli.DockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused").Combined()
containerOut = strings.TrimSpace(out)
c.Assert(RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, pausedID)
assert.Assert(c, RemoveOutputForExistingElements(containerOut, existingContainers), checker.Equals, pausedID)
}
}
@ -236,7 +236,7 @@ func (s *DockerSuite) TestPsListContainersFilterHealth(c *check.C) {
out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined()
containerOut := strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for legacy none filter, output: %q", containerID, containerOut, out))
assert.Assert(c, containerOut, checker.Equals, containerID, check.Commentf("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 *check.C) {
out = cli.DockerCmd(c, "ps", "-q", "-l", "--no-trunc", "--filter=health=none").Combined()
containerOut = strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected id %s, got %s for none filter, output: %q", containerID, containerOut, out))
assert.Assert(c, containerOut, checker.Equals, containerID, check.Commentf("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 *check.C) {
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=unhealthy").Combined()
containerOut = strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for unhealthy filter, output: %q", containerID, containerOut, out))
assert.Assert(c, containerOut, checker.Equals, containerID, check.Commentf("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 *check.C) {
out = cli.DockerCmd(c, "ps", "-q", "--no-trunc", "--filter=health=healthy").Combined()
containerOut = strings.TrimSpace(RemoveOutputForExistingElements(out, existingContainers))
c.Assert(containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
assert.Assert(c, containerOut, checker.Equals, containerID, check.Commentf("Expected containerID %s, got %s for healthy filter, output: %q", containerID, containerOut, out))
}
func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
@ -280,7 +280,7 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
// filter containers by id
out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID)
containerOut := strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, firstID[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
assert.Assert(c, containerOut, checker.Equals, firstID[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID[:12], containerOut, out))
}
func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
@ -294,7 +294,7 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
// filter containers by name
out, _ := dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match")
containerOut := strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, id[:12], check.Commentf("Expected id %s, got %s for exited filter, output: %q", id[:12], containerOut, out))
assert.Assert(c, containerOut, checker.Equals, id[:12], check.Commentf("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 *check.C, out string, filterName string, expe
sort.Strings(actualIDs)
sort.Strings(expectedIDs)
c.Assert(actualIDs, checker.HasLen, 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.Assert(c, actualIDs, checker.HasLen, 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))
if len(expectedIDs) > 0 {
same := true
for i := range expectedIDs {
@ -396,7 +396,7 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe
break
}
}
c.Assert(same, checker.Equals, true, check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs))
assert.Assert(c, same, checker.Equals, true, check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs))
}
}
@ -416,24 +416,24 @@ func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
// filter containers by exact match
out, _ := dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=label=match=me")
containerOut := strings.TrimSpace(out)
c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
assert.Assert(c, containerOut, checker.Equals, firstID, check.Commentf("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)
c.Assert(containerOut, checker.Equals, firstID, check.Commentf("Expected id %s, got %s for exited filter, output: %q", firstID, containerOut, out))
assert.Assert(c, containerOut, checker.Equals, firstID, check.Commentf("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)
c.Assert(containerOut, checker.Equals, "", check.Commentf("Expected nothing, got %s for exited filter, output: %q", containerOut, out))
assert.Assert(c, containerOut, checker.Equals, "", check.Commentf("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")
containerOut = strings.TrimSpace(out)
c.Assert(containerOut, checker.Contains, firstID)
c.Assert(containerOut, checker.Contains, secondID)
c.Assert(containerOut, checker.Not(checker.Contains), thirdID)
assert.Assert(c, containerOut, checker.Contains, firstID)
assert.Assert(c, containerOut, checker.Contains, secondID)
assert.Assert(c, containerOut, checker.Not(checker.Contains), thirdID)
}
func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
@ -443,25 +443,25 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
secondZero, _ := dockerCmd(c, "run", "-d", "busybox", "true")
out, _, err := dockerCmdWithError("run", "--name", "nonzero1", "busybox", "false")
c.Assert(err, checker.NotNil, check.Commentf("Should fail. out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("Should fail. out: %s", out))
firstNonZero := getIDByName(c, "nonzero1")
out, _, err = dockerCmdWithError("run", "--name", "nonzero2", "busybox", "false")
c.Assert(err, checker.NotNil, check.Commentf("Should fail. out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("Should fail. out: %s", out))
secondNonZero := getIDByName(c, "nonzero2")
// filter containers by exited=0
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=0")
c.Assert(out, checker.Contains, strings.TrimSpace(firstZero))
c.Assert(out, checker.Contains, strings.TrimSpace(secondZero))
c.Assert(out, checker.Not(checker.Contains), strings.TrimSpace(firstNonZero))
c.Assert(out, checker.Not(checker.Contains), strings.TrimSpace(secondNonZero))
assert.Assert(c, out, checker.Contains, strings.TrimSpace(firstZero))
assert.Assert(c, out, checker.Contains, strings.TrimSpace(secondZero))
assert.Assert(c, out, checker.Not(checker.Contains), strings.TrimSpace(firstNonZero))
assert.Assert(c, out, checker.Not(checker.Contains), strings.TrimSpace(secondNonZero))
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=exited=1")
c.Assert(out, checker.Contains, strings.TrimSpace(firstNonZero))
c.Assert(out, checker.Contains, strings.TrimSpace(secondNonZero))
c.Assert(out, checker.Not(checker.Contains), strings.TrimSpace(firstZero))
c.Assert(out, checker.Not(checker.Contains), strings.TrimSpace(secondZero))
assert.Assert(c, out, checker.Contains, strings.TrimSpace(firstNonZero))
assert.Assert(c, out, checker.Contains, strings.TrimSpace(secondNonZero))
assert.Assert(c, out, checker.Not(checker.Contains), strings.TrimSpace(firstZero))
assert.Assert(c, out, checker.Not(checker.Contains), strings.TrimSpace(secondZero))
}
func (s *DockerSuite) TestPsRightTagName(c *check.C) {
@ -499,11 +499,11 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
f := strings.Fields(line)
switch f[0] {
case id1:
c.Assert(f[1], checker.Equals, "busybox", check.Commentf("Expected %s tag for id %s, got %s", "busybox", id1, f[1]))
assert.Assert(c, f[1], checker.Equals, "busybox", check.Commentf("Expected %s tag for id %s, got %s", "busybox", id1, f[1]))
case id2:
c.Assert(f[1], checker.Equals, tag, check.Commentf("Expected %s tag for id %s, got %s", tag, id2, f[1]))
assert.Assert(c, f[1], checker.Equals, tag, check.Commentf("Expected %s tag for id %s, got %s", tag, id2, f[1]))
case id3:
c.Assert(f[1], checker.Equals, imageID, check.Commentf("Expected %s imageID for id %s, got %s", tag, id3, f[1]))
assert.Assert(c, f[1], checker.Equals, imageID, check.Commentf("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)
}
@ -518,7 +518,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
// Make sure it DOESN'T show up w/o a '-a' for normal 'ps'
out, _ = dockerCmd(c, "ps", "-q")
c.Assert(out, checker.Not(checker.Contains), shortCID, check.Commentf("Should have not seen '%s' in ps output:\n%s", shortCID, out))
assert.Assert(c, out, checker.Not(checker.Contains), shortCID, check.Commentf("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")
@ -529,10 +529,10 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
continue
}
hits++
c.Assert(line, checker.Contains, "Created", check.Commentf("Missing 'Created' on '%s'", line))
assert.Assert(c, line, checker.Contains, "Created", check.Commentf("Missing 'Created' on '%s'", line))
}
c.Assert(hits, checker.Equals, 1, check.Commentf("Should have seen '%s' in ps -a output once:%d\n%s", shortCID, hits, out))
assert.Assert(c, hits, checker.Equals, 1, check.Commentf("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")
@ -564,11 +564,11 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
lines = RemoveLinesForExistingElements(lines, existingContainers)
// skip header
lines = lines[1:]
c.Assert(len(lines), checker.Equals, 1)
assert.Assert(c, len(lines), checker.Equals, 1)
for _, line := range lines {
f := strings.Fields(line)
c.Assert(f[1], checker.Equals, originalImageName)
assert.Assert(c, f[1], checker.Equals, originalImageName)
}
icmd.RunCommand(dockerBinary, "commit", containerID, updatedImageName).Assert(c, icmd.Success)
@ -581,11 +581,11 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
lines = RemoveLinesForExistingElements(lines, existingContainers)
// skip header
lines = lines[1:]
c.Assert(len(lines), checker.Equals, 1)
assert.Assert(c, len(lines), checker.Equals, 1)
for _, line := range lines {
f := strings.Fields(line)
c.Assert(f[1], checker.Equals, originalImageID)
assert.Assert(c, f[1], checker.Equals, originalImageID)
}
}
@ -593,19 +593,19 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name=foo", "-d", "-p", "5000:5000", "busybox", "top")
c.Assert(waitRun("foo"), checker.IsNil)
assert.Assert(c, waitRun("foo"), checker.IsNil)
out, _ := dockerCmd(c, "ps")
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
expected := "0.0.0.0:5000->5000/tcp"
fields := strings.Fields(lines[1])
c.Assert(fields[len(fields)-2], checker.Equals, expected, check.Commentf("Expected: %v, got: %v", expected, fields[len(fields)-2]))
assert.Assert(c, fields[len(fields)-2], checker.Equals, expected, check.Commentf("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])
c.Assert(fields[len(fields)-2], checker.Not(checker.Equals), expected, check.Commentf("Should not got %v", expected))
assert.Assert(c, fields[len(fields)-2], checker.Not(checker.Equals), expected, check.Commentf("Should not got %v", expected))
}
func (s *DockerSuite) TestPsShowMounts(c *check.C) {
@ -618,9 +618,9 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
dockerCmd(c, "volume", "create", "ps-volume-test")
// volume mount containers
runSleepingContainer(c, "--name=volume-test-1", "--volume", "ps-volume-test:"+mp)
c.Assert(waitRun("volume-test-1"), checker.IsNil)
assert.Assert(c, waitRun("volume-test-1"), checker.IsNil)
runSleepingContainer(c, "--name=volume-test-2", "--volume", mp)
c.Assert(waitRun("volume-test-2"), checker.IsNil)
assert.Assert(c, waitRun("volume-test-2"), checker.IsNil)
// bind mount container
var bindMountSource string
var bindMountDestination string
@ -632,7 +632,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
bindMountDestination = "/t"
}
runSleepingContainer(c, "--name=bind-mount-test", "-v", bindMountSource+":"+bindMountDestination)
c.Assert(waitRun("bind-mount-test"), checker.IsNil)
assert.Assert(c, waitRun("bind-mount-test"), checker.IsNil)
out, _ := dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}")
@ -642,8 +642,8 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
fields := strings.Fields(lines[0])
assert.Equal(c, len(fields), 2)
c.Assert(fields[0], checker.Equals, "bind-mount-test")
c.Assert(fields[1], checker.Equals, bindMountSource)
assert.Assert(c, fields[0], checker.Equals, "bind-mount-test")
assert.Assert(c, fields[1], checker.Equals, bindMountSource)
fields = strings.Fields(lines[1])
assert.Equal(c, len(fields), 2)
@ -651,7 +651,7 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
anonymousVolumeID := fields[1]
fields = strings.Fields(lines[2])
c.Assert(fields[1], checker.Equals, "ps-volume-test")
assert.Assert(c, fields[1], checker.Equals, "ps-volume-test")
// filter by volume name
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=ps-volume-test")
@ -661,11 +661,11 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
assert.Equal(c, len(lines), 1)
fields = strings.Fields(lines[0])
c.Assert(fields[1], checker.Equals, "ps-volume-test")
assert.Assert(c, fields[1], checker.Equals, "ps-volume-test")
// empty results filtering by unknown volume
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=this-volume-should-not-exist")
c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)
assert.Assert(c, strings.TrimSpace(string(out)), checker.HasLen, 0)
// filter by mount destination
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+mp)
@ -675,9 +675,9 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
assert.Equal(c, len(lines), 2)
fields = strings.Fields(lines[0])
c.Assert(fields[1], checker.Equals, anonymousVolumeID)
assert.Assert(c, fields[1], checker.Equals, anonymousVolumeID)
fields = strings.Fields(lines[1])
c.Assert(fields[1], checker.Equals, "ps-volume-test")
assert.Assert(c, fields[1], checker.Equals, "ps-volume-test")
// filter by bind mount source
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountSource)
@ -688,8 +688,8 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
fields = strings.Fields(lines[0])
assert.Equal(c, len(fields), 2)
c.Assert(fields[0], checker.Equals, "bind-mount-test")
c.Assert(fields[1], checker.Equals, bindMountSource)
assert.Assert(c, fields[0], checker.Equals, "bind-mount-test")
assert.Assert(c, fields[1], checker.Equals, bindMountSource)
// filter by bind mount destination
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+bindMountDestination)
@ -700,12 +700,12 @@ func (s *DockerSuite) TestPsShowMounts(c *check.C) {
fields = strings.Fields(lines[0])
assert.Equal(c, len(fields), 2)
c.Assert(fields[0], checker.Equals, "bind-mount-test")
c.Assert(fields[1], checker.Equals, bindMountSource)
assert.Assert(c, fields[0], checker.Equals, "bind-mount-test")
assert.Assert(c, fields[1], checker.Equals, bindMountSource)
// empty results filtering by unknown mount point
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+prefix+slash+"this-path-was-never-mounted")
c.Assert(strings.TrimSpace(string(out)), checker.HasLen, 0)
assert.Assert(c, strings.TrimSpace(string(out)), checker.HasLen, 0)
}
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
@ -743,7 +743,7 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
assert.Equal(c, len(RemoveLinesForExistingElements(lines, existing)), 1)
// Making sure onbridgenetwork is on the output
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
assert.Assert(c, containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
// Filter docker ps on networks bridge and none
out, _ = dockerCmd(c, "ps", "--filter", "network=bridge", "--filter", "network=none")
@ -758,8 +758,8 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
assert.Equal(c, len(RemoveLinesForExistingElements(lines, existing)), 2)
// Making sure onbridgenetwork and onnonenetwork is on the output
c.Assert(containerOut, checker.Contains, "onnonenetwork", check.Commentf("Missing the container on none network\n"))
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on bridge network\n"))
assert.Assert(c, containerOut, checker.Contains, "onnonenetwork", check.Commentf("Missing the container on none network\n"))
assert.Assert(c, containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on bridge network\n"))
nwID, _ := dockerCmd(c, "network", "inspect", "--format", "{{.ID}}", "bridge")
@ -784,7 +784,7 @@ func (s *DockerSuite) TestPsListContainersFilterNetwork(c *check.C) {
assert.Equal(c, len(RemoveLinesForExistingElements(lines, existing)), 1)
// Making sure onbridgenetwork is on the output
c.Assert(containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
assert.Assert(c, containerOut, checker.Contains, "onbridgenetwork", check.Commentf("Missing the container on network\n"))
}
@ -818,28 +818,28 @@ func (s *DockerSuite) TestPsListContainersFilterPorts(c *check.C) {
id2 := strings.TrimSpace(out)
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q")
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, id2)
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=80-8080/udp")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Equals), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Equals), id2)
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8081")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Equals), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Equals), id2)
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "publish=80-81")
assert.Equal(c, strings.TrimSpace(out), id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Equals), id2)
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=80/tcp")
assert.Equal(c, strings.TrimSpace(out), id1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Equals), id2)
out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter", "expose=8080/tcp")
out = RemoveOutputForExistingElements(out, existingContainers)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), id1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Equals), id1)
assert.Equal(c, strings.TrimSpace(out), id2)
}

View file

@ -340,10 +340,10 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *check.C) {
// Add to revision store
revisionDir := filepath.Join(registryV2Path, "repositories", remoteRepoName, "_manifests", "revisions", "sha256", hexDigest)
err = os.Mkdir(revisionDir, 0755)
c.Assert(err, checker.IsNil, check.Commentf("error creating revision dir"))
assert.Assert(c, err, checker.IsNil, check.Commentf("error creating revision dir"))
revisionPath := filepath.Join(revisionDir, "link")
err = ioutil.WriteFile(revisionPath, []byte(manifestListDigest.String()), 0644)
c.Assert(err, checker.IsNil, check.Commentf("error writing revision link"))
assert.Assert(c, err, checker.IsNil, check.Commentf("error writing revision link"))
// Update tag
tagPath := filepath.Join(registryV2Path, "repositories", remoteRepoName, "_manifests", "tags", "latest", "current", "link")
@ -355,7 +355,7 @@ func (s *DockerRegistrySuite) TestPullManifestList(c *check.C) {
// The pull output includes "Digest: <digest>", so find that
matches := digestRegex.FindStringSubmatch(out)
c.Assert(matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
assert.Assert(c, matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
pullDigest := matches[1]
// Make sure the pushed and pull digests match
@ -395,7 +395,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuthLoginWithSchem
b, err := ioutil.ReadFile(configPath)
assert.NilError(c, err)
c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":")
assert.Assert(c, string(b), checker.Not(checker.Contains), "\"auth\":")
dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
dockerCmd(c, "--config", tmp, "push", repoName)
@ -440,7 +440,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullWithExternalAuth(c *check.C) {
b, err := ioutil.ReadFile(configPath)
assert.NilError(c, err)
c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":")
assert.Assert(c, string(b), checker.Not(checker.Contains), "\"auth\":")
dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
dockerCmd(c, "--config", tmp, "push", repoName)
@ -462,10 +462,10 @@ func (s *DockerRegistrySuite) TestRunImplicitPullWithNoTag(c *check.C) {
dockerCmd(c, "rmi", repoTag2)
out, _ := dockerCmd(c, "run", repo)
c.Assert(out, checker.Contains, fmt.Sprintf("Unable to find image '%s:latest' locally", repo))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Unable to find image '%s:latest' locally", repo))
// There should be only one line for repo, the one with repo:latest
outImageCmd, _ := dockerCmd(c, "images", repo)
splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
c.Assert(splitOutImageCmd, checker.HasLen, 2)
assert.Assert(c, splitOutImageCmd, checker.HasLen, 2)
}

View file

@ -27,12 +27,12 @@ func (s *DockerSuite) TestRmiWithContainerFails(c *check.C) {
// Container is using image, should not be able to rmi
assert.ErrorContains(c, err, "")
// Container is using image, error message should contain errSubstr
c.Assert(out, checker.Contains, errSubstr, check.Commentf("Container: %q", cleanedContainerID))
assert.Assert(c, out, checker.Contains, errSubstr, check.Commentf("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
c.Assert(images, checker.Contains, "busybox")
assert.Assert(c, images, checker.Contains, "busybox")
}
func (s *DockerSuite) TestRmiTag(c *check.C) {
@ -42,23 +42,23 @@ func (s *DockerSuite) TestRmiTag(c *check.C) {
dockerCmd(c, "tag", "busybox", "utest:5000/docker:tag3")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+3, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Assert(c, strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+3, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
dockerCmd(c, "rmi", "utest/docker:tag2")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Assert(c, strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
dockerCmd(c, "rmi", "utest:5000/docker:tag3")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+1, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Assert(c, strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+1, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
dockerCmd(c, "rmi", "utest:tag1")
{
imagesAfter, _ := dockerCmd(c, "images", "-a")
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n"), check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Assert(c, strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n"), check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
}
@ -81,7 +81,7 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
// tag busybox to create 2 more images with same imageID
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("docker images shows: %q\n", imagesAfter))
assert.Assert(c, strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+2, check.Commentf("docker images shows: %q\n", imagesAfter))
imgID := inspectField(c, "busybox-one:tag1", "Id")
@ -101,7 +101,7 @@ func (s *DockerSuite) TestRmiImgIDMultipleTag(c *check.C) {
imagesAfter = cli.DockerCmd(c, "images", "-a").Combined()
// rmi -f failed, image still exists
c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12], check.Commentf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter))
assert.Assert(c, imagesAfter, checker.Not(checker.Contains), imgID[:12], check.Commentf("ImageID:%q; ImagesAfter: %q", imgID, imagesAfter))
}
func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
@ -123,7 +123,7 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
cli.DockerCmd(c, "tag", "busybox-test", "utest:5000/docker:tag4")
{
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
c.Assert(strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+4, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
assert.Assert(c, strings.Count(imagesAfter, "\n"), checker.Equals, strings.Count(imagesBefore, "\n")+4, check.Commentf("before: %q\n\nafter: %q\n", imagesBefore, imagesAfter))
}
imgID := inspectField(c, "busybox-test", "Id")
@ -137,7 +137,7 @@ func (s *DockerSuite) TestRmiImgIDForce(c *check.C) {
{
imagesAfter := cli.DockerCmd(c, "images", "-a").Combined()
// rmi failed, image still exists
c.Assert(imagesAfter, checker.Not(checker.Contains), imgID[:12])
assert.Assert(c, imagesAfter, checker.Not(checker.Contains), imgID[:12])
}
}
@ -154,7 +154,7 @@ func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c
out, _, err := dockerCmdWithError("rmi", "-f", imgID)
// rmi -f should not delete image with running containers
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "(cannot be forced) - image is being used by running container")
assert.Assert(c, out, checker.Contains, "(cannot be forced) - image is being used by running container")
}
func (s *DockerSuite) TestRmiTagWithExistingContainers(c *check.C) {
@ -166,7 +166,7 @@ func (s *DockerSuite) TestRmiTagWithExistingContainers(c *check.C) {
dockerCmd(c, "run", "--name", container, bb, "/bin/true")
out, _ := dockerCmd(c, "rmi", newtag)
c.Assert(strings.Count(out, "Untagged: "), checker.Equals, 1)
assert.Assert(c, strings.Count(out, "Untagged: "), checker.Equals, 1)
}
func (s *DockerSuite) TestRmiForceWithExistingContainers(c *check.C) {
@ -194,7 +194,7 @@ func (s *DockerSuite) TestRmiWithMultipleRepositories(c *check.C) {
dockerCmd(c, "commit", "test", newTag)
out, _ := dockerCmd(c, "rmi", newTag)
c.Assert(out, checker.Contains, "Untagged: "+newTag)
assert.Assert(c, out, checker.Contains, "Untagged: "+newTag)
}
func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) {
@ -207,12 +207,12 @@ func (s *DockerSuite) TestRmiForceWithMultipleRepositories(c *check.C) {
dockerCmd(c, "tag", tag1, tag2)
out, _ := dockerCmd(c, "rmi", "-f", tag2)
c.Assert(out, checker.Contains, "Untagged: "+tag2)
c.Assert(out, checker.Not(checker.Contains), "Untagged: "+tag1)
assert.Assert(c, out, checker.Contains, "Untagged: "+tag2)
assert.Assert(c, out, checker.Not(checker.Contains), "Untagged: "+tag1)
// Check built image still exists
images, _ := dockerCmd(c, "images", "-a")
c.Assert(images, checker.Contains, imageName, check.Commentf("Built image missing %q; Images: %q", imageName, images))
assert.Assert(c, images, checker.Contains, imageName, check.Commentf("Built image missing %q; Images: %q", imageName, images))
}
func (s *DockerSuite) TestRmiBlank(c *check.C) {
@ -220,9 +220,9 @@ func (s *DockerSuite) TestRmiBlank(c *check.C) {
// Should have failed to delete ' ' image
assert.ErrorContains(c, err, "")
// Wrong error message generated
c.Assert(out, checker.Not(checker.Contains), "no such id", check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Not(checker.Contains), "no such id", check.Commentf("out: %s", out))
// Expected error message not generated
c.Assert(out, checker.Contains, "image name cannot be blank", check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Contains, "image name cannot be blank", check.Commentf("out: %s", out))
}
func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) {
@ -247,7 +247,7 @@ func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) {
out, _, err := dockerCmdWithError("rmi", "-f", imageIds[0])
// The image of the running container should not be removed.
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "image is being used by running container", check.Commentf("out: %s", out))
assert.Assert(c, out, checker.Contains, "image is being used by running container", check.Commentf("out: %s", out))
}
// #13422
@ -274,7 +274,7 @@ RUN echo 2 #layer2
// See if the "tmp2" can be untagged.
out, _ = dockerCmd(c, "rmi", newTag)
// Expected 1 untagged entry
c.Assert(strings.Count(out, "Untagged: "), checker.Equals, 1, check.Commentf("out: %s", out))
assert.Assert(c, strings.Count(out, "Untagged: "), checker.Equals, 1, check.Commentf("out: %s", out))
// Now let's add the tag again and create a container based on it.
dockerCmd(c, "tag", idToTag, newTag)
@ -286,13 +286,13 @@ RUN echo 2 #layer2
out, _, err := dockerCmdWithError("rmi", newTag)
// should not be untagged without the -f flag
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, cid[:12])
c.Assert(out, checker.Contains, "(must force)")
assert.Assert(c, out, checker.Contains, cid[:12])
assert.Assert(c, out, checker.Contains, "(must force)")
// Add the -f flag and test again.
out, _ = dockerCmd(c, "rmi", "-f", newTag)
// should be allowed to untag with the -f flag
c.Assert(out, checker.Contains, fmt.Sprintf("Untagged: %s:latest", newTag))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("Untagged: %s:latest", newTag))
}
func (*DockerSuite) TestRmiParentImageFail(c *check.C) {
@ -335,5 +335,5 @@ func (s *DockerSuite) TestRmiByIDHardConflict(c *check.C) {
// check that tag was not removed
imgID2 := inspectField(c, "busybox:latest", "Id")
c.Assert(imgID, checker.Equals, imgID2)
assert.Assert(c, imgID, checker.Equals, imgID2)
}

View file

@ -211,13 +211,13 @@ func (s *DockerSuite) TestUserDefinedNetworkLinks(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "udlinkNet")
dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
// run a container in user-defined network udlinkNet with a link for an existing container
// and a link for a container that doesn't exist
dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=second", "--link=first:foo",
"--link=third:bar", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// ping to first and its alias foo must succeed
_, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
@ -233,7 +233,7 @@ func (s *DockerSuite) TestUserDefinedNetworkLinks(c *check.C) {
// start third container now
dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=third", "busybox", "top")
c.Assert(waitRun("third"), check.IsNil)
assert.Assert(c, waitRun("third"), check.IsNil)
// ping to third and its alias must succeed now
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "third")
@ -247,11 +247,11 @@ func (s *DockerSuite) TestUserDefinedNetworkLinksWithRestart(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "udlinkNet")
dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
dockerCmd(c, "run", "-d", "--net=udlinkNet", "--name=second", "--link=first:foo",
"busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// ping to first and its alias foo must succeed
_, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
@ -261,7 +261,7 @@ func (s *DockerSuite) TestUserDefinedNetworkLinksWithRestart(c *check.C) {
// Restart first container
dockerCmd(c, "restart", "first")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
// ping to first and its alias foo must still succeed
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
@ -271,7 +271,7 @@ func (s *DockerSuite) TestUserDefinedNetworkLinksWithRestart(c *check.C) {
// Restart second container
dockerCmd(c, "restart", "second")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// ping to first and its alias foo must still succeed
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
@ -287,7 +287,7 @@ func (s *DockerSuite) TestRunWithNetAliasOnDefaultNetworks(c *check.C) {
for _, net := range defaults {
out, _, err := dockerCmdWithError("run", "-d", "--net", net, "--net-alias", "alias_"+net, "busybox", "top")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrUnsupportedNetworkAndAlias.Error())
}
}
@ -296,20 +296,20 @@ func (s *DockerSuite) TestUserDefinedNetworkAlias(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "net1")
cid1, _ := dockerCmd(c, "run", "-d", "--net=net1", "--name=first", "--net-alias=foo1", "--net-alias=foo2", "busybox:glibc", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
// Check if default short-id alias is added automatically
id := strings.TrimSpace(cid1)
aliases := inspectField(c, id, "NetworkSettings.Networks.net1.Aliases")
c.Assert(aliases, checker.Contains, stringid.TruncateID(id))
assert.Assert(c, aliases, checker.Contains, stringid.TruncateID(id))
cid2, _ := dockerCmd(c, "run", "-d", "--net=net1", "--name=second", "busybox:glibc", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// Check if default short-id alias is added automatically
id = strings.TrimSpace(cid2)
aliases = inspectField(c, id, "NetworkSettings.Networks.net1.Aliases")
c.Assert(aliases, checker.Contains, stringid.TruncateID(id))
assert.Assert(c, aliases, checker.Contains, stringid.TruncateID(id))
// ping to first and its network-scoped aliases
_, _, err := dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
@ -324,7 +324,7 @@ func (s *DockerSuite) TestUserDefinedNetworkAlias(c *check.C) {
// Restart first container
dockerCmd(c, "restart", "first")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
// ping to first and its network-scoped aliases must succeed
_, _, err = dockerCmdWithError("exec", "second", "ping", "-c", "1", "first")
@ -342,7 +342,7 @@ func (s *DockerSuite) TestUserDefinedNetworkAlias(c *check.C) {
func (s *DockerSuite) TestRunWithDaemonFlags(c *check.C) {
out, _, err := dockerCmdWithError("--exec-opt", "foo=bar", "run", "-i", "busybox", "true")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "unknown flag: --exec-opt")
assert.Assert(c, out, checker.Contains, "unknown flag: --exec-opt")
}
// Regression test for #4979
@ -2294,8 +2294,8 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughExpose(c *check.C) {
func (s *DockerSuite) TestRunExposePort(c *check.C) {
out, _, err := dockerCmdWithError("run", "--expose", "80000", "busybox")
c.Assert(err, checker.NotNil, check.Commentf("--expose with an invalid port should error out"))
c.Assert(out, checker.Contains, "invalid range format for --expose")
assert.Assert(c, err, checker.NotNil, check.Commentf("--expose with an invalid port should error out"))
assert.Assert(c, out, checker.Contains, "invalid range format for --expose")
}
func (s *DockerSuite) TestRunModeIpcHost(c *check.C) {
@ -2478,7 +2478,7 @@ func (s *DockerSuite) TestRunModeUTSHost(c *check.C) {
}
out, _ = dockerCmdWithFail(c, "run", "-h=name", "--uts=host", "busybox", "ps")
c.Assert(out, checker.Contains, runconfig.ErrConflictUTSHostname.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictUTSHostname.Error())
}
func (s *DockerSuite) TestRunTLSVerify(c *check.C) {
@ -2815,7 +2815,7 @@ func (s *DockerSuite) TestRunPIDHostWithChildIsKillable(c *check.C) {
name := "ibuildthecloud"
dockerCmd(c, "run", "-d", "--pid=host", "--name", name, "busybox", "sh", "-c", "sleep 30; echo hi")
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
errchan := make(chan error)
go func() {
@ -3210,11 +3210,11 @@ func (s *DockerSuite) TestRunCreateContainerFailedCleanUp(c *check.C) {
testRequires(c, DaemonIsLinux)
name := "unique_name"
_, _, err := dockerCmdWithError("run", "--name", name, "--link", "nothing:nothing", "busybox")
c.Assert(err, check.NotNil, check.Commentf("Expected docker run to fail!"))
assert.Assert(c, err, check.NotNil, check.Commentf("Expected docker run to fail!"))
containerID, err := inspectFieldWithError(name, "Id")
c.Assert(err, checker.NotNil, check.Commentf("Expected not to have this container: %s!", containerID))
c.Assert(containerID, check.Equals, "", check.Commentf("Expected not to have this container: %s!", containerID))
assert.Assert(c, err, checker.NotNil, check.Commentf("Expected not to have this container: %s!", containerID))
assert.Assert(c, containerID, check.Equals, "", check.Commentf("Expected not to have this container: %s!", containerID))
}
func (s *DockerSuite) TestRunNamedVolume(c *check.C) {
@ -3223,10 +3223,10 @@ func (s *DockerSuite) TestRunNamedVolume(c *check.C) {
dockerCmd(c, "run", "--name=test", "-v", "testing:"+prefix+"/foo", "busybox", "sh", "-c", "echo hello > "+prefix+"/foo/bar")
out, _ := dockerCmd(c, "run", "--volumes-from", "test", "busybox", "sh", "-c", "cat "+prefix+"/foo/bar")
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "hello")
out, _ = dockerCmd(c, "run", "-v", "testing:"+prefix+"/foo", "busybox", "sh", "-c", "cat "+prefix+"/foo/bar")
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "hello")
}
func (s *DockerSuite) TestRunWithUlimits(c *check.C) {
@ -3466,7 +3466,7 @@ func (s *DockerSuite) TestContainersInUserDefinedNetwork(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace, NotArm)
dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork")
dockerCmd(c, "run", "-d", "--net=testnetwork", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
dockerCmd(c, "run", "-t", "--net=testnetwork", "--name=second", "busybox", "ping", "-c", "1", "first")
}
@ -3477,9 +3477,9 @@ func (s *DockerSuite) TestContainersInMultipleNetworks(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork2")
// Run and connect containers to testnetwork1
dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=second", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// Check connectivity between containers in testnetwork2
dockerCmd(c, "exec", "first", "ping", "-c", "1", "second.testnetwork1")
// Connect containers to testnetwork2
@ -3496,9 +3496,9 @@ func (s *DockerSuite) TestContainersNetworkIsolation(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork2")
// Run 1 container in testnetwork1 and another in testnetwork2
dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
dockerCmd(c, "run", "-d", "--net=testnetwork2", "--name=second", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// Check Isolation between containers : ping must fail
_, _, err := dockerCmdWithError("exec", "first", "ping", "-c", "1", "second")
@ -3522,9 +3522,9 @@ func (s *DockerSuite) TestNetworkRmWithActiveContainers(c *check.C) {
dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1")
// Run and connect containers to testnetwork1
dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=second", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// Network delete with active containers must fail
_, _, err := dockerCmdWithError("network", "rm", "testnetwork1")
assert.ErrorContains(c, err, "")
@ -3542,9 +3542,9 @@ func (s *DockerSuite) TestContainerRestartInMultipleNetworks(c *check.C) {
// Run and connect containers to testnetwork1
dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=second", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// Check connectivity between containers in testnetwork2
dockerCmd(c, "exec", "first", "ping", "-c", "1", "second.testnetwork1")
// Connect containers to testnetwork2
@ -3570,7 +3570,7 @@ func (s *DockerSuite) TestContainerWithConflictingHostNetworks(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace)
// Run a container with --net=host
dockerCmd(c, "run", "-d", "--net=host", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
// Create a network using bridge driver
dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1")
@ -3583,10 +3583,10 @@ func (s *DockerSuite) TestContainerWithConflictingHostNetworks(c *check.C) {
func (s *DockerSuite) TestContainerWithConflictingSharedNetwork(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
// Run second container in first container's network namespace
dockerCmd(c, "run", "-d", "--net=container:first", "--name=second", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// Create a network using bridge driver
dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1")
@ -3594,13 +3594,13 @@ func (s *DockerSuite) TestContainerWithConflictingSharedNetwork(c *check.C) {
// Connecting to the user defined network must fail
out, _, err := dockerCmdWithError("network", "connect", "testnetwork1", "second")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, runconfig.ErrConflictSharedNetwork.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictSharedNetwork.Error())
}
func (s *DockerSuite) TestContainerWithConflictingNoneNetwork(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "-d", "--net=none", "--name=first", "busybox", "top")
c.Assert(waitRun("first"), check.IsNil)
assert.Assert(c, waitRun("first"), check.IsNil)
// Create a network using bridge driver
dockerCmd(c, "network", "create", "-d", "bridge", "testnetwork1")
@ -3608,11 +3608,11 @@ func (s *DockerSuite) TestContainerWithConflictingNoneNetwork(c *check.C) {
// Connecting to the user defined network must fail
out, _, err := dockerCmdWithError("network", "connect", "testnetwork1", "first")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, runconfig.ErrConflictNoNetwork.Error())
assert.Assert(c, out, checker.Contains, runconfig.ErrConflictNoNetwork.Error())
// create a container connected to testnetwork1
dockerCmd(c, "run", "-d", "--net=testnetwork1", "--name=second", "busybox", "top")
c.Assert(waitRun("second"), check.IsNil)
assert.Assert(c, waitRun("second"), check.IsNil)
// Connect second container to none network. it must fail as well
_, _, err = dockerCmdWithError("network", "connect", "none", "second")
@ -3628,7 +3628,7 @@ func (s *DockerSuite) TestRunStdinBlockedAfterContainerExit(c *check.C) {
stdout := bytes.NewBuffer(nil)
cmd.Stdout = stdout
cmd.Stderr = stdout
c.Assert(cmd.Start(), check.IsNil)
assert.Assert(c, cmd.Start(), check.IsNil)
waitChan := make(chan error)
go func() {
@ -3637,7 +3637,7 @@ func (s *DockerSuite) TestRunStdinBlockedAfterContainerExit(c *check.C) {
select {
case err := <-waitChan:
c.Assert(err, check.IsNil, check.Commentf(stdout.String()))
assert.Assert(c, err, check.IsNil, check.Commentf(stdout.String()))
case <-time.After(30 * time.Second):
c.Fatal("timeout waiting for command to exit")
}
@ -3857,8 +3857,8 @@ func (s *DockerSuite) TestRunVolumesMountedAsSlave(c *check.C) {
func (s *DockerSuite) TestRunNamedVolumesMountedAsShared(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace)
out, exitCode, _ := dockerCmdWithError("run", "-v", "foo:/test:shared", "busybox", "touch", "/test/somefile")
c.Assert(exitCode, checker.Not(checker.Equals), 0)
c.Assert(out, checker.Contains, "invalid mount config")
assert.Assert(c, exitCode, checker.Not(checker.Equals), 0)
assert.Assert(c, out, checker.Contains, "invalid mount config")
}
func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) {
@ -3872,7 +3872,7 @@ func (s *DockerSuite) TestRunNamedVolumeCopyImageData(c *check.C) {
dockerCmd(c, "run", "-v", "foo:/foo", testImg)
out, _ := dockerCmd(c, "run", "-v", "foo:/foo", "busybox", "cat", "/foo/hello")
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "hello")
}
func (s *DockerSuite) TestRunNamedVolumeNotRemoved(c *check.C) {
@ -3911,7 +3911,7 @@ func (s *DockerSuite) TestRunNamedVolumesFromNotRemoved(c *check.C) {
vname = v.Name
}
}
c.Assert(vname, checker.Not(checker.Equals), "")
assert.Assert(c, vname, checker.Not(checker.Equals), "")
// Remove the parent so there are not other references to the volumes
dockerCmd(c, "rm", "-f", "parent")
@ -3920,7 +3920,7 @@ func (s *DockerSuite) TestRunNamedVolumesFromNotRemoved(c *check.C) {
dockerCmd(c, "volume", "inspect", "test")
out, _ := dockerCmd(c, "volume", "ls", "-q")
assert.Assert(c, strings.Contains(out, "test"))
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), vname)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), vname)
}
func (s *DockerSuite) TestRunAttachFailedNoLeak(c *check.C) {
@ -3944,16 +3944,16 @@ func (s *DockerSuite) TestRunAttachFailedNoLeak(c *check.C) {
runSleepingContainer(c, "--name=test", "-p", "8000:8000")
// Wait until container is fully up and running
c.Assert(waitRun("test"), check.IsNil)
assert.Assert(c, waitRun("test"), check.IsNil)
out, _, err := dockerCmdWithError("run", "--name=fail", "-p", "8000:8000", "busybox", "true")
// 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")
c.Assert(err, checker.NotNil, 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, checker.NotNil, check.Commentf("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
c.Assert(strings.Contains(string(out), "port is already allocated") ||
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") ||
@ -3961,7 +3961,7 @@ func (s *DockerSuite) TestRunAttachFailedNoLeak(c *check.C) {
dockerCmd(c, "rm", "-f", "test")
// NGoroutines is not updated right away, so we need to wait before failing
c.Assert(waitForGoroutines(nroutines), checker.IsNil)
assert.Assert(c, waitForGoroutines(nroutines), checker.IsNil)
}
// Test for one character directory name case (#20122)
@ -4036,9 +4036,9 @@ func (s *DockerSuite) TestRunDNSInHostMode(c *check.C) {
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()
c.Assert(out, checker.Contains, expectedOutput1, check.Commentf("Expected '%s', but got %q", expectedOutput1, out))
c.Assert(out, checker.Contains, expectedOutput2, check.Commentf("Expected '%s', but got %q", expectedOutput2, out))
c.Assert(out, checker.Contains, expectedOutput3, check.Commentf("Expected '%s', but got %q", expectedOutput3, out))
assert.Assert(c, out, checker.Contains, expectedOutput1, check.Commentf("Expected '%s', but got %q", expectedOutput1, out))
assert.Assert(c, out, checker.Contains, expectedOutput2, check.Commentf("Expected '%s', but got %q", expectedOutput2, out))
assert.Assert(c, out, checker.Contains, expectedOutput3, check.Commentf("Expected '%s', but got %q", expectedOutput3, out))
}
// Test case for #21976
@ -4047,16 +4047,16 @@ func (s *DockerSuite) TestRunAddHostInHostMode(c *check.C) {
expectedOutput := "1.2.3.4\textra"
out, _ := dockerCmd(c, "run", "--add-host=extra:1.2.3.4", "--net=host", "busybox", "cat", "/etc/hosts")
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
}
func (s *DockerSuite) TestRunRmAndWait(c *check.C) {
dockerCmd(c, "run", "--name=test", "--rm", "-d", "busybox", "sh", "-c", "sleep 3;exit 2")
out, code, err := dockerCmdWithError("wait", "test")
c.Assert(err, checker.IsNil, check.Commentf("out: %s; exit code: %d", out, code))
assert.Assert(c, err, checker.IsNil, check.Commentf("out: %s; exit code: %d", out, code))
assert.Equal(c, out, "2\n", "exit code: %d", code)
c.Assert(code, checker.Equals, 0)
assert.Assert(c, code, checker.Equals, 0)
}
// Test that auto-remove is performed by the daemon (API 1.25 and above)
@ -4104,7 +4104,7 @@ exec "$@"`,
cli.BuildCmd(c, name, build.WithExternalBuildContext(ctx))
out := cli.DockerCmd(c, "run", "--entrypoint=", "-t", name, "echo", "foo").Combined()
c.Assert(strings.TrimSpace(out), check.Equals, "foo")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "foo")
// CMD will be reset as well (the same as setting a custom entrypoint)
cli.Docker(cli.Args("run", "--entrypoint=", "-t", name)).Assert(c, icmd.Expected{
@ -4123,7 +4123,7 @@ func (s *DockerDaemonSuite) TestRunWithUlimitAndDaemonDefault(c *check.C) {
out, err := s.d.Cmd("inspect", "--format", "{{.HostConfig.Ulimits}}", name)
assert.NilError(c, err)
c.Assert(out, checker.Contains, "[nofile=65535:65535]")
assert.Assert(c, out, checker.Contains, "[nofile=65535:65535]")
name = "test-B"
_, err = s.d.Cmd("run", "--name", name, "--ulimit=nofile=42", "-d", "busybox", "top")
@ -4141,10 +4141,10 @@ func (s *DockerSuite) TestRunStoppedLoggingDriverNoLeak(c *check.C) {
out, _, err := dockerCmdWithError("run", "--name=fail", "--log-driver=splunk", "busybox", "true")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "failed to initialize logging driver", check.Commentf("error should be about logging driver, got output %s", out))
assert.Assert(c, out, checker.Contains, "failed to initialize logging driver", check.Commentf("error should be about logging driver, got output %s", out))
// NGoroutines is not updated right away, so we need to wait before failing
c.Assert(waitForGoroutines(nroutines), checker.IsNil)
assert.Assert(c, waitForGoroutines(nroutines), checker.IsNil)
}
// Handles error conditions for --credentialspec. Validating E2E success cases
@ -4162,8 +4162,8 @@ func (s *DockerSuite) TestRunCredentialSpecFailures(c *check.C) {
}
for _, attempt := range attempts {
_, _, err := dockerCmdWithError("run", "--security-opt=credentialspec="+attempt.value, "busybox", "true")
c.Assert(err, checker.NotNil, check.Commentf("%s expected non-nil err", attempt.value))
c.Assert(err.Error(), checker.Contains, attempt.expectedError, check.Commentf("%s expected %s got %s", attempt.value, attempt.expectedError, err))
assert.Assert(c, err, checker.NotNil, check.Commentf("%s expected non-nil err", attempt.value))
assert.Assert(c, err.Error(), checker.Contains, attempt.expectedError, check.Commentf("%s expected %s got %s", attempt.value, attempt.expectedError, err))
}
}
@ -4179,8 +4179,8 @@ func (s *DockerSuite) TestRunCredentialSpecWellFormed(c *check.C) {
// controller handy
out, _ := dockerCmd(c, "run", "--rm", "--security-opt=credentialspec="+value, minimalBaseImage(), "nltest", "/PARENTDOMAIN")
c.Assert(out, checker.Contains, "hyperv.local.")
c.Assert(out, checker.Contains, "The command completed successfully")
assert.Assert(c, out, checker.Contains, "hyperv.local.")
assert.Assert(c, out, checker.Contains, "The command completed successfully")
}
}
@ -4198,11 +4198,11 @@ func (s *DockerSuite) TestRunDuplicateMount(c *check.C) {
name := "test"
out, _ := dockerCmd(c, "run", "--name", name, "-v", "/tmp:/tmp", "-v", "/tmp:/tmp", "busybox", "sh", "-c", "cat "+tmpFile.Name()+" && ls /")
c.Assert(out, checker.Not(checker.Contains), "tmp:")
c.Assert(out, checker.Contains, data)
assert.Assert(c, out, checker.Not(checker.Contains), "tmp:")
assert.Assert(c, out, checker.Contains, data)
out = inspectFieldJSON(c, name, "Config.Volumes")
c.Assert(out, checker.Contains, "null")
assert.Assert(c, out, checker.Contains, "null")
}
func (s *DockerSuite) TestRunWindowsWithCPUCount(c *check.C) {
@ -4239,9 +4239,9 @@ func (s *DockerSuite) TestRunProcessIsolationWithCPUCountCPUSharesAndCPUPercent(
testRequires(c, DaemonIsWindows, IsolationIsProcess)
out, _ := dockerCmd(c, "run", "--cpu-count=1", "--cpu-shares=1000", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing")
c.Assert(strings.TrimSpace(out), checker.Contains, "WARNING: Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded")
c.Assert(strings.TrimSpace(out), checker.Contains, "WARNING: Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded")
c.Assert(strings.TrimSpace(out), checker.Contains, "testing")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "WARNING: Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "WARNING: Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "testing")
out = inspectField(c, "test", "HostConfig.CPUCount")
assert.Equal(c, out, "1")
@ -4257,7 +4257,7 @@ func (s *DockerSuite) TestRunHypervIsolationWithCPUCountCPUSharesAndCPUPercent(c
testRequires(c, DaemonIsWindows, IsolationIsHyperv)
out, _ := dockerCmd(c, "run", "--cpu-count=1", "--cpu-shares=1000", "--cpu-percent=80", "--name", "test", "busybox", "echo", "testing")
c.Assert(strings.TrimSpace(out), checker.Contains, "testing")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "testing")
out = inspectField(c, "test", "HostConfig.CPUCount")
assert.Equal(c, out, "1")
@ -4329,7 +4329,7 @@ func (s *DockerSuite) TestRunMountReadOnlyDevShm(c *check.C) {
"-v", fmt.Sprintf("%s:/dev/shm:ro", emptyDir),
"busybox", "touch", "/dev/shm/foo")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "Read-only file system")
assert.Assert(c, out, checker.Contains, "Read-only file system")
}
func (s *DockerSuite) TestRunMount(c *check.C) {
@ -4497,11 +4497,11 @@ func (s *DockerSuite) TestRunMount(c *check.C) {
_, _, err := dockerCmdWithError(append([]string{"run", "-i", "-d", "--name", cName},
append(opts, []string{"busybox", "top"}...)...)...)
if testCase.valid {
c.Assert(err, check.IsNil, check.Commentf("got error while creating a container with %v (%s)", opts, cName))
c.Assert(testCase.fn(cName), check.IsNil, check.Commentf("got error while executing test for %v (%s)", opts, cName))
assert.Assert(c, err, check.IsNil, check.Commentf("got error while creating a container with %v (%s)", opts, cName))
assert.Assert(c, testCase.fn(cName), check.IsNil, check.Commentf("got error while executing test for %v (%s)", opts, cName))
dockerCmd(c, "rm", "-f", cName)
} else {
c.Assert(err, checker.NotNil, check.Commentf("got nil while creating a container with %v (%s)", opts, cName))
assert.Assert(c, err, checker.NotNil, check.Commentf("got nil while creating a container with %v (%s)", opts, cName))
}
}
}
@ -4518,7 +4518,7 @@ func (s *DockerSuite) TestRunHostnameFQDN(c *check.C) {
out, _ = dockerCmd(c, "run", "--hostname=foobar.example.com", "busybox", "sh", "-c", `cat /etc/hosts`)
expectedOutput = "foobar.example.com foobar"
c.Assert(strings.TrimSpace(out), checker.Contains, expectedOutput)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, expectedOutput)
}
// Test case for 29129

View file

@ -35,7 +35,7 @@ import (
func (s *DockerSuite) TestRunRedirectStdout(c *check.C) {
checkRedirect := func(command string) {
_, tty, err := pty.Open()
c.Assert(err, checker.IsNil, check.Commentf("Could not open pty"))
assert.Assert(c, err, checker.IsNil, check.Commentf("Could not open pty"))
cmd := exec.Command("sh", "-c", command)
cmd.Stdin = tty
cmd.Stdout = tty
@ -51,7 +51,7 @@ func (s *DockerSuite) TestRunRedirectStdout(c *check.C) {
case <-time.After(10 * time.Second):
c.Fatal("command timeout")
case err := <-ch:
c.Assert(err, checker.IsNil, check.Commentf("wait err"))
assert.Assert(c, err, checker.IsNil, check.Commentf("wait err"))
}
}
@ -70,15 +70,15 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) {
// Create a temporary tmpfs mount.
tmpfsDir := filepath.Join(tmpDir, "tmpfs")
c.Assert(os.MkdirAll(tmpfsDir, 0777), checker.IsNil, check.Commentf("failed to mkdir at %s", tmpfsDir))
c.Assert(mount.Mount("tmpfs", tmpfsDir, "tmpfs", ""), checker.IsNil, check.Commentf("failed to create a tmpfs mount at %s", tmpfsDir))
assert.Assert(c, os.MkdirAll(tmpfsDir, 0777), checker.IsNil, check.Commentf("failed to mkdir at %s", tmpfsDir))
assert.Assert(c, mount.Mount("tmpfs", tmpfsDir, "tmpfs", ""), checker.IsNil, check.Commentf("failed to create a tmpfs mount at %s", tmpfsDir))
f, err := ioutil.TempFile(tmpfsDir, "touch-me")
assert.NilError(c, err)
defer f.Close()
out, _ := dockerCmd(c, "run", "--name", "test-data", "--volume", fmt.Sprintf("%s:/tmp:ro", tmpDir), "busybox:latest", "ls", "/tmp/tmpfs")
c.Assert(out, checker.Contains, filepath.Base(f.Name()), check.Commentf("Recursive bind mount test failed. Expected file not found"))
assert.Assert(c, out, checker.Contains, filepath.Base(f.Name()), check.Commentf("Recursive bind mount test failed. Expected file not found"))
}
func (s *DockerSuite) TestRunDeviceDirectory(c *check.C) {
@ -88,10 +88,10 @@ func (s *DockerSuite) TestRunDeviceDirectory(c *check.C) {
}
out, _ := dockerCmd(c, "run", "--device", "/dev/snd:/dev/snd", "busybox", "sh", "-c", "ls /dev/snd/")
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "timer", check.Commentf("expected output /dev/snd/timer"))
assert.Assert(c, strings.Trim(out, "\r\n"), checker.Contains, "timer", check.Commentf("expected output /dev/snd/timer"))
out, _ = dockerCmd(c, "run", "--device", "/dev/snd:/dev/othersnd", "busybox", "sh", "-c", "ls /dev/othersnd/")
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "seq", check.Commentf("expected output /dev/othersnd/seq"))
assert.Assert(c, strings.Trim(out, "\r\n"), checker.Contains, "seq", check.Commentf("expected output /dev/othersnd/seq"))
}
// TestRunAttachDetach checks attaching and detaching with the default escape sequence.
@ -108,7 +108,7 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
defer cpty.Close()
cmd.Stdin = tty
assert.NilError(c, cmd.Start())
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
_, err = cpty.Write([]byte("hello\n"))
assert.NilError(c, err)
@ -137,12 +137,12 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
}
running := inspectField(c, name, "State.Running")
c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
assert.Assert(c, running, checker.Equals, "true", check.Commentf("expected container to still be running"))
out, _ = dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c), "-f", "container="+name)
// attach and detach event should be monitored
c.Assert(out, checker.Contains, "attach")
c.Assert(out, checker.Contains, "detach")
assert.Assert(c, out, checker.Contains, "attach")
assert.Assert(c, out, checker.Contains, "detach")
}
// TestRunAttachDetachFromFlag checks attaching and detaching with the escape sequence specified via flags.
@ -167,7 +167,7 @@ func (s *DockerSuite) TestRunAttachDetachFromFlag(c *check.C) {
if err := cmd.Start(); err != nil {
c.Fatal(err)
}
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
if _, err := cpty.Write([]byte("hello\n")); err != nil {
c.Fatal(err)
@ -203,14 +203,14 @@ func (s *DockerSuite) TestRunAttachDetachFromFlag(c *check.C) {
}
running := inspectField(c, name, "State.Running")
c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
assert.Assert(c, running, checker.Equals, "true", check.Commentf("expected container to still be running"))
}
// TestRunAttachDetachFromInvalidFlag checks attaching and detaching with the escape sequence specified via flags.
func (s *DockerSuite) TestRunAttachDetachFromInvalidFlag(c *check.C) {
name := "attach-detach"
dockerCmd(c, "run", "--name", name, "-itd", "busybox", "top")
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
// specify an invalid detach key, container will ignore it and use default
cmd := exec.Command(dockerBinary, "attach", "--detach-keys=ctrl-A,a", name)
@ -283,7 +283,7 @@ func (s *DockerSuite) TestRunAttachDetachFromConfig(c *check.C) {
if err := cmd.Start(); err != nil {
c.Fatal(err)
}
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
if _, err := cpty.Write([]byte("hello\n")); err != nil {
c.Fatal(err)
@ -319,7 +319,7 @@ func (s *DockerSuite) TestRunAttachDetachFromConfig(c *check.C) {
}
running := inspectField(c, name, "State.Running")
c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
assert.Assert(c, running, checker.Equals, "true", check.Commentf("expected container to still be running"))
}
// TestRunAttachDetachKeysOverrideConfig checks attaching and detaching with the detach flags, making sure it overrides config file
@ -366,7 +366,7 @@ func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *check.C) {
if err := cmd.Start(); err != nil {
c.Fatal(err)
}
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
if _, err := cpty.Write([]byte("hello\n")); err != nil {
c.Fatal(err)
@ -402,7 +402,7 @@ func (s *DockerSuite) TestRunAttachDetachKeysOverrideConfig(c *check.C) {
}
running := inspectField(c, name, "State.Running")
c.Assert(running, checker.Equals, "true", check.Commentf("expected container to still be running"))
assert.Assert(c, running, checker.Equals, "true", check.Commentf("expected container to still be running"))
}
func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *check.C) {
@ -427,7 +427,7 @@ func (s *DockerSuite) TestRunAttachInvalidDetachKeySequencePreserved(c *check.C)
c.Fatal(err)
}
go cmd.Wait()
c.Assert(waitRun(name), check.IsNil)
assert.Assert(c, waitRun(name), check.IsNil)
// Invalid escape sequence aba, should print aba in output
if _, err := cpty.Write(keyA); err != nil {
@ -673,11 +673,11 @@ func (s *DockerSuite) TestRunWithSwappinessInvalid(c *check.C) {
out, _, err := dockerCmdWithError("run", "--memory-swappiness", "101", "busybox", "true")
assert.ErrorContains(c, err, "")
expected := "Valid memory swappiness range is 0-100"
c.Assert(out, checker.Contains, expected, check.Commentf("Expected output to contain %q, not %q", out, expected))
assert.Assert(c, out, checker.Contains, expected, check.Commentf("Expected output to contain %q, not %q", out, expected))
out, _, err = dockerCmdWithError("run", "--memory-swappiness", "-10", "busybox", "true")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, expected, check.Commentf("Expected output to contain %q, not %q", out, expected))
assert.Assert(c, out, checker.Contains, expected, check.Commentf("Expected output to contain %q, not %q", out, expected))
}
func (s *DockerSuite) TestRunWithMemoryReservation(c *check.C) {
@ -697,24 +697,24 @@ func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *check.C) {
out, _, err := dockerCmdWithError("run", "-m", "500M", "--memory-reservation", "800M", "busybox", "true")
assert.ErrorContains(c, err, "")
expected := "Minimum memory limit can not be less than memory reservation limit"
c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation"))
assert.Assert(c, strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation"))
out, _, err = dockerCmdWithError("run", "--memory-reservation", "1k", "busybox", "true")
assert.ErrorContains(c, err, "")
expected = "Minimum memory reservation allowed is 4MB"
c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation"))
assert.Assert(c, strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation"))
}
func (s *DockerSuite) TestStopContainerSignal(c *check.C) {
out, _ := dockerCmd(c, "run", "--stop-signal", "SIGUSR1", "-d", "busybox", "/bin/sh", "-c", `trap 'echo "exit trapped"; exit 0' USR1; while true; do sleep 1; done`)
containerID := strings.TrimSpace(out)
c.Assert(waitRun(containerID), checker.IsNil)
assert.Assert(c, waitRun(containerID), checker.IsNil)
dockerCmd(c, "stop", containerID)
out, _ = dockerCmd(c, "logs", containerID)
c.Assert(out, checker.Contains, "exit trapped", check.Commentf("Expected `exit trapped` in the log"))
assert.Assert(c, out, checker.Contains, "exit trapped", check.Commentf("Expected `exit trapped` in the log"))
}
func (s *DockerSuite) TestRunSwapLessThanMemoryLimit(c *check.C) {
@ -793,7 +793,7 @@ func (s *DockerSuite) TestRunWithDefaultShmSize(c *check.C) {
c.Fatalf("Expected shm of 64MB in mount command, got %v", out)
}
shmSize := inspectField(c, name, "HostConfig.ShmSize")
c.Assert(shmSize, check.Equals, "67108864")
assert.Assert(c, shmSize, check.Equals, "67108864")
}
func (s *DockerSuite) TestRunWithShmSize(c *check.C) {
@ -806,7 +806,7 @@ func (s *DockerSuite) TestRunWithShmSize(c *check.C) {
c.Fatalf("Expected shm of 1GB in mount command, got %v", out)
}
shmSize := inspectField(c, name, "HostConfig.ShmSize")
c.Assert(shmSize, check.Equals, "1073741824")
assert.Assert(c, shmSize, check.Equals, "1073741824")
}
func (s *DockerSuite) TestRunTmpfsMountsEnsureOrdered(c *check.C) {
@ -814,7 +814,7 @@ func (s *DockerSuite) TestRunTmpfsMountsEnsureOrdered(c *check.C) {
assert.NilError(c, err)
defer tmpFile.Close()
out, _ := dockerCmd(c, "run", "--tmpfs", "/run", "-v", tmpFile.Name()+":/run/test", "busybox", "ls", "/run")
c.Assert(out, checker.Contains, "test")
assert.Assert(c, out, checker.Contains, "test")
}
func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) {
@ -846,7 +846,7 @@ func (s *DockerSuite) TestRunTmpfsMountsOverrideImageVolumes(c *check.C) {
RUN touch /run/stuff
`))
out, _ := dockerCmd(c, "run", "--tmpfs", "/run", name, "ls", "/run")
c.Assert(out, checker.Not(checker.Contains), "stuff")
assert.Assert(c, out, checker.Not(checker.Contains), "stuff")
}
// Test case for #22420
@ -856,27 +856,27 @@ func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) {
expectedOptions := []string{"rw", "nosuid", "nodev", "noexec", "relatime"}
out, _ := dockerCmd(c, "run", "--tmpfs", "/tmp", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'")
for _, option := range expectedOptions {
c.Assert(out, checker.Contains, option)
assert.Assert(c, out, checker.Contains, option)
}
c.Assert(out, checker.Not(checker.Contains), "size=")
assert.Assert(c, out, checker.Not(checker.Contains), "size=")
expectedOptions = []string{"rw", "nosuid", "nodev", "noexec", "relatime"}
out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'")
for _, option := range expectedOptions {
c.Assert(out, checker.Contains, option)
assert.Assert(c, out, checker.Contains, option)
}
c.Assert(out, checker.Not(checker.Contains), "size=")
assert.Assert(c, out, checker.Not(checker.Contains), "size=")
expectedOptions = []string{"rw", "nosuid", "nodev", "relatime", "size=8192k"}
out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw,exec,size=8192k", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'")
for _, option := range expectedOptions {
c.Assert(out, checker.Contains, option)
assert.Assert(c, out, checker.Contains, option)
}
expectedOptions = []string{"rw", "nosuid", "nodev", "noexec", "relatime", "size=4096k"}
out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:rw,size=8192k,exec,size=4096k,noexec", "busybox", "sh", "-c", "mount | grep 'tmpfs on /tmp'")
for _, option := range expectedOptions {
c.Assert(out, checker.Contains, option)
assert.Assert(c, out, checker.Contains, option)
}
// We use debian:jessie as there is no findmnt in busybox. Also the output will be in the format of
@ -886,7 +886,7 @@ func (s *DockerSuite) TestRunTmpfsMountsWithOptions(c *check.C) {
expectedOptions = []string{"shared"}
out, _ = dockerCmd(c, "run", "--tmpfs", "/tmp:shared", "debian:jessie", "findmnt", "-o", "TARGET,PROPAGATION", "/tmp")
for _, option := range expectedOptions {
c.Assert(out, checker.Contains, option)
assert.Assert(c, out, checker.Contains, option)
}
}
@ -895,23 +895,23 @@ func (s *DockerSuite) TestRunSysctls(c *check.C) {
var err error
out, _ := dockerCmd(c, "run", "--sysctl", "net.ipv4.ip_forward=1", "--name", "test", "busybox", "cat", "/proc/sys/net/ipv4/ip_forward")
c.Assert(strings.TrimSpace(out), check.Equals, "1")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "1")
out = inspectFieldJSON(c, "test", "HostConfig.Sysctls")
sysctls := make(map[string]string)
err = json.Unmarshal([]byte(out), &sysctls)
assert.NilError(c, err)
c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "1")
assert.Assert(c, sysctls["net.ipv4.ip_forward"], check.Equals, "1")
out, _ = dockerCmd(c, "run", "--sysctl", "net.ipv4.ip_forward=0", "--name", "test1", "busybox", "cat", "/proc/sys/net/ipv4/ip_forward")
c.Assert(strings.TrimSpace(out), check.Equals, "0")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "0")
out = inspectFieldJSON(c, "test1", "HostConfig.Sysctls")
err = json.Unmarshal([]byte(out), &sysctls)
assert.NilError(c, err)
c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "0")
assert.Assert(c, sysctls["net.ipv4.ip_forward"], check.Equals, "0")
icmd.RunCommand(dockerBinary, "run", "--sysctl", "kernel.foobar=1", "--name", "test2",
"busybox", "cat", "/proc/sys/kernel/foobar").Assert(c, icmd.Expected{
@ -1391,16 +1391,16 @@ func (s *DockerSuite) TestRunDeviceSymlink(c *check.C) {
// md5sum of 'dd if=/dev/zero bs=4K count=8' is bb7df04e1b0a2570657527a7e108ae23
out, _ := dockerCmd(c, "run", "--device", symZero+":/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum")
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "bb7df04e1b0a2570657527a7e108ae23", check.Commentf("expected output bb7df04e1b0a2570657527a7e108ae23"))
assert.Assert(c, strings.Trim(out, "\r\n"), checker.Contains, "bb7df04e1b0a2570657527a7e108ae23", check.Commentf("expected output bb7df04e1b0a2570657527a7e108ae23"))
// symlink "tmpDir/file" to a file "tmpDir/temp" will result in an error as it is not a device.
out, _, err = dockerCmdWithError("run", "--device", symFile+":/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum")
assert.ErrorContains(c, err, "")
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "not a device node", check.Commentf("expected output 'not a device node'"))
assert.Assert(c, strings.Trim(out, "\r\n"), checker.Contains, "not a device node", check.Commentf("expected output 'not a device node'"))
// md5sum of 'dd if=/dev/zero bs=4K count=8' is bb7df04e1b0a2570657527a7e108ae23 (this time check with relative path backed, see #22271)
out, _ = dockerCmd(c, "run", "--device", "/dev/symzero:/dev/symzero", "busybox", "sh", "-c", "dd if=/dev/symzero bs=4K count=8 | md5sum")
c.Assert(strings.Trim(out, "\r\n"), checker.Contains, "bb7df04e1b0a2570657527a7e108ae23", check.Commentf("expected output bb7df04e1b0a2570657527a7e108ae23"))
assert.Assert(c, strings.Trim(out, "\r\n"), checker.Contains, "bb7df04e1b0a2570657527a7e108ae23", check.Commentf("expected output bb7df04e1b0a2570657527a7e108ae23"))
}
// TestRunPIDsLimit makes sure the pids cgroup is set with --pids-limit
@ -1438,7 +1438,7 @@ func (s *DockerSuite) TestRunUserDeviceAllowed(c *check.C) {
file := "/sys/fs/cgroup/devices/devices.list"
out, _ := dockerCmd(c, "run", "--device", "/dev/snd/timer:w", "busybox", "cat", file)
c.Assert(out, checker.Contains, fmt.Sprintf("c %d:%d w", stat.Rdev/256, stat.Rdev%256))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("c %d:%d w", stat.Rdev/256, stat.Rdev%256))
}
func (s *DockerDaemonSuite) TestRunSeccompJSONNewFormat(c *check.C) {
@ -1463,7 +1463,7 @@ func (s *DockerDaemonSuite) TestRunSeccompJSONNewFormat(c *check.C) {
out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Operation not permitted")
assert.Assert(c, out, checker.Contains, "Operation not permitted")
}
func (s *DockerDaemonSuite) TestRunSeccompJSONNoNameAndNames(c *check.C) {
@ -1489,7 +1489,7 @@ func (s *DockerDaemonSuite) TestRunSeccompJSONNoNameAndNames(c *check.C) {
out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'")
assert.Assert(c, out, checker.Contains, "'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'")
}
func (s *DockerDaemonSuite) TestRunSeccompJSONNoArchAndArchMap(c *check.C) {
@ -1526,7 +1526,7 @@ func (s *DockerDaemonSuite) TestRunSeccompJSONNoArchAndArchMap(c *check.C) {
out, err := s.d.Cmd("run", "--security-opt", "seccomp="+tmpFile.Name(), "busybox", "chmod", "777", ".")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "'architectures' and 'archMap' were specified in the seccomp profile, use either 'architectures' or 'archMap'")
assert.Assert(c, out, checker.Contains, "'architectures' and 'archMap' were specified in the seccomp profile, use either 'architectures' or 'archMap'")
}
func (s *DockerDaemonSuite) TestRunWithDaemonDefaultSeccompProfile(c *check.C) {
@ -1562,7 +1562,7 @@ func (s *DockerDaemonSuite) TestRunWithDaemonDefaultSeccompProfile(c *check.C) {
out, err := s.d.Cmd("run", "busybox", "chmod", "777", ".")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Operation not permitted")
assert.Assert(c, out, checker.Contains, "Operation not permitted")
}
func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
@ -1577,7 +1577,7 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
assert.NilError(c, err)
inspect, err := clt.ContainerInspect(context.Background(), "test")
assert.NilError(c, err)
c.Assert(inspect.HostConfig.NanoCPUs, checker.Equals, int64(500000000))
assert.Assert(c, inspect.HostConfig.NanoCPUs, checker.Equals, int64(500000000))
out = inspectField(c, "test", "HostConfig.CpuQuota")
assert.Equal(c, out, "0", "CPU CFS quota should be 0")
@ -1586,5 +1586,5 @@ func (s *DockerSuite) TestRunWithNanoCPUs(c *check.C) {
out, _, err = dockerCmdWithError("run", "--cpus", "0.5", "--cpu-quota", "50000", "--cpu-period", "100000", "busybox", "sh")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Conflicting options: Nano CPUs and CPU Period cannot both be set")
assert.Assert(c, out, checker.Contains, "Conflicting options: Nano CPUs and CPU Period cannot both be set")
}

View file

@ -129,21 +129,21 @@ func (s *DockerSuite) TestSaveImageId(c *check.C) {
cleanedShortImageID := strings.TrimSpace(out)
// Make sure IDs are not empty
c.Assert(cleanedLongImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty."))
c.Assert(cleanedShortImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty."))
assert.Assert(c, cleanedLongImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty."))
assert.Assert(c, cleanedShortImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty."))
saveCmd := exec.Command(dockerBinary, "save", cleanedShortImageID)
tarCmd := exec.Command("tar", "t")
var err error
tarCmd.Stdin, err = saveCmd.StdoutPipe()
c.Assert(err, checker.IsNil, check.Commentf("cannot set stdout pipe for tar: %v", err))
assert.Assert(c, err, checker.IsNil, check.Commentf("cannot set stdout pipe for tar: %v", err))
grepCmd := exec.Command("grep", cleanedLongImageID)
grepCmd.Stdin, err = tarCmd.StdoutPipe()
c.Assert(err, checker.IsNil, check.Commentf("cannot set stdout pipe for grep: %v", err))
assert.Assert(c, err, checker.IsNil, check.Commentf("cannot set stdout pipe for grep: %v", err))
c.Assert(tarCmd.Start(), checker.IsNil, check.Commentf("tar failed with error: %v", err))
c.Assert(saveCmd.Start(), checker.IsNil, check.Commentf("docker save failed with error: %v", err))
assert.Assert(c, tarCmd.Start(), checker.IsNil, check.Commentf("tar failed with error: %v", err))
assert.Assert(c, saveCmd.Start(), checker.IsNil, check.Commentf("docker save failed with error: %v", err))
defer func() {
saveCmd.Wait()
tarCmd.Wait()
@ -152,7 +152,7 @@ func (s *DockerSuite) TestSaveImageId(c *check.C) {
out, _, err = runCommandWithOutput(grepCmd)
c.Assert(err, checker.IsNil, check.Commentf("failed to save repo with image ID: %s, %v", out, err))
assert.Assert(c, err, checker.IsNil, check.Commentf("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 *check.C) {
name := "save-directory-permissions"
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary directory: %s", err))
assert.Assert(c, err, checker.IsNil, check.Commentf("failed to create temporary directory: %s", err))
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
os.Mkdir(extractionDirectory, 0777)
@ -393,9 +393,9 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
assert.NilError(c, err, "failed to save and load repo: %s, %v", out, err)
// Should not show 'name' but should show the image ID during the load
c.Assert(out, checker.Not(checker.Contains), "Loaded image: ")
c.Assert(out, checker.Contains, "Loaded image ID:")
c.Assert(out, checker.Contains, id)
assert.Assert(c, out, checker.Not(checker.Contains), "Loaded image: ")
assert.Assert(c, out, checker.Contains, "Loaded image ID:")
assert.Assert(c, out, checker.Contains, id)
// Test to make sure that save by name shows that name during load
out, err = RunCommandPipelineWithOutput(
@ -403,6 +403,6 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
exec.Command(dockerBinary, "load"))
assert.NilError(c, err, "failed to save and load repo: %s, %v", out, err)
c.Assert(out, checker.Contains, "Loaded image: "+name+":latest")
c.Assert(out, checker.Not(checker.Contains), "Loaded image ID:")
assert.Assert(c, out, checker.Contains, "Loaded image: "+name+":latest")
assert.Assert(c, out, checker.Not(checker.Contains), "Loaded image ID:")
}

View file

@ -41,27 +41,27 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *check.C) {
assert.NilError(c, err, out)
var mountConfig []mount.Mount
c.Assert(json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
c.Assert(mountConfig, checker.HasLen, 1)
assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
assert.Assert(c, mountConfig, checker.HasLen, 1)
c.Assert(mountConfig[0].Source, checker.Equals, "foo")
c.Assert(mountConfig[0].Target, checker.Equals, "/foo")
c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeVolume)
c.Assert(mountConfig[0].VolumeOptions, checker.NotNil)
c.Assert(mountConfig[0].VolumeOptions.NoCopy, checker.True)
assert.Assert(c, mountConfig[0].Source, checker.Equals, "foo")
assert.Assert(c, mountConfig[0].Target, checker.Equals, "/foo")
assert.Assert(c, mountConfig[0].Type, checker.Equals, mount.TypeVolume)
assert.Assert(c, mountConfig[0].VolumeOptions, checker.NotNil)
assert.Assert(c, mountConfig[0].VolumeOptions.NoCopy, checker.True)
// check container mounts actual
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
assert.NilError(c, err, out)
var mounts []types.MountPoint
c.Assert(json.Unmarshal([]byte(out), &mounts), checker.IsNil)
c.Assert(mounts, checker.HasLen, 1)
assert.Assert(c, json.Unmarshal([]byte(out), &mounts), checker.IsNil)
assert.Assert(c, mounts, checker.HasLen, 1)
c.Assert(mounts[0].Type, checker.Equals, mount.TypeVolume)
c.Assert(mounts[0].Name, checker.Equals, "foo")
c.Assert(mounts[0].Destination, checker.Equals, "/foo")
c.Assert(mounts[0].RW, checker.Equals, true)
assert.Assert(c, mounts[0].Type, checker.Equals, mount.TypeVolume)
assert.Assert(c, mounts[0].Name, checker.Equals, "foo")
assert.Assert(c, mounts[0].Destination, checker.Equals, "/foo")
assert.Assert(c, mounts[0].RW, checker.Equals, true)
}
func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *check.C) {
@ -75,7 +75,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *check.C) {
},
Data: []byte("TESTINGDATA"),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--secret", testName, "busybox", "top")
assert.NilError(c, err, out)
@ -84,14 +84,14 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *check.C) {
assert.NilError(c, err)
var refs []swarm.SecretReference
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Equal(c, len(refs), 1)
c.Assert(refs[0].SecretName, checker.Equals, testName)
c.Assert(refs[0].File, checker.Not(checker.IsNil))
c.Assert(refs[0].File.Name, checker.Equals, testName)
c.Assert(refs[0].File.UID, checker.Equals, "0")
c.Assert(refs[0].File.GID, checker.Equals, "0")
assert.Assert(c, refs[0].SecretName, checker.Equals, testName)
assert.Assert(c, refs[0].File, checker.Not(checker.IsNil))
assert.Assert(c, refs[0].File.Name, checker.Equals, testName)
assert.Assert(c, refs[0].File.UID, checker.Equals, "0")
assert.Assert(c, refs[0].File.GID, checker.Equals, "0")
out, err = d.Cmd("service", "rm", serviceName)
assert.NilError(c, err, out)
@ -117,7 +117,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check
},
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
secretFlags = append(secretFlags, "--secret", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
}
@ -133,7 +133,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *check
assert.NilError(c, err)
var refs []swarm.SecretReference
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Equal(c, len(refs), len(testPaths))
var tasks []swarm.Task
@ -173,7 +173,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C
},
Data: []byte("TESTINGDATA"),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("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")
@ -183,7 +183,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *check.C
assert.NilError(c, err)
var refs []swarm.SecretReference
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Equal(c, len(refs), 2)
var tasks []swarm.Task
@ -223,7 +223,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *check.C) {
},
Data: []byte("TESTINGDATA"),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
out, err := d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", serviceName, "--config", testName, "busybox", "top")
assert.NilError(c, err, out)
@ -232,14 +232,14 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *check.C) {
assert.NilError(c, err)
var refs []swarm.ConfigReference
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Equal(c, len(refs), 1)
c.Assert(refs[0].ConfigName, checker.Equals, testName)
c.Assert(refs[0].File, checker.Not(checker.IsNil))
c.Assert(refs[0].File.Name, checker.Equals, testName)
c.Assert(refs[0].File.UID, checker.Equals, "0")
c.Assert(refs[0].File.GID, checker.Equals, "0")
assert.Assert(c, refs[0].ConfigName, checker.Equals, testName)
assert.Assert(c, refs[0].File, checker.Not(checker.IsNil))
assert.Assert(c, refs[0].File.Name, checker.Equals, testName)
assert.Assert(c, refs[0].File.UID, checker.Equals, "0")
assert.Assert(c, refs[0].File.GID, checker.Equals, "0")
out, err = d.Cmd("service", "rm", serviceName)
assert.NilError(c, err, out)
@ -264,7 +264,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check
},
Data: []byte("TESTINGDATA " + testName + " " + testTarget),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
configFlags = append(configFlags, "--config", fmt.Sprintf("source=%s,target=%s", testName, testTarget))
}
@ -280,7 +280,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *check
assert.NilError(c, err)
var refs []swarm.ConfigReference
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Equal(c, len(refs), len(testPaths))
var tasks []swarm.Task
@ -320,7 +320,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C
},
Data: []byte("TESTINGDATA"),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("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")
@ -330,7 +330,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *check.C
assert.NilError(c, err)
var refs []swarm.ConfigReference
c.Assert(json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Assert(c, json.Unmarshal([]byte(out), &refs), checker.IsNil)
assert.Equal(c, len(refs), 2)
var tasks []swarm.Task
@ -384,27 +384,27 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *check.C) {
assert.NilError(c, err, out)
var mountConfig []mount.Mount
c.Assert(json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
c.Assert(mountConfig, checker.HasLen, 1)
assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
assert.Assert(c, mountConfig, checker.HasLen, 1)
c.Assert(mountConfig[0].Source, checker.Equals, "")
c.Assert(mountConfig[0].Target, checker.Equals, "/foo")
c.Assert(mountConfig[0].Type, checker.Equals, mount.TypeTmpfs)
c.Assert(mountConfig[0].TmpfsOptions, checker.NotNil)
c.Assert(mountConfig[0].TmpfsOptions.SizeBytes, checker.Equals, int64(1048576))
assert.Assert(c, mountConfig[0].Source, checker.Equals, "")
assert.Assert(c, mountConfig[0].Target, checker.Equals, "/foo")
assert.Assert(c, mountConfig[0].Type, checker.Equals, mount.TypeTmpfs)
assert.Assert(c, mountConfig[0].TmpfsOptions, checker.NotNil)
assert.Assert(c, mountConfig[0].TmpfsOptions.SizeBytes, checker.Equals, int64(1048576))
// check container mounts actual
out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
assert.NilError(c, err, out)
var mounts []types.MountPoint
c.Assert(json.Unmarshal([]byte(out), &mounts), checker.IsNil)
c.Assert(mounts, checker.HasLen, 1)
assert.Assert(c, json.Unmarshal([]byte(out), &mounts), checker.IsNil)
assert.Assert(c, mounts, checker.HasLen, 1)
c.Assert(mounts[0].Type, checker.Equals, mount.TypeTmpfs)
c.Assert(mounts[0].Name, checker.Equals, "")
c.Assert(mounts[0].Destination, checker.Equals, "/foo")
c.Assert(mounts[0].RW, checker.Equals, true)
assert.Assert(c, mounts[0].Type, checker.Equals, mount.TypeTmpfs)
assert.Assert(c, mounts[0].Name, checker.Equals, "")
assert.Assert(c, mounts[0].Destination, checker.Equals, "/foo")
assert.Assert(c, mounts[0].RW, checker.Equals, true)
out, err = s.nodeCmd(c, task.NodeID, "logs", task.Status.ContainerStatus.ContainerID)
assert.NilError(c, err, out)
@ -441,8 +441,8 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *check.C) {
// Make sure the only alias seen is the container-id
var aliases []string
c.Assert(json.Unmarshal([]byte(out), &aliases), checker.IsNil)
c.Assert(aliases, checker.HasLen, 1)
assert.Assert(c, json.Unmarshal([]byte(out), &aliases), checker.IsNil)
assert.Assert(c, aliases, checker.HasLen, 1)
c.Assert(task.Status.ContainerStatus.ContainerID, checker.Contains, aliases[0])
assert.Assert(c, task.Status.ContainerStatus.ContainerID, checker.Contains, aliases[0])
}

View file

@ -124,7 +124,7 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *check.C) {
// task should be blocked at starting status
task = d.GetTask(c, task.ID)
c.Assert(task.Status.State, check.Equals, swarm.TaskStateStarting)
assert.Assert(c, task.Status.State, check.Equals, swarm.TaskStateStarting)
// make it healthy
d.Cmd("exec", containerID, "touch", "/status")

View file

@ -21,7 +21,7 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
// 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
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
ch := make(chan error)
go func() {
@ -64,7 +64,7 @@ func (s *DockerSuite) TestStartAttachSilent(c *check.C) {
startOut, _ := dockerCmd(c, "start", "-a", name)
// start -a produced unexpected output
c.Assert(startOut, checker.Equals, "test\n")
assert.Assert(c, startOut, checker.Equals, "test\n")
}
func (s *DockerSuite) TestStartRecordError(c *check.C) {
@ -74,22 +74,22 @@ func (s *DockerSuite) TestStartRecordError(c *check.C) {
dockerCmd(c, "run", "-d", "-p", "9999:9999", "--name", "test", "busybox", "top")
stateErr := inspectField(c, "test", "State.Error")
// Expected to not have state error
c.Assert(stateErr, checker.Equals, "")
assert.Assert(c, stateErr, checker.Equals, "")
// 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
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
stateErr = inspectField(c, "test2", "State.Error")
c.Assert(stateErr, checker.Contains, "port is already allocated")
assert.Assert(c, stateErr, checker.Contains, "port is already allocated")
// Expect the conflict to be resolved when we stop the initial container
dockerCmd(c, "stop", "test")
dockerCmd(c, "start", "test2")
stateErr = inspectField(c, "test2", "State.Error")
// Expected to not have state error but got one
c.Assert(stateErr, checker.Equals, "")
assert.Assert(c, stateErr, checker.Equals, "")
}
func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
@ -102,9 +102,9 @@ func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
out, _, err := dockerCmdWithError("start", "testing")
// an error should have been shown that you cannot start paused container
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
// an error should have been shown that you cannot start paused container
c.Assert(strings.ToLower(out), checker.Contains, "cannot start a paused container, try unpause instead")
assert.Assert(c, strings.ToLower(out), checker.Contains, "cannot start a paused container, try unpause instead")
}
func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
@ -130,7 +130,7 @@ func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
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
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("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)
@ -158,9 +158,9 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) {
for _, option := range []string{"-a", "-i", "-ai"} {
out, _, err := dockerCmdWithError("start", option, "test1", "test2", "test3")
// err shouldn't be nil because start will fail
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
assert.Assert(c, err, checker.NotNil, check.Commentf("out: %s", out))
// output does not correspond to what was expected
c.Assert(out, checker.Contains, "you cannot start and attach multiple containers at once")
assert.Assert(c, out, checker.Contains, "you cannot start and attach multiple containers at once")
}
// confirm the state of all the containers be stopped
@ -184,7 +184,7 @@ func (s *DockerSuite) TestStartAttachWithRename(c *check.C) {
result := cli.Docker(cli.Args("start", "-a", "before")).Assert(c, icmd.Expected{
ExitCode: 137,
})
c.Assert(result.Stderr(), checker.Not(checker.Contains), "No such container")
assert.Assert(c, result.Stderr(), checker.Not(checker.Contains), "No such container")
}
func (s *DockerSuite) TestStartReturnCorrectExitCode(c *check.C) {
@ -193,9 +193,9 @@ func (s *DockerSuite) TestStartReturnCorrectExitCode(c *check.C) {
out, exitCode, err := dockerCmdWithError("start", "-a", "withRestart")
assert.ErrorContains(c, err, "")
c.Assert(exitCode, checker.Equals, 11, check.Commentf("out: %s", out))
assert.Assert(c, exitCode, checker.Equals, 11, check.Commentf("out: %s", out))
out, exitCode, err = dockerCmdWithError("start", "-a", "withRm")
assert.ErrorContains(c, err, "")
c.Assert(exitCode, checker.Equals, 12, check.Commentf("out: %s", out))
assert.Assert(c, exitCode, checker.Equals, 12, check.Commentf("out: %s", out))
}

View file

@ -46,15 +46,15 @@ func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) {
assert.NilError(c, err, out)
spec := getSpec()
c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, 11*time.Second)
assert.Assert(c, spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
assert.Assert(c, spec.Dispatcher.HeartbeatPeriod, checker.Equals, 11*time.Second)
// setting anything under 30m for cert-expiry is not allowed
out, err = d.Cmd("swarm", "update", "--cert-expiry", "15m")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "minimum certificate expiry time")
assert.Assert(c, out, checker.Contains, "minimum certificate expiry time")
spec = getSpec()
c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
assert.Assert(c, spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
// passing an external CA (this is without starting a root rotation) does not fail
cli.Docker(cli.Args("swarm", "update", "--external-ca", "protocol=cfssl,url=https://something.org",
@ -65,9 +65,9 @@ func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) {
assert.NilError(c, err)
spec = getSpec()
c.Assert(spec.CAConfig.ExternalCAs, checker.HasLen, 2)
c.Assert(spec.CAConfig.ExternalCAs[0].CACert, checker.Equals, "")
c.Assert(spec.CAConfig.ExternalCAs[1].CACert, checker.Equals, string(expected))
assert.Assert(c, spec.CAConfig.ExternalCAs, checker.HasLen, 2)
assert.Assert(c, spec.CAConfig.ExternalCAs[0].CACert, checker.Equals, "")
assert.Assert(c, spec.CAConfig.ExternalCAs[1].CACert, checker.Equals, string(expected))
// passing an invalid external CA fails
tempFile := fs.NewFile(c, "testfile", fs.WithContent("fakecert"))
@ -111,18 +111,18 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) {
assert.NilError(c, err)
spec := getSpec()
c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, 11*time.Second)
c.Assert(spec.CAConfig.ExternalCAs, checker.HasLen, 2)
c.Assert(spec.CAConfig.ExternalCAs[0].CACert, checker.Equals, "")
c.Assert(spec.CAConfig.ExternalCAs[1].CACert, checker.Equals, string(expected))
assert.Assert(c, spec.CAConfig.NodeCertExpiry, checker.Equals, 30*time.Hour)
assert.Assert(c, spec.Dispatcher.HeartbeatPeriod, checker.Equals, 11*time.Second)
assert.Assert(c, spec.CAConfig.ExternalCAs, checker.HasLen, 2)
assert.Assert(c, spec.CAConfig.ExternalCAs[0].CACert, checker.Equals, "")
assert.Assert(c, spec.CAConfig.ExternalCAs[1].CACert, checker.Equals, string(expected))
c.Assert(d.SwarmLeave(c, true), checker.IsNil)
assert.Assert(c, d.SwarmLeave(c, true), checker.IsNil)
cli.Docker(cli.Args("swarm", "init"), cli.Daemon(d)).Assert(c, icmd.Success)
spec = getSpec()
c.Assert(spec.CAConfig.NodeCertExpiry, checker.Equals, 90*24*time.Hour)
c.Assert(spec.Dispatcher.HeartbeatPeriod, checker.Equals, 5*time.Second)
assert.Assert(c, spec.CAConfig.NodeCertExpiry, checker.Equals, 90*24*time.Hour)
assert.Assert(c, spec.Dispatcher.HeartbeatPeriod, checker.Equals, 5*time.Second)
}
func (s *DockerSwarmSuite) TestSwarmInitIPv6(c *check.C) {
@ -134,14 +134,14 @@ func (s *DockerSwarmSuite) TestSwarmInitIPv6(c *check.C) {
cli.Docker(cli.Args("swarm", "join", "::1"), cli.Daemon(d2)).Assert(c, icmd.Success)
out := cli.Docker(cli.Args("info"), cli.Daemon(d2)).Assert(c, icmd.Success).Combined()
c.Assert(out, checker.Contains, "Swarm: active")
assert.Assert(c, out, checker.Contains, "Swarm: active")
}
func (s *DockerSwarmSuite) TestSwarmInitUnspecifiedAdvertiseAddr(c *check.C) {
d := s.AddDaemon(c, false, false)
out, err := d.Cmd("swarm", "init", "--advertise-addr", "0.0.0.0")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "advertise address must be a non-zero IP address")
assert.Assert(c, out, checker.Contains, "advertise address must be a non-zero IP address")
}
func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *check.C) {
@ -156,14 +156,14 @@ func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *check.C) {
assert.ErrorContains(c, err, "")
content, err := d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, "--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
assert.Assert(c, string(content), checker.Contains, "--cluster-store and --cluster-advertise daemon configurations are incompatible with swarm mode")
// start a daemon with --live-restore
err = d.StartWithError("--live-restore")
assert.ErrorContains(c, err, "")
content, err = d.ReadLogFile()
assert.NilError(c, err)
c.Assert(string(content), checker.Contains, "--live-restore daemon configuration is incompatible with swarm mode")
assert.Assert(c, string(content), checker.Contains, "--live-restore daemon configuration is incompatible with swarm mode")
// restart for teardown
d.StartNode(c)
}
@ -171,7 +171,7 @@ func (s *DockerSwarmSuite) TestSwarmIncompatibleDaemon(c *check.C) {
func (s *DockerSwarmSuite) TestSwarmServiceTemplatingHostname(c *check.C) {
d := s.AddDaemon(c, true, true)
hostname, err := d.Cmd("node", "inspect", "--format", "{{.Description.Hostname}}", "self")
c.Assert(err, checker.IsNil, check.Commentf("%s", hostname))
assert.Assert(c, err, checker.IsNil, check.Commentf("%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)
@ -182,7 +182,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTemplatingHostname(c *check.C) {
containers := d.ActiveContainers(c)
out, err = d.Cmd("inspect", "--type", "container", "--format", "{{.Config.Hostname}}", containers[0])
assert.NilError(c, err, out)
c.Assert(strings.Split(out, "\n")[0], checker.Equals, "test-1-"+strings.Split(hostname, "\n")[0], check.Commentf("hostname with templating invalid"))
assert.Assert(c, strings.Split(out, "\n")[0], checker.Equals, "test-1-"+strings.Split(hostname, "\n")[0], check.Commentf("hostname with templating invalid"))
}
// Test case for #24270
@ -210,21 +210,21 @@ func (s *DockerSwarmSuite) TestSwarmServiceListFilter(c *check.C) {
// We search checker.Contains with `name+" "` to prevent prefix only.
out, err = d.Cmd("service", "ls", "--filter", filter1)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name1+" ")
c.Assert(out, checker.Not(checker.Contains), name2+" ")
c.Assert(out, checker.Not(checker.Contains), name3+" ")
assert.Assert(c, out, checker.Contains, name1+" ")
assert.Assert(c, out, checker.Not(checker.Contains), name2+" ")
assert.Assert(c, out, checker.Not(checker.Contains), name3+" ")
out, err = d.Cmd("service", "ls", "--filter", filter2)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name1+" ")
c.Assert(out, checker.Contains, name2+" ")
c.Assert(out, checker.Not(checker.Contains), name3+" ")
assert.Assert(c, out, checker.Contains, name1+" ")
assert.Assert(c, out, checker.Contains, name2+" ")
assert.Assert(c, out, checker.Not(checker.Contains), name3+" ")
out, err = d.Cmd("service", "ls")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name1+" ")
c.Assert(out, checker.Contains, name2+" ")
c.Assert(out, checker.Contains, name3+" ")
assert.Assert(c, out, checker.Contains, name1+" ")
assert.Assert(c, out, checker.Contains, name2+" ")
assert.Assert(c, out, checker.Contains, name3+" ")
}
func (s *DockerSwarmSuite) TestSwarmNodeListFilter(c *check.C) {
@ -239,11 +239,11 @@ func (s *DockerSwarmSuite) TestSwarmNodeListFilter(c *check.C) {
out, err = d.Cmd("node", "ls", "--filter", filter)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
out, err = d.Cmd("node", "ls", "--filter", "name=none")
assert.NilError(c, err, out)
c.Assert(out, checker.Not(checker.Contains), name)
assert.Assert(c, out, checker.Not(checker.Contains), name)
}
func (s *DockerSwarmSuite) TestSwarmNodeTaskListFilter(c *check.C) {
@ -261,15 +261,15 @@ func (s *DockerSwarmSuite) TestSwarmNodeTaskListFilter(c *check.C) {
out, err = d.Cmd("node", "ps", "--filter", filter, "self")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name+".1")
c.Assert(out, checker.Contains, name+".2")
c.Assert(out, checker.Contains, name+".3")
assert.Assert(c, out, checker.Contains, name+".1")
assert.Assert(c, out, checker.Contains, name+".2")
assert.Assert(c, out, checker.Contains, name+".3")
out, err = d.Cmd("node", "ps", "--filter", "name=none", "self")
assert.NilError(c, err, out)
c.Assert(out, checker.Not(checker.Contains), name+".1")
c.Assert(out, checker.Not(checker.Contains), name+".2")
c.Assert(out, checker.Not(checker.Contains), name+".3")
assert.Assert(c, out, checker.Not(checker.Contains), name+".1")
assert.Assert(c, out, checker.Not(checker.Contains), name+".2")
assert.Assert(c, out, checker.Not(checker.Contains), name+".3")
}
// Test case for #25375
@ -431,7 +431,7 @@ func (s *DockerSwarmSuite) TestOverlayAttachableOnSwarmLeave(c *check.C) {
assert.NilError(c, err, out)
// Leave the swarm
c.Assert(d.SwarmLeave(c, true), checker.IsNil)
assert.Assert(c, d.SwarmLeave(c, true), checker.IsNil)
// Check the container is disconnected
out, err = d.Cmd("inspect", "c1", "--format", "{{.NetworkSettings.Networks."+nwName+"}}")
@ -441,7 +441,7 @@ func (s *DockerSwarmSuite) TestOverlayAttachableOnSwarmLeave(c *check.C) {
// Check the network is gone
out, err = d.Cmd("network", "ls", "--format", "{{.Name}}")
assert.NilError(c, err, out)
c.Assert(out, checker.Not(checker.Contains), nwName)
assert.Assert(c, out, checker.Not(checker.Contains), nwName)
}
func (s *DockerSwarmSuite) TestOverlayAttachableReleaseResourcesOnFailure(c *check.C) {
@ -488,7 +488,7 @@ func (s *DockerSwarmSuite) TestSwarmIngressNetwork(c *check.C) {
// But only one is allowed
out, err = d.Cmd("network", "create", "-d", "overlay", "--ingress", "another-ingress")
assert.ErrorContains(c, err, "")
c.Assert(strings.TrimSpace(out), checker.Contains, "is already present")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "is already present")
// It cannot be removed if it is being used
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "srv1", "-p", "9000:8000", "busybox", "top")
@ -510,12 +510,12 @@ func (s *DockerSwarmSuite) TestSwarmIngressNetwork(c *check.C) {
// A service which needs the ingress network cannot be created if no ingress is present
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "srv2", "-p", "500:500", "busybox", "top")
assert.ErrorContains(c, err, "")
c.Assert(strings.TrimSpace(out), checker.Contains, "no ingress network is present")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "no ingress network is present")
// An existing service cannot be updated to use the ingress nw if the nw is not present
out, err = d.Cmd("service", "update", "--detach", "--publish-add", "9000:8000", "srv1")
assert.ErrorContains(c, err, "")
c.Assert(strings.TrimSpace(out), checker.Contains, "no ingress network is present")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "no ingress network is present")
// But services which do not need routing mesh can be created regardless
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", "srv3", "--endpoint-mode", "dnsrr", "busybox", "top")
@ -562,21 +562,21 @@ func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *check.C) {
out, err = d.Cmd("service", "ps", "--filter", filter, name)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name+".1")
c.Assert(out, checker.Contains, name+".2")
c.Assert(out, checker.Contains, name+".3")
assert.Assert(c, out, checker.Contains, name+".1")
assert.Assert(c, out, checker.Contains, name+".2")
assert.Assert(c, out, checker.Contains, name+".3")
out, err = d.Cmd("service", "ps", "--filter", "name="+name+".1", name)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name+".1")
c.Assert(out, checker.Not(checker.Contains), name+".2")
c.Assert(out, checker.Not(checker.Contains), name+".3")
assert.Assert(c, out, checker.Contains, name+".1")
assert.Assert(c, out, checker.Not(checker.Contains), name+".2")
assert.Assert(c, out, checker.Not(checker.Contains), name+".3")
out, err = d.Cmd("service", "ps", "--filter", "name=none", name)
assert.NilError(c, err, out)
c.Assert(out, checker.Not(checker.Contains), name+".1")
c.Assert(out, checker.Not(checker.Contains), name+".2")
c.Assert(out, checker.Not(checker.Contains), name+".3")
assert.Assert(c, out, checker.Not(checker.Contains), name+".1")
assert.Assert(c, out, checker.Not(checker.Contains), name+".2")
assert.Assert(c, out, checker.Not(checker.Contains), name+".3")
name = "redis-cluster-sha1"
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--name", name, "--mode=global", "busybox", "top")
@ -588,15 +588,15 @@ func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *check.C) {
filter = "name=redis-cluster"
out, err = d.Cmd("service", "ps", "--filter", filter, name)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
out, err = d.Cmd("service", "ps", "--filter", "name="+name, name)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
out, err = d.Cmd("service", "ps", "--filter", "name=none", name)
assert.NilError(c, err, out)
c.Assert(out, checker.Not(checker.Contains), name)
assert.Assert(c, out, checker.Not(checker.Contains), name)
}
func (s *DockerSwarmSuite) TestPsListContainersFilterIsTask(c *check.C) {
@ -619,14 +619,14 @@ func (s *DockerSwarmSuite) TestPsListContainersFilterIsTask(c *check.C) {
out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=false")
assert.NilError(c, err, out)
psOut := strings.TrimSpace(out)
c.Assert(psOut, checker.Equals, bareID, check.Commentf("Expected id %s, got %s for is-task label, output %q", bareID, psOut, out))
assert.Assert(c, psOut, checker.Equals, bareID, check.Commentf("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)
c.Assert(lines[0], checker.Not(checker.Equals), bareID, check.Commentf("Expected not %s, but got it for is-task label, output %q", bareID, out))
assert.Assert(c, lines[0], checker.Not(checker.Equals), bareID, check.Commentf("Expected not %s, but got it for is-task label, output %q", bareID, out))
}
const globalNetworkPlugin = "global-network-plugin"
@ -803,7 +803,7 @@ func setupRemoteGlobalNetworkPlugin(c *check.C, mux *http.ServeMux, url, netDrv,
func (s *DockerSwarmSuite) TestSwarmNetworkPlugin(c *check.C) {
mux := http.NewServeMux()
s.server = httptest.NewServer(mux)
c.Assert(s.server, check.NotNil) // check that HTTP server has started
assert.Assert(c, s.server, check.NotNil) // check that HTTP server has started
setupRemoteGlobalNetworkPlugin(c, mux, s.server.URL, globalNetworkPlugin, globalIPAMPlugin)
defer func() {
s.server.Close()
@ -815,7 +815,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkPlugin(c *check.C) {
out, err := d.Cmd("network", "create", "-d", globalNetworkPlugin, "foo")
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "not supported in swarm mode")
assert.Assert(c, out, checker.Contains, "not supported in swarm mode")
}
// Test case for #24712
@ -834,7 +834,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceEnvFile(c *check.C) {
// The complete env is [VAR1=A VAR2=A VAR1=B VAR1=C VAR2= VAR2] and duplicates will be removed => [VAR1=C VAR2]
out, err = d.Cmd("inspect", "--format", "{{ .Spec.TaskTemplate.ContainerSpec.Env }}", name)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, "[VAR1=C VAR2]")
assert.Assert(c, out, checker.Contains, "[VAR1=C VAR2]")
}
func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *check.C) {
@ -859,7 +859,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *check.C) {
out, err = d.Cmd("exec", id, "cat", "/status")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
// Remove service
out, err = d.Cmd("service", "rm", name)
@ -882,7 +882,7 @@ func (s *DockerSwarmSuite) TestSwarmServiceTTY(c *check.C) {
out, err = d.Cmd("exec", id, "cat", "/status")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
}
func (s *DockerSwarmSuite) TestSwarmServiceTTYUpdate(c *check.C) {
@ -969,9 +969,9 @@ func (s *DockerSwarmSuite) TestDNSConfig(c *check.C) {
expectedOutput3 := "options timeout:3"
out, err = d.Cmd("exec", id, "cat", "/etc/resolv.conf")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, expectedOutput1, check.Commentf("Expected '%s', but got %q", expectedOutput1, out))
c.Assert(out, checker.Contains, expectedOutput2, check.Commentf("Expected '%s', but got %q", expectedOutput2, out))
c.Assert(out, checker.Contains, expectedOutput3, check.Commentf("Expected '%s', but got %q", expectedOutput3, out))
assert.Assert(c, out, checker.Contains, expectedOutput1, check.Commentf("Expected '%s', but got %q", expectedOutput1, out))
assert.Assert(c, out, checker.Contains, expectedOutput2, check.Commentf("Expected '%s', but got %q", expectedOutput2, out))
assert.Assert(c, out, checker.Contains, expectedOutput3, check.Commentf("Expected '%s', but got %q", expectedOutput3, out))
}
func (s *DockerSwarmSuite) TestDNSConfigUpdate(c *check.C) {
@ -1039,8 +1039,8 @@ func (s *DockerSwarmSuite) TestUnlockEngineAndUnlockedSwarm(c *check.C) {
result.Assert(c, icmd.Expected{
ExitCode: 1,
})
c.Assert(result.Combined(), checker.Contains, "Error: This node is not part of a swarm")
c.Assert(result.Combined(), checker.Not(checker.Contains), "Please enter unlock key")
assert.Assert(c, result.Combined(), checker.Contains, "Error: This node is not part of a swarm")
assert.Assert(c, result.Combined(), checker.Not(checker.Contains), "Please enter unlock key")
out, err := d.Cmd("swarm", "init")
assert.NilError(c, err, out)
@ -1051,22 +1051,22 @@ func (s *DockerSwarmSuite) TestUnlockEngineAndUnlockedSwarm(c *check.C) {
result.Assert(c, icmd.Expected{
ExitCode: 1,
})
c.Assert(result.Combined(), checker.Contains, "Error: swarm is not locked")
c.Assert(result.Combined(), checker.Not(checker.Contains), "Please enter unlock key")
assert.Assert(c, result.Combined(), checker.Contains, "Error: swarm is not locked")
assert.Assert(c, result.Combined(), checker.Not(checker.Contains), "Please enter unlock key")
}
func (s *DockerSwarmSuite) TestSwarmInitLocked(c *check.C) {
d := s.AddDaemon(c, false, false)
outs, err := d.Cmd("swarm", "init", "--autolock")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
unlockKey := getUnlockKey(d, c, outs)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
// It starts off locked
d.RestartNode(c)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked)
cmd := d.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString("wrong-secret-key")
@ -1075,33 +1075,33 @@ func (s *DockerSwarmSuite) TestSwarmInitLocked(c *check.C) {
Err: "invalid key",
})
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked)
cmd = d.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString(unlockKey)
icmd.RunCmd(cmd).Assert(c, icmd.Success)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
outs, err = d.Cmd("node", "ls")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
outs, err = d.Cmd("swarm", "update", "--autolock=false")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
checkSwarmLockedToUnlocked(c, d)
outs, err = d.Cmd("node", "ls")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
}
func (s *DockerSwarmSuite) TestSwarmLeaveLocked(c *check.C) {
d := s.AddDaemon(c, false, false)
outs, err := d.Cmd("swarm", "init", "--autolock")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
// It starts off locked
d.RestartNode(c)
@ -1110,21 +1110,21 @@ func (s *DockerSwarmSuite) TestSwarmLeaveLocked(c *check.C) {
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateLocked)
outs, _ = d.Cmd("node", "ls")
c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
// `docker swarm leave` a locked swarm without --force will return an error
outs, _ = d.Cmd("swarm", "leave")
c.Assert(outs, checker.Contains, "Swarm is encrypted and locked.")
assert.Assert(c, outs, checker.Contains, "Swarm is encrypted and locked.")
// It is OK for user to leave a locked swarm with --force
outs, err = d.Cmd("swarm", "leave", "--force")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
info = d.SwarmInfo(c)
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateInactive)
outs, err = d.Cmd("swarm", "init")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
info = d.SwarmInfo(c)
assert.Equal(c, info.LocalNodeState, swarm.LocalNodeStateActive)
@ -1137,14 +1137,14 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *check.C) {
// they start off unlocked
d2.RestartNode(c)
c.Assert(getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateActive)
// stop this one so it does not get autolock info
d2.Stop(c)
// enable autolock
outs, err := d1.Cmd("swarm", "update", "--autolock")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
unlockKey := getUnlockKey(d1, c, outs)
// The ones that got the cluster update should be set to locked
@ -1154,19 +1154,19 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *check.C) {
cmd := d.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString(unlockKey)
icmd.RunCmd(cmd).Assert(c, icmd.Success)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
}
// d2 never got the cluster update, so it is still set to unlocked
d2.StartNode(c)
c.Assert(getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateActive)
// d2 is now set to lock
checkSwarmUnlockedToLocked(c, d2)
// leave it locked, and set the cluster to no longer autolock
outs, err = d1.Cmd("swarm", "update", "--autolock=false")
c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("out: %v", outs))
// the ones that got the update are now set to unlocked
for _, d := range []*daemon.Daemon{d1, d3} {
@ -1174,13 +1174,13 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *check.C) {
}
// d2 still locked
c.Assert(getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateLocked)
assert.Assert(c, getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateLocked)
// unlock it
cmd := d2.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString(unlockKey)
icmd.RunCmd(cmd).Assert(c, icmd.Success)
c.Assert(getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d2), checker.Equals, swarm.LocalNodeStateActive)
// once it's caught up, d2 is set to not be locked
checkSwarmLockedToUnlocked(c, d2)
@ -1188,7 +1188,7 @@ func (s *DockerSwarmSuite) TestSwarmLockUnlockCluster(c *check.C) {
// managers who join now are never set to locked in the first place
d4 := s.AddDaemon(c, true, true)
d4.RestartNode(c)
c.Assert(getNodeStatus(c, d4), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d4), checker.Equals, swarm.LocalNodeStateActive)
}
func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) {
@ -1196,7 +1196,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) {
// enable autolock
outs, err := d1.Cmd("swarm", "update", "--autolock")
c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("out: %v", outs))
unlockKey := getUnlockKey(d1, c, outs)
// joined workers start off unlocked
@ -1207,7 +1207,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) {
// promote worker
outs, err = d1.Cmd("node", "promote", d2.NodeID())
assert.NilError(c, err)
c.Assert(outs, checker.Contains, "promoted to a manager in the swarm")
assert.Assert(c, outs, checker.Contains, "promoted to a manager in the swarm")
// join new manager node
d3 := s.AddDaemon(c, true, true)
@ -1219,13 +1219,13 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *check.C) {
cmd := d.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString(unlockKey)
icmd.RunCmd(cmd).Assert(c, icmd.Success)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
}
// demote manager back to worker - workers are not locked
outs, err = d1.Cmd("node", "demote", d3.NodeID())
assert.NilError(c, err)
c.Assert(outs, checker.Contains, "demoted in the swarm")
assert.Assert(c, outs, checker.Contains, "demoted in the swarm")
// Wait for it to actually be demoted, for the key and cert to be replaced.
// Then restart and assert that the node is not locked. If we don't wait for the cert
@ -1254,23 +1254,23 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) {
d := s.AddDaemon(c, true, true)
outs, err := d.Cmd("swarm", "update", "--autolock")
c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("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")
c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("out: %v", outs))
// Strip \n
newUnlockKey := outs[:len(outs)-1]
c.Assert(newUnlockKey, checker.Not(checker.Equals), "")
c.Assert(newUnlockKey, checker.Not(checker.Equals), unlockKey)
assert.Assert(c, newUnlockKey, checker.Not(checker.Equals), "")
assert.Assert(c, newUnlockKey, checker.Not(checker.Equals), unlockKey)
d.RestartNode(c)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked)
outs, _ = d.Cmd("node", "ls")
c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
cmd := d.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString(unlockKey)
@ -1299,13 +1299,13 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) {
})
outs, _ = d.Cmd("node", "ls")
c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
cmd = d.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString(newUnlockKey)
icmd.RunCmd(cmd).Assert(c, icmd.Success)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
retry := 0
for {
@ -1319,7 +1319,7 @@ func (s *DockerSwarmSuite) TestSwarmRotateUnlockKey(c *check.C) {
}
}
assert.NilError(c, err)
c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
break
}
@ -1343,26 +1343,26 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *check.C) {
d3 := s.AddDaemon(c, true, true)
outs, err := d1.Cmd("swarm", "update", "--autolock")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("%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")
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
// Strip \n
newUnlockKey := outs[:len(outs)-1]
c.Assert(newUnlockKey, checker.Not(checker.Equals), "")
c.Assert(newUnlockKey, checker.Not(checker.Equals), unlockKey)
assert.Assert(c, newUnlockKey, checker.Not(checker.Equals), "")
assert.Assert(c, newUnlockKey, checker.Not(checker.Equals), unlockKey)
d2.RestartNode(c)
d3.RestartNode(c)
for _, d := range []*daemon.Daemon{d2, d3} {
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateLocked)
outs, _ := d.Cmd("node", "ls")
c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
cmd := d.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString(unlockKey)
@ -1391,13 +1391,13 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *check.C) {
})
outs, _ = d.Cmd("node", "ls")
c.Assert(outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, outs, checker.Contains, "Swarm is encrypted and needs to be unlocked")
cmd = d.Command("swarm", "unlock")
cmd.Stdin = bytes.NewBufferString(newUnlockKey)
icmd.RunCmd(cmd).Assert(c, icmd.Success)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
retry := 0
for {
@ -1410,8 +1410,8 @@ func (s *DockerSwarmSuite) TestSwarmClusterRotateUnlockKey(c *check.C) {
continue
}
}
c.Assert(err, checker.IsNil, check.Commentf("%s", outs))
c.Assert(outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", outs))
assert.Assert(c, outs, checker.Not(checker.Contains), "Swarm is encrypted and needs to be unlocked")
break
}
}
@ -1426,8 +1426,8 @@ func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *check.C) {
for i := 0; i < 2; i++ {
// set to lock
outs, err := d.Cmd("swarm", "update", "--autolock")
c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs))
c.Assert(outs, checker.Contains, "docker swarm unlock")
assert.Assert(c, err, checker.IsNil, check.Commentf("out: %v", outs))
assert.Assert(c, outs, checker.Contains, "docker swarm unlock")
unlockKey := getUnlockKey(d, c, outs)
checkSwarmUnlockedToLocked(c, d)
@ -1436,10 +1436,10 @@ func (s *DockerSwarmSuite) TestSwarmAlternateLockUnlock(c *check.C) {
cmd.Stdin = bytes.NewBufferString(unlockKey)
icmd.RunCmd(cmd).Assert(c, icmd.Success)
c.Assert(getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
assert.Assert(c, getNodeStatus(c, d), checker.Equals, swarm.LocalNodeStateActive)
outs, err = d.Cmd("swarm", "update", "--autolock=false")
c.Assert(err, checker.IsNil, check.Commentf("out: %v", outs))
assert.Assert(c, err, checker.IsNil, check.Commentf("out: %v", outs))
checkSwarmLockedToUnlocked(c, d)
}
@ -1465,7 +1465,7 @@ func (s *DockerSwarmSuite) TestExtraHosts(c *check.C) {
expectedOutput := "1.2.3.4\texample.com"
out, err = d.Cmd("exec", id, "cat", "/etc/hosts")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
assert.Assert(c, out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
}
func (s *DockerSwarmSuite) TestSwarmManagerAddress(c *check.C) {
@ -1498,8 +1498,8 @@ func (s *DockerSwarmSuite) TestSwarmNetworkIPAMOptions(c *check.C) {
out, err = d.Cmd("network", "inspect", "--format", "{{.IPAM.Options}}", "foo")
assert.NilError(c, err, out)
c.Assert(strings.TrimSpace(out), checker.Contains, "foo:bar")
c.Assert(strings.TrimSpace(out), checker.Contains, "com.docker.network.ipam.serial:true")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "foo:bar")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "com.docker.network.ipam.serial:true")
out, err = d.Cmd("service", "create", "--detach", "--no-resolve-image", "--network=foo", "--name", "top", "busybox", "top")
assert.NilError(c, err, out)
@ -1509,8 +1509,8 @@ func (s *DockerSwarmSuite) TestSwarmNetworkIPAMOptions(c *check.C) {
out, err = d.Cmd("network", "inspect", "--format", "{{.IPAM.Options}}", "foo")
assert.NilError(c, err, out)
c.Assert(strings.TrimSpace(out), checker.Contains, "foo:bar")
c.Assert(strings.TrimSpace(out), checker.Contains, "com.docker.network.ipam.serial:true")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "foo:bar")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "com.docker.network.ipam.serial:true")
}
// Test case for issue #27866, which did not allow NW name that is the prefix of a swarm NW ID.
@ -1520,7 +1520,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkCreateIssue27866(c *check.C) {
out, err := d.Cmd("network", "inspect", "-f", "{{.Id}}", "ingress")
assert.NilError(c, err, "out: %v", out)
ingressID := strings.TrimSpace(out)
c.Assert(ingressID, checker.Not(checker.Equals), "")
assert.Assert(c, ingressID, checker.Not(checker.Equals), "")
// create a network of which name is the prefix of the ID of an overlay network
// (ingressID in this case)
@ -1549,7 +1549,7 @@ func (s *DockerSwarmSuite) TestSwarmNetworkCreateDup(c *check.C) {
out, err := d.Cmd("network", "create", "--driver", driver1, nwName)
assert.NilError(c, err, "out: %v", out)
out, err = d.Cmd("network", "create", "--driver", driver2, nwName)
c.Assert(out, checker.Contains, fmt.Sprintf("network with name %s already exists", nwName))
assert.Assert(c, out, checker.Contains, fmt.Sprintf("network with name %s already exists", nwName))
assert.ErrorContains(c, err, "")
c.Logf("As expected, the attempt to network %q with %q failed: %s",
nwName, driver2, out)
@ -1573,9 +1573,9 @@ func (s *DockerSwarmSuite) TestSwarmPublishDuplicatePorts(c *check.C) {
// Dynamic ports are likely to be 30000 and 30001 but doesn't matter
out, err = d.Cmd("service", "inspect", "--format", "{{.Endpoint.Ports}} len={{len .Endpoint.Ports}}", id)
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, "len=4")
c.Assert(out, checker.Contains, "{ tcp 80 5005 ingress}")
c.Assert(out, checker.Contains, "{ tcp 80 5006 ingress}")
assert.Assert(c, out, checker.Contains, "len=4")
assert.Assert(c, out, checker.Contains, "{ tcp 80 5005 ingress}")
assert.Assert(c, out, checker.Contains, "{ tcp 80 5006 ingress}")
}
func (s *DockerSwarmSuite) TestSwarmJoinWithDrain(c *check.C) {
@ -1583,7 +1583,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinWithDrain(c *check.C) {
out, err := d.Cmd("node", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Not(checker.Contains), "Drain")
assert.Assert(c, out, checker.Not(checker.Contains), "Drain")
out, err = d.Cmd("swarm", "join-token", "-q", "manager")
assert.NilError(c, err)
@ -1599,11 +1599,11 @@ func (s *DockerSwarmSuite) TestSwarmJoinWithDrain(c *check.C) {
out, err = d.Cmd("node", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "Drain")
assert.Assert(c, out, checker.Contains, "Drain")
out, err = d1.Cmd("node", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "Drain")
assert.Assert(c, out, checker.Contains, "Drain")
}
func (s *DockerSwarmSuite) TestSwarmInitWithDrain(c *check.C) {
@ -1614,7 +1614,7 @@ func (s *DockerSwarmSuite) TestSwarmInitWithDrain(c *check.C) {
out, err = d.Cmd("node", "ls")
assert.NilError(c, err)
c.Assert(out, checker.Contains, "Drain")
assert.Assert(c, out, checker.Contains, "Drain")
}
func (s *DockerSwarmSuite) TestSwarmReadonlyRootfs(c *check.C) {
@ -1677,7 +1677,7 @@ func (s *DockerSwarmSuite) TestNetworkInspectWithDuplicateNames(c *check.C) {
// Name with duplicates
out, err = d.Cmd("network", "inspect", "--format", "{{.ID}}", name)
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "2 matches found based on name")
assert.Assert(c, out, checker.Contains, "2 matches found based on name")
out, err = d.Cmd("network", "rm", n2.ID)
assert.NilError(c, err, out)
@ -1700,7 +1700,7 @@ func (s *DockerSwarmSuite) TestNetworkInspectWithDuplicateNames(c *check.C) {
// Name with duplicates
out, err = d.Cmd("network", "inspect", "--format", "{{.ID}}", name)
assert.ErrorContains(c, err, "", out)
c.Assert(out, checker.Contains, "2 matches found based on name")
assert.Assert(c, out, checker.Contains, "2 matches found based on name")
}
func (s *DockerSwarmSuite) TestSwarmStopSignal(c *check.C) {
@ -1747,19 +1747,19 @@ func (s *DockerSwarmSuite) TestSwarmServiceLsFilterMode(c *check.C) {
out, err = d.Cmd("service", "ls")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, "top1")
c.Assert(out, checker.Contains, "top2")
c.Assert(out, checker.Not(checker.Contains), "localnet")
assert.Assert(c, out, checker.Contains, "top1")
assert.Assert(c, out, checker.Contains, "top2")
assert.Assert(c, out, checker.Not(checker.Contains), "localnet")
out, err = d.Cmd("service", "ls", "--filter", "mode=global")
c.Assert(out, checker.Not(checker.Contains), "top1")
c.Assert(out, checker.Contains, "top2")
assert.Assert(c, out, checker.Not(checker.Contains), "top1")
assert.Assert(c, out, checker.Contains, "top2")
assert.NilError(c, err, out)
out, err = d.Cmd("service", "ls", "--filter", "mode=replicated")
assert.NilError(c, err, out)
c.Assert(out, checker.Contains, "top1")
c.Assert(out, checker.Not(checker.Contains), "top2")
assert.Assert(c, out, checker.Contains, "top1")
assert.Assert(c, out, checker.Not(checker.Contains), "top2")
}
func (s *DockerSwarmSuite) TestSwarmInitUnspecifiedDataPathAddr(c *check.C) {
@ -1767,11 +1767,11 @@ func (s *DockerSwarmSuite) TestSwarmInitUnspecifiedDataPathAddr(c *check.C) {
out, err := d.Cmd("swarm", "init", "--data-path-addr", "0.0.0.0")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "data path address must be a non-zero IP")
assert.Assert(c, out, checker.Contains, "data path address must be a non-zero IP")
out, err = d.Cmd("swarm", "init", "--data-path-addr", "0.0.0.0:2000")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "data path address must be a non-zero IP")
assert.Assert(c, out, checker.Contains, "data path address must be a non-zero IP")
}
func (s *DockerSwarmSuite) TestSwarmJoinLeave(c *check.C) {
@ -1833,7 +1833,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSource(c *check.C) {
out, err := d1.Cmd("network", "create", "--attachable", "-d", "overlay", "foo")
assert.NilError(c, err, out)
networkID := strings.TrimSpace(out)
c.Assert(networkID, checker.Not(checker.Equals), "")
assert.Assert(c, networkID, checker.Not(checker.Equals), "")
// d1, d2 are managers that can get swarm events
waitForEvent(c, d1, "0", "-f scope=swarm", "network create "+networkID, defaultRetryCount)
@ -1841,7 +1841,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSource(c *check.C) {
// d3 is a worker, not able to get cluster events
out = waitForEvent(c, d3, "0", "-f scope=swarm", "", 1)
c.Assert(out, checker.Not(checker.Contains), "network create ")
assert.Assert(c, out, checker.Not(checker.Contains), "network create ")
}
func (s *DockerSwarmSuite) TestSwarmClusterEventsScope(c *check.C) {
@ -1854,7 +1854,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsScope(c *check.C) {
// scope swarm filters cluster events
out = waitForEvent(c, d, "0", "-f scope=swarm", "service create "+serviceID, defaultRetryCount)
c.Assert(out, checker.Not(checker.Contains), "container create ")
assert.Assert(c, out, checker.Not(checker.Contains), "container create ")
// all events are returned if scope is not specified
waitForEvent(c, d, "0", "", "service create "+serviceID, 1)
@ -1862,7 +1862,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsScope(c *check.C) {
// scope local only shows non-cluster events
out = waitForEvent(c, d, "0", "-f scope=local", "container create ", 1)
c.Assert(out, checker.Not(checker.Contains), "service create ")
assert.Assert(c, out, checker.Not(checker.Contains), "service create ")
}
func (s *DockerSwarmSuite) TestSwarmClusterEventsType(c *check.C) {
@ -1877,15 +1877,15 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsType(c *check.C) {
out, err = d.Cmd("network", "create", "--attachable", "-d", "overlay", "foo")
assert.NilError(c, err, out)
networkID := strings.TrimSpace(out)
c.Assert(networkID, checker.Not(checker.Equals), "")
assert.Assert(c, networkID, checker.Not(checker.Equals), "")
// filter by service
out = waitForEvent(c, d, "0", "-f type=service", "service create "+serviceID, defaultRetryCount)
c.Assert(out, checker.Not(checker.Contains), "network create")
assert.Assert(c, out, checker.Not(checker.Contains), "network create")
// filter by network
out = waitForEvent(c, d, "0", "-f type=network", "network create "+networkID, defaultRetryCount)
c.Assert(out, checker.Not(checker.Contains), "service create")
assert.Assert(c, out, checker.Not(checker.Contains), "service create")
}
func (s *DockerSwarmSuite) TestSwarmClusterEventsService(c *check.C) {
@ -1905,12 +1905,12 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsService(c *check.C) {
// wait for service update start
out = waitForEvent(c, d, t1, "-f scope=swarm", "service update "+serviceID, defaultRetryCount)
c.Assert(out, checker.Contains, "updatestate.new=updating")
assert.Assert(c, out, checker.Contains, "updatestate.new=updating")
// allow service update complete. This is a service with 1 instance
time.Sleep(400 * time.Millisecond)
out = waitForEvent(c, d, t1, "-f scope=swarm", "service update "+serviceID, defaultRetryCount)
c.Assert(out, checker.Contains, "updatestate.new=completed, updatestate.old=updating")
assert.Assert(c, out, checker.Contains, "updatestate.new=completed, updatestate.old=updating")
// scale service
t2 := daemonUnixTime(c)
@ -1918,7 +1918,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsService(c *check.C) {
assert.NilError(c, err, out)
out = waitForEvent(c, d, t2, "-f scope=swarm", "service update "+serviceID, defaultRetryCount)
c.Assert(out, checker.Contains, "replicas.new=3, replicas.old=1")
assert.Assert(c, out, checker.Contains, "replicas.new=3, replicas.old=1")
// remove service
t3 := daemonUnixTime(c)
@ -1942,7 +1942,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsNode(c *check.C) {
// filter by type
out = waitForEvent(c, d1, t1, "-f type=node", "node update "+d3ID, defaultRetryCount)
c.Assert(out, checker.Contains, "availability.new=pause, availability.old=active")
assert.Assert(c, out, checker.Contains, "availability.new=pause, availability.old=active")
t2 := daemonUnixTime(c)
out, err = d1.Cmd("node", "demote", d3ID)
@ -1987,7 +1987,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsSecret(c *check.C) {
},
Data: []byte("TESTINGDATA"),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("secrets: %s", id))
waitForEvent(c, d, "0", "-f scope=swarm", "secret create "+id, defaultRetryCount)
@ -2007,7 +2007,7 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *check.C) {
},
Data: []byte("TESTINGDATA"),
})
c.Assert(id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
assert.Assert(c, id, checker.Not(checker.Equals), "", check.Commentf("configs: %s", id))
waitForEvent(c, d, "0", "-f scope=swarm", "config create "+id, defaultRetryCount)
@ -2019,13 +2019,13 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *check.C) {
func getUnlockKey(d *daemon.Daemon, c *check.C, autolockOutput string) string {
unlockKey, err := d.Cmd("swarm", "unlock-key", "-q")
c.Assert(err, checker.IsNil, check.Commentf("%s", unlockKey))
assert.Assert(c, err, checker.IsNil, check.Commentf("%s", unlockKey))
unlockKey = strings.TrimSuffix(unlockKey, "\n")
// Check that "docker swarm init --autolock" or "docker swarm update --autolock"
// contains all the expected strings, including the unlock key
c.Assert(autolockOutput, checker.Contains, "docker swarm unlock")
c.Assert(autolockOutput, checker.Contains, unlockKey)
assert.Assert(c, autolockOutput, checker.Contains, "docker swarm unlock")
assert.Assert(c, autolockOutput, checker.Contains, unlockKey)
return unlockKey
}

View file

@ -38,7 +38,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
// 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), ".")
c.Assert(uidgid, checker.HasLen, 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.Root)))
assert.Assert(c, uidgid, checker.HasLen, 2, check.Commentf("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])
@ -51,16 +51,16 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
assert.NilError(c, err, "Output: %s", out)
user := s.findUser(c, "userns")
c.Assert(uidgid[0], checker.Equals, user)
assert.Assert(c, uidgid[0], checker.Equals, user)
// check that the created directory is owned by remapped uid:gid
statNotExists, err := system.Stat(tmpDirNotExists)
assert.NilError(c, err)
c.Assert(statNotExists.UID(), checker.Equals, uint32(uid), check.Commentf("Created directory not owned by remapped root UID"))
c.Assert(statNotExists.GID(), checker.Equals, uint32(gid), check.Commentf("Created directory not owned by remapped root GID"))
assert.Assert(c, statNotExists.UID(), checker.Equals, uint32(uid), check.Commentf("Created directory not owned by remapped root UID"))
assert.Assert(c, statNotExists.GID(), checker.Equals, uint32(gid), check.Commentf("Created directory not owned by remapped root GID"))
pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns")
c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid))
assert.Assert(c, err, checker.IsNil, check.Commentf("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(
@ -76,21 +76,21 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
// check that the touched file is owned by remapped uid:gid
stat, err := system.Stat(filepath.Join(tmpDir, "testfile"))
assert.NilError(c, err)
c.Assert(stat.UID(), checker.Equals, uint32(uid), check.Commentf("Touched file not owned by remapped root UID"))
c.Assert(stat.GID(), checker.Equals, uint32(gid), check.Commentf("Touched file not owned by remapped root GID"))
assert.Assert(c, stat.UID(), checker.Equals, uint32(uid), check.Commentf("Touched file not owned by remapped root UID"))
assert.Assert(c, stat.GID(), checker.Equals, uint32(gid), check.Commentf("Touched file not owned by remapped root GID"))
// use host usernamespace
out, err = s.d.Cmd("run", "-d", "--name", "userns_skip", "--userns", "host", "busybox", "sh", "-c", "touch /goofy/testfile; top")
c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("Output: %s", out))
user = s.findUser(c, "userns_skip")
// userns are skipped, user is root
c.Assert(user, checker.Equals, "root")
assert.Assert(c, user, checker.Equals, "root")
}
// findUser finds the uid or name of the user of the first process that runs in a container
func (s *DockerDaemonSuite) findUser(c *check.C, container string) string {
out, err := s.d.Cmd("top", container)
c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("Output: %s", out))
rows := strings.Split(out, "\n")
if len(rows) < 2 {
// No process rows founds

View file

@ -29,23 +29,23 @@ func (s *DockerSuite) TestVolumeCLICreate(c *check.C) {
// test using hidden --name option
out, _ := dockerCmd(c, "volume", "create", "--name=test")
name := strings.TrimSpace(out)
c.Assert(name, check.Equals, "test")
assert.Assert(c, name, check.Equals, "test")
out, _ = dockerCmd(c, "volume", "create", "test2")
name = strings.TrimSpace(out)
c.Assert(name, check.Equals, "test2")
assert.Assert(c, name, check.Equals, "test2")
}
func (s *DockerSuite) TestVolumeCLIInspect(c *check.C) {
c.Assert(exec.Command(dockerBinary, "volume", "inspect", "doesnotexist").Run(), check.Not(check.IsNil), check.Commentf("volume inspect should error on non-existent volume"))
assert.Assert(c, exec.Command(dockerBinary, "volume", "inspect", "doesnotexist").Run(), check.Not(check.IsNil), check.Commentf("volume inspect should error on non-existent volume"))
out, _ := dockerCmd(c, "volume", "create")
name := strings.TrimSpace(out)
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Name }}", name)
c.Assert(strings.TrimSpace(out), check.Equals, name)
assert.Assert(c, strings.TrimSpace(out), check.Equals, name)
dockerCmd(c, "volume", "create", "test")
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Name }}", "test")
c.Assert(strings.TrimSpace(out), check.Equals, "test")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "test")
}
func (s *DockerSuite) TestVolumeCLIInspectMulti(c *check.C) {
@ -60,9 +60,9 @@ func (s *DockerSuite) TestVolumeCLIInspectMulti(c *check.C) {
})
out := result.Stdout()
c.Assert(out, checker.Contains, "test1")
c.Assert(out, checker.Contains, "test2")
c.Assert(out, checker.Contains, "test3")
assert.Assert(c, out, checker.Contains, "test1")
assert.Assert(c, out, checker.Contains, "test2")
assert.Assert(c, out, checker.Contains, "test3")
}
func (s *DockerSuite) TestVolumeCLILs(c *check.C) {
@ -134,52 +134,52 @@ func (s *DockerSuite) TestVolumeCLILsFilterDangling(c *check.C) {
out, _ := dockerCmd(c, "volume", "ls")
// No filter, all volumes should show
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
assert.Assert(c, out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
assert.Assert(c, out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
assert.Assert(c, out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=false")
// Explicitly disabling dangling
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
assert.Assert(c, out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
assert.Assert(c, out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
assert.Assert(c, out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=true")
// Filter "dangling" volumes; only "dangling" (unused) volumes should be in the output
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
assert.Assert(c, out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
assert.Assert(c, out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
assert.Assert(c, out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("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
c.Assert(out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
c.Assert(out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
assert.Assert(c, out, checker.Contains, "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
assert.Assert(c, out, check.Not(checker.Contains), "testisinuse1\n", check.Commentf("volume 'testisinuse1' in output, but not expected"))
assert.Assert(c, out, check.Not(checker.Contains), "testisinuse2\n", check.Commentf("volume 'testisinuse2' in output, but not expected"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "dangling=0")
// dangling=0 is same as dangling=false case
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
assert.Assert(c, out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
assert.Assert(c, out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
assert.Assert(c, out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "name=testisin")
c.Assert(out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
c.Assert(out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
assert.Assert(c, out, check.Not(checker.Contains), "testnotinuse1\n", check.Commentf("expected volume 'testnotinuse1' in output"))
assert.Assert(c, out, checker.Contains, "testisinuse1\n", check.Commentf("expected volume 'testisinuse1' in output"))
assert.Assert(c, out, checker.Contains, "testisinuse2\n", check.Commentf("expected volume 'testisinuse2' in output"))
}
func (s *DockerSuite) TestVolumeCLILsErrorWithInvalidFilterName(c *check.C) {
out, _, err := dockerCmdWithError("volume", "ls", "-f", "FOO=123")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Invalid filter")
assert.Assert(c, out, checker.Contains, "Invalid filter")
}
func (s *DockerSuite) TestVolumeCLILsWithIncorrectFilterValue(c *check.C) {
out, _, err := dockerCmdWithError("volume", "ls", "-f", "dangling=invalid")
assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Invalid filter")
assert.Assert(c, out, checker.Contains, "Invalid filter")
}
func (s *DockerSuite) TestVolumeCLIRm(c *check.C) {
@ -200,17 +200,17 @@ func (s *DockerSuite) TestVolumeCLIRm(c *check.C) {
})
out, _ = dockerCmd(c, "run", "--volumes-from=test", "--name=test2", "busybox", "sh", "-c", "cat /foo/bar")
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
assert.Assert(c, strings.TrimSpace(out), check.Equals, "hello")
dockerCmd(c, "rm", "-fv", "test2")
dockerCmd(c, "volume", "inspect", volumeID)
dockerCmd(c, "rm", "-f", "test")
out, _ = dockerCmd(c, "run", "--name=test2", "-v", volumeID+":"+prefix+"/foo", "busybox", "sh", "-c", "cat /foo/bar")
c.Assert(strings.TrimSpace(out), check.Equals, "hello", check.Commentf("volume data was removed"))
assert.Assert(c, strings.TrimSpace(out), check.Equals, "hello", check.Commentf("volume data was removed"))
dockerCmd(c, "rm", "test2")
dockerCmd(c, "volume", "rm", volumeID)
c.Assert(exec.Command("volume", "rm", "doesnotexist").Run(), check.Not(check.IsNil), check.Commentf("volume rm should fail with non-existent volume"))
assert.Assert(c, exec.Command("volume", "rm", "doesnotexist").Run(), check.Not(check.IsNil), check.Commentf("volume rm should fail with non-existent volume"))
}
// FIXME(vdemeester) should be a unit test in cli/command/volume package
@ -218,7 +218,7 @@ func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) {
out, _ := dockerCmd(c, "volume")
// no args should produce the cmd usage output
usage := "Usage: docker volume COMMAND"
c.Assert(out, checker.Contains, usage)
assert.Assert(c, out, checker.Contains, usage)
// invalid arg should error and show the command usage on stderr
icmd.RunCommand(dockerBinary, "volume", "somearg").Assert(c, icmd.Expected{
@ -234,7 +234,7 @@ func (s *DockerSuite) TestVolumeCLINoArgs(c *check.C) {
Error: "exit status 125",
Err: usage,
})
c.Assert(result.Stderr(), checker.Contains, "unknown flag: --no-such-flag")
assert.Assert(c, result.Stderr(), checker.Contains, "unknown flag: --no-such-flag")
}
func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *check.C) {
@ -242,9 +242,9 @@ func (s *DockerSuite) TestVolumeCLIInspectTmplError(c *check.C) {
name := strings.TrimSpace(out)
out, exitCode, err := dockerCmdWithError("volume", "inspect", "--format='{{ .FooBar }}'", name)
c.Assert(err, checker.NotNil, check.Commentf("Output: %s", out))
c.Assert(exitCode, checker.Equals, 1, check.Commentf("Output: %s", out))
c.Assert(out, checker.Contains, "Template parsing error")
assert.Assert(c, err, checker.NotNil, check.Commentf("Output: %s", out))
assert.Assert(c, exitCode, checker.Equals, 1, check.Commentf("Output: %s", out))
assert.Assert(c, out, checker.Contains, "Template parsing error")
}
func (s *DockerSuite) TestVolumeCLICreateWithOpts(c *check.C) {
@ -260,15 +260,15 @@ func (s *DockerSuite) TestVolumeCLICreateWithOpts(c *check.C) {
found = true
info := strings.Fields(m)
// tmpfs on <path> type tmpfs (rw,relatime,size=1024k,uid=1000)
c.Assert(info[0], checker.Equals, "tmpfs")
c.Assert(info[2], checker.Equals, "/foo")
c.Assert(info[4], checker.Equals, "tmpfs")
c.Assert(info[5], checker.Contains, "uid=1000")
c.Assert(info[5], checker.Contains, "size=1024k")
assert.Assert(c, info[0], checker.Equals, "tmpfs")
assert.Assert(c, info[2], checker.Equals, "/foo")
assert.Assert(c, info[4], checker.Equals, "tmpfs")
assert.Assert(c, info[5], checker.Contains, "uid=1000")
assert.Assert(c, info[5], checker.Contains, "size=1024k")
break
}
}
c.Assert(found, checker.Equals, true)
assert.Assert(c, found, checker.Equals, true)
}
func (s *DockerSuite) TestVolumeCLICreateLabel(c *check.C) {
@ -280,7 +280,7 @@ func (s *DockerSuite) TestVolumeCLICreateLabel(c *check.C) {
assert.NilError(c, err)
out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+testLabel+" }}", testVol)
c.Assert(strings.TrimSpace(out), check.Equals, testValue)
assert.Assert(c, strings.TrimSpace(out), check.Equals, testValue)
}
func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *check.C) {
@ -306,7 +306,7 @@ func (s *DockerSuite) TestVolumeCLICreateLabelMultiple(c *check.C) {
for k, v := range testLabels {
out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Labels."+k+" }}", testVol)
c.Assert(strings.TrimSpace(out), check.Equals, v)
assert.Assert(c, strings.TrimSpace(out), check.Equals, v)
}
}
@ -322,22 +322,22 @@ func (s *DockerSuite) TestVolumeCLILsFilterLabels(c *check.C) {
out, _ := dockerCmd(c, "volume", "ls", "--filter", "label=foo")
// filter with label=key
c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
c.Assert(out, checker.Contains, "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2' in output"))
assert.Assert(c, out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
assert.Assert(c, out, checker.Contains, "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2' in output"))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=bar1")
// filter with label=key=value
c.Assert(out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
c.Assert(out, check.Not(checker.Contains), "testvolcreatelabel-2\n", check.Commentf("expected volume 'testvolcreatelabel-2 in output"))
assert.Assert(c, out, checker.Contains, "testvolcreatelabel-1\n", check.Commentf("expected volume 'testvolcreatelabel-1' in output"))
assert.Assert(c, out, check.Not(checker.Contains), "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")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
assert.Assert(c, len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
out, _ = dockerCmd(c, "volume", "ls", "--filter", "label=foo=non-exist")
outArr = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
assert.Assert(c, len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
}
func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *check.C) {
@ -352,23 +352,23 @@ func (s *DockerSuite) TestVolumeCLILsFilterDrivers(c *check.C) {
// filter with driver=local
out, _ := dockerCmd(c, "volume", "ls", "--filter", "driver=local")
c.Assert(out, checker.Contains, "testvol-1\n", check.Commentf("expected volume 'testvol-1' in output"))
c.Assert(out, checker.Contains, "testvol-2\n", check.Commentf("expected volume 'testvol-2' in output"))
assert.Assert(c, out, checker.Contains, "testvol-1\n", check.Commentf("expected volume 'testvol-1' in output"))
assert.Assert(c, out, checker.Contains, "testvol-2\n", check.Commentf("expected volume 'testvol-2' in output"))
// filter with driver=invaliddriver
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=invaliddriver")
outArr := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
assert.Assert(c, len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
// filter with driver=loca
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=loca")
outArr = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
assert.Assert(c, len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
// filter with driver=
out, _ = dockerCmd(c, "volume", "ls", "--filter", "driver=")
outArr = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
assert.Assert(c, len(outArr), check.Equals, 1, check.Commentf("\n%s", out))
}
func (s *DockerSuite) TestVolumeCLIRmForceUsage(c *check.C) {
@ -385,7 +385,7 @@ func (s *DockerSuite) TestVolumeCLIRmForce(c *check.C) {
name := "test"
out, _ := dockerCmd(c, "volume", "create", name)
id := strings.TrimSpace(out)
c.Assert(id, checker.Equals, name)
assert.Assert(c, id, checker.Equals, name)
out, _ = dockerCmd(c, "volume", "inspect", "--format", "{{.Mountpoint}}", name)
assert.Assert(c, strings.TrimSpace(out) != "")
@ -395,10 +395,10 @@ func (s *DockerSuite) TestVolumeCLIRmForce(c *check.C) {
dockerCmd(c, "volume", "rm", "-f", name)
out, _ = dockerCmd(c, "volume", "ls")
c.Assert(out, checker.Not(checker.Contains), name)
assert.Assert(c, out, checker.Not(checker.Contains), name)
dockerCmd(c, "volume", "create", name)
out, _ = dockerCmd(c, "volume", "ls")
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
}
// TestVolumeCLIRmForceInUse verifies that repeated `docker volume rm -f` calls does not remove a volume
@ -407,7 +407,7 @@ func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *check.C) {
name := "testvolume"
out, _ := dockerCmd(c, "volume", "create", name)
id := strings.TrimSpace(out)
c.Assert(id, checker.Equals, name)
assert.Assert(c, id, checker.Equals, name)
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
out, _ = dockerCmd(c, "create", "-v", "testvolume:"+prefix+slash+"foo", "busybox")
@ -417,7 +417,7 @@ func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *check.C) {
assert.ErrorContains(c, err, "")
assert.ErrorContains(c, err, "volume is in use")
out, _ = dockerCmd(c, "volume", "ls")
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
// The original issue did not _remove_ the volume from the list
// the first time. But a second call to `volume rm` removed it.
@ -427,18 +427,18 @@ func (s *DockerSuite) TestVolumeCLIRmForceInUse(c *check.C) {
assert.ErrorContains(c, err, "")
assert.ErrorContains(c, err, "volume is in use")
out, _ = dockerCmd(c, "volume", "ls")
c.Assert(out, checker.Contains, name)
assert.Assert(c, out, checker.Contains, name)
// Verify removing the volume after the container is removed works
_, e := dockerCmd(c, "rm", cid)
c.Assert(e, check.Equals, 0)
assert.Assert(c, e, check.Equals, 0)
_, e = dockerCmd(c, "volume", "rm", "-f", name)
c.Assert(e, check.Equals, 0)
assert.Assert(c, e, check.Equals, 0)
out, e = dockerCmd(c, "volume", "ls")
c.Assert(e, check.Equals, 0)
c.Assert(out, checker.Not(checker.Contains), name)
assert.Assert(c, e, check.Equals, 0)
assert.Assert(c, out, checker.Not(checker.Contains), name)
}
func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *check.C) {
@ -448,7 +448,7 @@ func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *check.C) {
name := "test1"
dockerCmd(c, "volume", "create", "-d", "local", name)
out, _ := dockerCmd(c, "volume", "inspect", "--format={{ .Options }}", name)
c.Assert(strings.TrimSpace(out), checker.Contains, "map[]")
assert.Assert(c, strings.TrimSpace(out), checker.Contains, "map[]")
// With options
name = "test2"
@ -457,9 +457,9 @@ func (s *DockerSuite) TestVolumeCliInspectWithVolumeOpts(c *check.C) {
k3, v3 := "o", "size=1m,uid=1000"
dockerCmd(c, "volume", "create", "-d", "local", name, "--opt", fmt.Sprintf("%s=%s", k1, v1), "--opt", fmt.Sprintf("%s=%s", k2, v2), "--opt", fmt.Sprintf("%s=%s", k3, v3))
out, _ = dockerCmd(c, "volume", "inspect", "--format={{ .Options }}", name)
c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k1, v1))
c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k2, v2))
c.Assert(strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k3, v3))
assert.Assert(c, strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k1, v1))
assert.Assert(c, strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k2, v2))
assert.Assert(c, strings.TrimSpace(out), checker.Contains, fmt.Sprintf("%s:%s", k3, v3))
}
// Test case (1) for 21845: duplicate targets for --volumes-from
@ -476,19 +476,19 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *check.C) {
out, _ := dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data1")
data1 := strings.TrimSpace(out)
c.Assert(data1, checker.Not(checker.Equals), "")
assert.Assert(c, data1, checker.Not(checker.Equals), "")
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data2")
data2 := strings.TrimSpace(out)
c.Assert(data2, checker.Not(checker.Equals), "")
assert.Assert(c, data2, checker.Not(checker.Equals), "")
// Both volume should exist
out, _ = dockerCmd(c, "volume", "ls", "-q")
c.Assert(strings.TrimSpace(out), checker.Contains, data1)
c.Assert(strings.TrimSpace(out), checker.Contains, data2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, data1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, data2)
out, _, err := dockerCmdWithError("run", "--name=app", "--volumes-from=data1", "--volumes-from=data2", "-d", "busybox", "top")
c.Assert(err, checker.IsNil, check.Commentf("Out: %s", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("Out: %s", out))
// Only the second volume will be referenced, this is backward compatible
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "app")
@ -500,8 +500,8 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFrom(c *check.C) {
// Both volume should not exist
out, _ = dockerCmd(c, "volume", "ls", "-q")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data2)
}
// Test case (2) for 21845: duplicate targets for --volumes-from and -v (bind)
@ -518,25 +518,25 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *check.C)
out, _ := dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data1")
data1 := strings.TrimSpace(out)
c.Assert(data1, checker.Not(checker.Equals), "")
assert.Assert(c, data1, checker.Not(checker.Equals), "")
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data2")
data2 := strings.TrimSpace(out)
c.Assert(data2, checker.Not(checker.Equals), "")
assert.Assert(c, data2, checker.Not(checker.Equals), "")
// Both volume should exist
out, _ = dockerCmd(c, "volume", "ls", "-q")
c.Assert(strings.TrimSpace(out), checker.Contains, data1)
c.Assert(strings.TrimSpace(out), checker.Contains, data2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, data1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, 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")
c.Assert(err, checker.IsNil, check.Commentf("Out: %s", out))
assert.Assert(c, err, checker.IsNil, check.Commentf("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")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data2)
dockerCmd(c, "rm", "-f", "-v", "app")
dockerCmd(c, "rm", "-f", "-v", "data1")
@ -544,8 +544,8 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndBind(c *check.C)
// Both volume should not exist
out, _ = dockerCmd(c, "volume", "ls", "-q")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data2)
}
// Test case (3) for 21845: duplicate targets for --volumes-from and `Mounts` (API only)
@ -562,16 +562,16 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *check.C
out, _ := dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data1")
data1 := strings.TrimSpace(out)
c.Assert(data1, checker.Not(checker.Equals), "")
assert.Assert(c, data1, checker.Not(checker.Equals), "")
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "data2")
data2 := strings.TrimSpace(out)
c.Assert(data2, checker.Not(checker.Equals), "")
assert.Assert(c, data2, checker.Not(checker.Equals), "")
// Both volume should exist
out, _ = dockerCmd(c, "volume", "ls", "-q")
c.Assert(strings.TrimSpace(out), checker.Contains, data1)
c.Assert(strings.TrimSpace(out), checker.Contains, data2)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, data1)
assert.Assert(c, strings.TrimSpace(out), checker.Contains, data2)
err := os.MkdirAll("/tmp/data", 0755)
assert.NilError(c, err)
@ -601,8 +601,8 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *check.C
// No volume will be referenced (mount is /tmp/data), this is backward compatible
out, _ = dockerCmd(c, "inspect", "--format", "{{(index .Mounts 0).Name}}", "app")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data2)
dockerCmd(c, "rm", "-f", "-v", "app")
dockerCmd(c, "rm", "-f", "-v", "data1")
@ -610,6 +610,6 @@ func (s *DockerSuite) TestDuplicateMountpointsForVolumesFromAndMounts(c *check.C
// Both volume should not exist
out, _ = dockerCmd(c, "volume", "ls", "-q")
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data1)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), data2)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data1)
assert.Assert(c, strings.TrimSpace(out), checker.Not(checker.Contains), data2)
}

View file

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

View file

@ -77,7 +77,7 @@ func inspectFieldAndUnmarshall(c *check.C, name, field string, output interface{
str := inspectFieldJSON(c, name, field)
err := json.Unmarshal([]byte(str), output)
if c != nil {
c.Assert(err, check.IsNil, check.Commentf("failed to unmarshal: %v", err))
assert.Assert(c, err, check.IsNil, check.Commentf("failed to unmarshal: %v", err))
}
}
@ -201,7 +201,7 @@ func buildImage(name string, cmdOperators ...cli.CmdOperator) *icmd.Result {
// Fail the test when error occurs.
func writeFile(dst, content string, c *check.C) {
// Create subdirectories if necessary
c.Assert(os.MkdirAll(path.Dir(dst), 0700), check.IsNil)
assert.Assert(c, os.MkdirAll(path.Dir(dst), 0700), check.IsNil)
f, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0700)
assert.NilError(c, err)
defer f.Close()
@ -263,7 +263,7 @@ func daemonTime(c *check.C) time.Time {
assert.NilError(c, err)
dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
c.Assert(err, check.IsNil, check.Commentf("invalid time format in GET /info response"))
assert.Assert(c, err, check.IsNil, check.Commentf("invalid time format in GET /info response"))
return dt
}
@ -408,7 +408,7 @@ func waitForGoroutines(expected int) error {
// getErrorMessage returns the error message from an error API response
func getErrorMessage(c *check.C, body []byte) string {
var resp types.ErrorResponse
c.Assert(json.Unmarshal(body, &resp), check.IsNil)
assert.Assert(c, json.Unmarshal(body, &resp), check.IsNil)
return strings.TrimSpace(resp.Message)
}

View file

@ -15,64 +15,64 @@ var _ = check.Suite(&DiscoverySuite{})
func (s *DiscoverySuite) TestNewEntry(c *check.C) {
entry, err := NewEntry("127.0.0.1:2375")
c.Assert(err, check.IsNil)
c.Assert(entry.Equals(&Entry{Host: "127.0.0.1", Port: "2375"}), check.Equals, true)
c.Assert(entry.String(), check.Equals, "127.0.0.1:2375")
assert.Assert(c, err, check.IsNil)
assert.Assert(c, entry.Equals(&Entry{Host: "127.0.0.1", Port: "2375"}), check.Equals, true)
assert.Assert(c, entry.String(), check.Equals, "127.0.0.1:2375")
entry, err = NewEntry("[2001:db8:0:f101::2]:2375")
c.Assert(err, check.IsNil)
c.Assert(entry.Equals(&Entry{Host: "2001:db8:0:f101::2", Port: "2375"}), check.Equals, true)
c.Assert(entry.String(), check.Equals, "[2001:db8:0:f101::2]:2375")
assert.Assert(c, err, check.IsNil)
assert.Assert(c, entry.Equals(&Entry{Host: "2001:db8:0:f101::2", Port: "2375"}), check.Equals, true)
assert.Assert(c, entry.String(), check.Equals, "[2001:db8:0:f101::2]:2375")
_, err = NewEntry("127.0.0.1")
c.Assert(err, check.NotNil)
assert.Assert(c, err, check.NotNil)
}
func (s *DiscoverySuite) TestParse(c *check.C) {
scheme, uri := parse("127.0.0.1:2375")
c.Assert(scheme, check.Equals, "nodes")
c.Assert(uri, check.Equals, "127.0.0.1:2375")
assert.Assert(c, scheme, check.Equals, "nodes")
assert.Assert(c, uri, check.Equals, "127.0.0.1:2375")
scheme, uri = parse("localhost:2375")
c.Assert(scheme, check.Equals, "nodes")
c.Assert(uri, check.Equals, "localhost:2375")
assert.Assert(c, scheme, check.Equals, "nodes")
assert.Assert(c, uri, check.Equals, "localhost:2375")
scheme, uri = parse("scheme://127.0.0.1:2375")
c.Assert(scheme, check.Equals, "scheme")
c.Assert(uri, check.Equals, "127.0.0.1:2375")
assert.Assert(c, scheme, check.Equals, "scheme")
assert.Assert(c, uri, check.Equals, "127.0.0.1:2375")
scheme, uri = parse("scheme://localhost:2375")
c.Assert(scheme, check.Equals, "scheme")
c.Assert(uri, check.Equals, "localhost:2375")
assert.Assert(c, scheme, check.Equals, "scheme")
assert.Assert(c, uri, check.Equals, "localhost:2375")
scheme, uri = parse("")
c.Assert(scheme, check.Equals, "nodes")
c.Assert(uri, check.Equals, "")
assert.Assert(c, scheme, check.Equals, "nodes")
assert.Assert(c, uri, check.Equals, "")
}
func (s *DiscoverySuite) TestCreateEntries(c *check.C) {
entries, err := CreateEntries(nil)
c.Assert(entries, check.DeepEquals, Entries{})
c.Assert(err, check.IsNil)
assert.Assert(c, entries, check.DeepEquals, Entries{})
assert.Assert(c, err, check.IsNil)
entries, err = CreateEntries([]string{"127.0.0.1:2375", "127.0.0.2:2375", "[2001:db8:0:f101::2]:2375", ""})
c.Assert(err, check.IsNil)
assert.Assert(c, err, check.IsNil)
expected := Entries{
&Entry{Host: "127.0.0.1", Port: "2375"},
&Entry{Host: "127.0.0.2", Port: "2375"},
&Entry{Host: "2001:db8:0:f101::2", Port: "2375"},
}
c.Assert(entries.Equals(expected), check.Equals, true)
assert.Assert(c, entries.Equals(expected), check.Equals, true)
_, err = CreateEntries([]string{"127.0.0.1", "127.0.0.2"})
c.Assert(err, check.NotNil)
assert.Assert(c, err, check.NotNil)
}
func (s *DiscoverySuite) TestContainsEntry(c *check.C) {
entries, err := CreateEntries([]string{"127.0.0.1:2375", "127.0.0.2:2375", ""})
c.Assert(err, check.IsNil)
c.Assert(entries.Contains(&Entry{Host: "127.0.0.1", Port: "2375"}), check.Equals, true)
c.Assert(entries.Contains(&Entry{Host: "127.0.0.3", Port: "2375"}), check.Equals, false)
assert.Assert(c, err, check.IsNil)
assert.Assert(c, entries.Contains(&Entry{Host: "127.0.0.1", Port: "2375"}), check.Equals, true)
assert.Assert(c, entries.Contains(&Entry{Host: "127.0.0.3", Port: "2375"}), check.Equals, false)
}
func (s *DiscoverySuite) TestEntriesEquality(c *check.C) {
@ -82,20 +82,20 @@ func (s *DiscoverySuite) TestEntriesEquality(c *check.C) {
}
// Same
c.Assert(entries.Equals(Entries{
assert.Assert(c, entries.Equals(Entries{
&Entry{Host: "127.0.0.1", Port: "2375"},
&Entry{Host: "127.0.0.2", Port: "2375"},
}), check.Equals, true)
// Different size
c.Assert(entries.Equals(Entries{
assert.Assert(c, entries.Equals(Entries{
&Entry{Host: "127.0.0.1", Port: "2375"},
&Entry{Host: "127.0.0.2", Port: "2375"},
&Entry{Host: "127.0.0.3", Port: "2375"},
}), check.Equals, false)
// Different content
c.Assert(entries.Equals(Entries{
assert.Assert(c, entries.Equals(Entries{
&Entry{Host: "127.0.0.1", Port: "2375"},
&Entry{Host: "127.0.0.42", Port: "2375"},
}), check.Equals, false)
@ -110,25 +110,25 @@ func (s *DiscoverySuite) TestEntriesDiff(c *check.C) {
// No diff
added, removed := entries.Diff(Entries{entry2, entry1})
c.Assert(added, check.HasLen, 0)
c.Assert(removed, check.HasLen, 0)
assert.Assert(c, added, check.HasLen, 0)
assert.Assert(c, removed, check.HasLen, 0)
// Add
added, removed = entries.Diff(Entries{entry2, entry3, entry1})
c.Assert(added, check.HasLen, 1)
c.Assert(added.Contains(entry3), check.Equals, true)
c.Assert(removed, check.HasLen, 0)
assert.Assert(c, added, check.HasLen, 1)
assert.Assert(c, added.Contains(entry3), check.Equals, true)
assert.Assert(c, removed, check.HasLen, 0)
// Remove
added, removed = entries.Diff(Entries{entry2})
c.Assert(added, check.HasLen, 0)
c.Assert(removed, check.HasLen, 1)
c.Assert(removed.Contains(entry1), check.Equals, true)
assert.Assert(c, added, check.HasLen, 0)
assert.Assert(c, removed, check.HasLen, 1)
assert.Assert(c, removed.Contains(entry1), check.Equals, true)
// Add and remove
added, removed = entries.Diff(Entries{entry1, entry3})
c.Assert(added, check.HasLen, 1)
c.Assert(added.Contains(entry3), check.Equals, true)
c.Assert(removed, check.HasLen, 1)
c.Assert(removed.Contains(entry2), check.Equals, true)
assert.Assert(c, added, check.HasLen, 1)
assert.Assert(c, added.Contains(entry3), check.Equals, true)
assert.Assert(c, removed, check.HasLen, 1)
assert.Assert(c, removed.Contains(entry2), check.Equals, true)
}

View file

@ -20,13 +20,13 @@ var _ = check.Suite(&DiscoverySuite{})
func (s *DiscoverySuite) TestInitialize(c *check.C) {
d := &Discovery{}
d.Initialize("/path/to/file", 1000, 0, nil)
c.Assert(d.path, check.Equals, "/path/to/file")
assert.Assert(c, d.path, check.Equals, "/path/to/file")
}
func (s *DiscoverySuite) TestNew(c *check.C) {
d, err := discovery.New("file:///path/to/file", 0, 0, nil)
c.Assert(err, check.IsNil)
c.Assert(d.(*Discovery).path, check.Equals, "/path/to/file")
assert.Assert(c, err, check.IsNil)
assert.Assert(c, d.(*Discovery).path, check.Equals, "/path/to/file")
}
func (s *DiscoverySuite) TestContent(c *check.C) {
@ -35,17 +35,17 @@ func (s *DiscoverySuite) TestContent(c *check.C) {
2.2.2.[2:4]:2222
`
ips := parseFileContent([]byte(data))
c.Assert(ips, check.HasLen, 5)
c.Assert(ips[0], check.Equals, "1.1.1.1:1111")
c.Assert(ips[1], check.Equals, "1.1.1.2:1111")
c.Assert(ips[2], check.Equals, "2.2.2.2:2222")
c.Assert(ips[3], check.Equals, "2.2.2.3:2222")
c.Assert(ips[4], check.Equals, "2.2.2.4:2222")
assert.Assert(c, ips, check.HasLen, 5)
assert.Assert(c, ips[0], check.Equals, "1.1.1.1:1111")
assert.Assert(c, ips[1], check.Equals, "1.1.1.2:1111")
assert.Assert(c, ips[2], check.Equals, "2.2.2.2:2222")
assert.Assert(c, ips[3], check.Equals, "2.2.2.3:2222")
assert.Assert(c, ips[4], check.Equals, "2.2.2.4:2222")
}
func (s *DiscoverySuite) TestRegister(c *check.C) {
discovery := &Discovery{path: "/path/to/file"}
c.Assert(discovery.Register("0.0.0.0"), check.NotNil)
assert.Assert(c, discovery.Register("0.0.0.0"), check.NotNil)
}
func (s *DiscoverySuite) TestParsingContentsWithComments(c *check.C) {
@ -58,9 +58,9 @@ func (s *DiscoverySuite) TestParsingContentsWithComments(c *check.C) {
### test ###
`
ips := parseFileContent([]byte(data))
c.Assert(ips, check.HasLen, 2)
c.Assert("1.1.1.1:1111", check.Equals, ips[0])
c.Assert("3.3.3.3:3333", check.Equals, ips[1])
assert.Assert(c, ips, check.HasLen, 2)
assert.Assert(c, "1.1.1.1:1111", check.Equals, ips[0])
assert.Assert(c, "3.3.3.3:3333", check.Equals, ips[1])
}
func (s *DiscoverySuite) TestWatch(c *check.C) {
@ -75,9 +75,9 @@ func (s *DiscoverySuite) TestWatch(c *check.C) {
// Create a temporary file and remove it.
tmp, err := ioutil.TempFile(os.TempDir(), "discovery-file-test")
c.Assert(err, check.IsNil)
c.Assert(tmp.Close(), check.IsNil)
c.Assert(os.Remove(tmp.Name()), check.IsNil)
assert.Assert(c, err, check.IsNil)
assert.Assert(c, tmp.Close(), check.IsNil)
assert.Assert(c, os.Remove(tmp.Name()), check.IsNil)
// Set up file discovery.
d := &Discovery{}
@ -86,7 +86,7 @@ func (s *DiscoverySuite) TestWatch(c *check.C) {
ch, errCh := d.Watch(stopCh)
// Make sure it fires errors since the file doesn't exist.
c.Assert(<-errCh, check.NotNil)
assert.Assert(c, <-errCh, check.NotNil)
// We have to drain the error channel otherwise Watch will get stuck.
go func() {
for range errCh {
@ -94,21 +94,21 @@ func (s *DiscoverySuite) TestWatch(c *check.C) {
}()
// Write the file and make sure we get the expected value back.
c.Assert(ioutil.WriteFile(tmp.Name(), []byte(data), 0600), check.IsNil)
c.Assert(<-ch, check.DeepEquals, expected)
assert.Assert(c, ioutil.WriteFile(tmp.Name(), []byte(data), 0600), check.IsNil)
assert.Assert(c, <-ch, check.DeepEquals, expected)
// Add a new entry and look it up.
expected = append(expected, &discovery.Entry{Host: "3.3.3.3", Port: "3333"})
f, err := os.OpenFile(tmp.Name(), os.O_APPEND|os.O_WRONLY, 0600)
c.Assert(err, check.IsNil)
c.Assert(f, check.NotNil)
assert.Assert(c, err, check.IsNil)
assert.Assert(c, f, check.NotNil)
_, err = f.WriteString("\n3.3.3.3:3333\n")
c.Assert(err, check.IsNil)
assert.Assert(c, err, check.IsNil)
f.Close()
c.Assert(<-ch, check.DeepEquals, expected)
assert.Assert(c, <-ch, check.DeepEquals, expected)
// Stop and make sure it closes all channels.
close(stopCh)
c.Assert(<-ch, check.IsNil)
c.Assert(<-errCh, check.IsNil)
assert.Assert(c, <-ch, check.IsNil)
assert.Assert(c, <-errCh, check.IsNil)
}

View file

@ -6,48 +6,48 @@ import (
func (s *DiscoverySuite) TestGeneratorNotGenerate(c *check.C) {
ips := Generate("127.0.0.1")
c.Assert(len(ips), check.Equals, 1)
c.Assert(ips[0], check.Equals, "127.0.0.1")
assert.Assert(c, len(ips), check.Equals, 1)
assert.Assert(c, ips[0], check.Equals, "127.0.0.1")
}
func (s *DiscoverySuite) TestGeneratorWithPortNotGenerate(c *check.C) {
ips := Generate("127.0.0.1:8080")
c.Assert(len(ips), check.Equals, 1)
c.Assert(ips[0], check.Equals, "127.0.0.1:8080")
assert.Assert(c, len(ips), check.Equals, 1)
assert.Assert(c, ips[0], check.Equals, "127.0.0.1:8080")
}
func (s *DiscoverySuite) TestGeneratorMatchFailedNotGenerate(c *check.C) {
ips := Generate("127.0.0.[1]")
c.Assert(len(ips), check.Equals, 1)
c.Assert(ips[0], check.Equals, "127.0.0.[1]")
assert.Assert(c, len(ips), check.Equals, 1)
assert.Assert(c, ips[0], check.Equals, "127.0.0.[1]")
}
func (s *DiscoverySuite) TestGeneratorWithPort(c *check.C) {
ips := Generate("127.0.0.[1:11]:2375")
c.Assert(len(ips), check.Equals, 11)
c.Assert(ips[0], check.Equals, "127.0.0.1:2375")
c.Assert(ips[1], check.Equals, "127.0.0.2:2375")
c.Assert(ips[2], check.Equals, "127.0.0.3:2375")
c.Assert(ips[3], check.Equals, "127.0.0.4:2375")
c.Assert(ips[4], check.Equals, "127.0.0.5:2375")
c.Assert(ips[5], check.Equals, "127.0.0.6:2375")
c.Assert(ips[6], check.Equals, "127.0.0.7:2375")
c.Assert(ips[7], check.Equals, "127.0.0.8:2375")
c.Assert(ips[8], check.Equals, "127.0.0.9:2375")
c.Assert(ips[9], check.Equals, "127.0.0.10:2375")
c.Assert(ips[10], check.Equals, "127.0.0.11:2375")
assert.Assert(c, len(ips), check.Equals, 11)
assert.Assert(c, ips[0], check.Equals, "127.0.0.1:2375")
assert.Assert(c, ips[1], check.Equals, "127.0.0.2:2375")
assert.Assert(c, ips[2], check.Equals, "127.0.0.3:2375")
assert.Assert(c, ips[3], check.Equals, "127.0.0.4:2375")
assert.Assert(c, ips[4], check.Equals, "127.0.0.5:2375")
assert.Assert(c, ips[5], check.Equals, "127.0.0.6:2375")
assert.Assert(c, ips[6], check.Equals, "127.0.0.7:2375")
assert.Assert(c, ips[7], check.Equals, "127.0.0.8:2375")
assert.Assert(c, ips[8], check.Equals, "127.0.0.9:2375")
assert.Assert(c, ips[9], check.Equals, "127.0.0.10:2375")
assert.Assert(c, ips[10], check.Equals, "127.0.0.11:2375")
}
func (s *DiscoverySuite) TestGenerateWithMalformedInputAtRangeStart(c *check.C) {
malformedInput := "127.0.0.[x:11]:2375"
ips := Generate(malformedInput)
c.Assert(len(ips), check.Equals, 1)
c.Assert(ips[0], check.Equals, malformedInput)
assert.Assert(c, len(ips), check.Equals, 1)
assert.Assert(c, ips[0], check.Equals, malformedInput)
}
func (s *DiscoverySuite) TestGenerateWithMalformedInputAtRangeEnd(c *check.C) {
malformedInput := "127.0.0.[1:x]:2375"
ips := Generate(malformedInput)
c.Assert(len(ips), check.Equals, 1)
c.Assert(ips[0], check.Equals, malformedInput)
assert.Assert(c, len(ips), check.Equals, 1)
assert.Assert(c, ips[0], check.Equals, malformedInput)
}

View file

@ -30,9 +30,9 @@ func (ds *DiscoverySuite) TestInitialize(c *check.C) {
d.store = storeMock
s := d.store.(*FakeStore)
c.Assert(s.Endpoints, check.HasLen, 1)
c.Assert(s.Endpoints[0], check.Equals, "127.0.0.1")
c.Assert(d.path, check.Equals, defaultDiscoveryPath)
assert.Assert(c, s.Endpoints, check.HasLen, 1)
assert.Assert(c, s.Endpoints[0], check.Equals, "127.0.0.1")
assert.Assert(c, d.path, check.Equals, defaultDiscoveryPath)
storeMock = &FakeStore{
Endpoints: []string{"127.0.0.1:1234"},
@ -42,9 +42,9 @@ func (ds *DiscoverySuite) TestInitialize(c *check.C) {
d.store = storeMock
s = d.store.(*FakeStore)
c.Assert(s.Endpoints, check.HasLen, 1)
c.Assert(s.Endpoints[0], check.Equals, "127.0.0.1:1234")
c.Assert(d.path, check.Equals, "path/"+defaultDiscoveryPath)
assert.Assert(c, s.Endpoints, check.HasLen, 1)
assert.Assert(c, s.Endpoints[0], check.Equals, "127.0.0.1:1234")
assert.Assert(c, d.path, check.Equals, "path/"+defaultDiscoveryPath)
storeMock = &FakeStore{
Endpoints: []string{"127.0.0.1:1234", "127.0.0.2:1234", "127.0.0.3:1234"},
@ -54,12 +54,12 @@ func (ds *DiscoverySuite) TestInitialize(c *check.C) {
d.store = storeMock
s = d.store.(*FakeStore)
c.Assert(s.Endpoints, check.HasLen, 3)
c.Assert(s.Endpoints[0], check.Equals, "127.0.0.1:1234")
c.Assert(s.Endpoints[1], check.Equals, "127.0.0.2:1234")
c.Assert(s.Endpoints[2], check.Equals, "127.0.0.3:1234")
assert.Assert(c, s.Endpoints, check.HasLen, 3)
assert.Assert(c, s.Endpoints[0], check.Equals, "127.0.0.1:1234")
assert.Assert(c, s.Endpoints[1], check.Equals, "127.0.0.2:1234")
assert.Assert(c, s.Endpoints[2], check.Equals, "127.0.0.3:1234")
c.Assert(d.path, check.Equals, "path/"+defaultDiscoveryPath)
assert.Assert(c, d.path, check.Equals, "path/"+defaultDiscoveryPath)
}
// Extremely limited mock store so we can test initialization
@ -181,12 +181,12 @@ BFrwkQE4HQtQBV60hYQUzzlSk44VFDz+jxIEtacRHaomDRh2FtOTz+I=
-----END RSA PRIVATE KEY-----
`
certFile, err := ioutil.TempFile("", "cert")
c.Assert(err, check.IsNil)
assert.Assert(c, err, check.IsNil)
defer os.Remove(certFile.Name())
certFile.Write([]byte(cert))
certFile.Close()
keyFile, err := ioutil.TempFile("", "key")
c.Assert(err, check.IsNil)
assert.Assert(c, err, check.IsNil)
defer os.Remove(keyFile.Name())
keyFile.Write([]byte(key))
keyFile.Close()
@ -198,11 +198,11 @@ BFrwkQE4HQtQBV60hYQUzzlSk44VFDz+jxIEtacRHaomDRh2FtOTz+I=
"kv.certfile": certFile.Name(),
"kv.keyfile": keyFile.Name(),
})
c.Assert(err, check.IsNil)
assert.Assert(c, err, check.IsNil)
s := d.store.(*Mock)
c.Assert(s.Options.TLS, check.NotNil)
c.Assert(s.Options.TLS.RootCAs, check.NotNil)
c.Assert(s.Options.TLS.Certificates, check.HasLen, 1)
assert.Assert(c, s.Options.TLS, check.NotNil)
assert.Assert(c, s.Options.TLS.RootCAs, check.NotNil)
assert.Assert(c, s.Options.TLS.Certificates, check.HasLen, 1)
}
func (ds *DiscoverySuite) TestWatch(c *check.C) {
@ -230,7 +230,7 @@ func (ds *DiscoverySuite) TestWatch(c *check.C) {
ch, errCh := d.Watch(stopCh)
// It should fire an error since the first WatchTree call failed.
c.Assert(<-errCh, check.ErrorMatches, "test error")
assert.Assert(c, <-errCh, check.ErrorMatches, "test error")
// We have to drain the error channel otherwise Watch will get stuck.
go func() {
for range errCh {
@ -239,13 +239,13 @@ func (ds *DiscoverySuite) TestWatch(c *check.C) {
// Push the entries into the store channel and make sure discovery emits.
mockCh <- kvs
c.Assert(<-ch, check.DeepEquals, expected)
assert.Assert(c, <-ch, check.DeepEquals, expected)
// Add a new entry.
expected = append(expected, &discovery.Entry{Host: "3.3.3.3", Port: "3333"})
kvs = append(kvs, &store.KVPair{Key: path.Join("path", defaultDiscoveryPath, "3.3.3.3"), Value: []byte("3.3.3.3:3333")})
mockCh <- kvs
c.Assert(<-ch, check.DeepEquals, expected)
assert.Assert(c, <-ch, check.DeepEquals, expected)
close(mockCh)
// Give it enough time to call WatchTree.
@ -253,8 +253,8 @@ func (ds *DiscoverySuite) TestWatch(c *check.C) {
// Stop and make sure it closes all channels.
close(stopCh)
c.Assert(<-ch, check.IsNil)
c.Assert(<-errCh, check.IsNil)
assert.Assert(c, <-ch, check.IsNil)
assert.Assert(c, <-errCh, check.IsNil)
}
// FakeStore implements store.Store methods. It mocks all store

View file

@ -30,19 +30,19 @@ func (s *discoverySuite) TestWatch(c *check.C) {
&discovery.Entry{Host: "1.1.1.1", Port: "1111"},
}
c.Assert(d.Register("1.1.1.1:1111"), check.IsNil)
c.Assert(<-ch, check.DeepEquals, expected)
assert.Assert(c, d.Register("1.1.1.1:1111"), check.IsNil)
assert.Assert(c, <-ch, check.DeepEquals, expected)
expected = discovery.Entries{
&discovery.Entry{Host: "1.1.1.1", Port: "1111"},
&discovery.Entry{Host: "2.2.2.2", Port: "2222"},
}
c.Assert(d.Register("2.2.2.2:2222"), check.IsNil)
c.Assert(<-ch, check.DeepEquals, expected)
assert.Assert(c, d.Register("2.2.2.2:2222"), check.IsNil)
assert.Assert(c, <-ch, check.DeepEquals, expected)
// Stop and make sure it closes all channels.
close(stopCh)
c.Assert(<-ch, check.IsNil)
c.Assert(<-errCh, check.IsNil)
assert.Assert(c, <-ch, check.IsNil)
assert.Assert(c, <-errCh, check.IsNil)
}

View file

@ -18,20 +18,20 @@ var _ = check.Suite(&DiscoverySuite{})
func (s *DiscoverySuite) TestInitialize(c *check.C) {
d := &Discovery{}
d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil)
c.Assert(len(d.entries), check.Equals, 2)
c.Assert(d.entries[0].String(), check.Equals, "1.1.1.1:1111")
c.Assert(d.entries[1].String(), check.Equals, "2.2.2.2:2222")
assert.Assert(c, len(d.entries), check.Equals, 2)
assert.Assert(c, d.entries[0].String(), check.Equals, "1.1.1.1:1111")
assert.Assert(c, d.entries[1].String(), check.Equals, "2.2.2.2:2222")
}
func (s *DiscoverySuite) TestInitializeWithPattern(c *check.C) {
d := &Discovery{}
d.Initialize("1.1.1.[1:2]:1111,2.2.2.[2:4]:2222", 0, 0, nil)
c.Assert(len(d.entries), check.Equals, 5)
c.Assert(d.entries[0].String(), check.Equals, "1.1.1.1:1111")
c.Assert(d.entries[1].String(), check.Equals, "1.1.1.2:1111")
c.Assert(d.entries[2].String(), check.Equals, "2.2.2.2:2222")
c.Assert(d.entries[3].String(), check.Equals, "2.2.2.3:2222")
c.Assert(d.entries[4].String(), check.Equals, "2.2.2.4:2222")
assert.Assert(c, len(d.entries), check.Equals, 5)
assert.Assert(c, d.entries[0].String(), check.Equals, "1.1.1.1:1111")
assert.Assert(c, d.entries[1].String(), check.Equals, "1.1.1.2:1111")
assert.Assert(c, d.entries[2].String(), check.Equals, "2.2.2.2:2222")
assert.Assert(c, d.entries[3].String(), check.Equals, "2.2.2.3:2222")
assert.Assert(c, d.entries[4].String(), check.Equals, "2.2.2.4:2222")
}
func (s *DiscoverySuite) TestWatch(c *check.C) {
@ -42,10 +42,10 @@ func (s *DiscoverySuite) TestWatch(c *check.C) {
&discovery.Entry{Host: "2.2.2.2", Port: "2222"},
}
ch, _ := d.Watch(nil)
c.Assert(expected.Equals(<-ch), check.Equals, true)
assert.Assert(c, expected.Equals(<-ch), check.Equals, true)
}
func (s *DiscoverySuite) TestRegister(c *check.C) {
d := &Discovery{}
c.Assert(d.Register("0.0.0.0"), check.NotNil)
assert.Assert(c, d.Register("0.0.0.0"), check.NotNil)
}