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

rm-gocheck: HasLen -> assert.Equal + len()

sed -E -i 's#\bassert\.Assert\(c, (.*), checker\.HasLen, (.*)#assert.Equal(c, len(\1), \2#g' \
-- "integration-cli/docker_api_containers_test.go" "integration-cli/docker_cli_by_digest_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_import_test.go" "integration-cli/docker_cli_inspect_test.go" "integration-cli/docker_cli_network_unix_test.go" "integration-cli/docker_cli_ps_test.go" "integration-cli/docker_cli_pull_local_test.go" "integration-cli/docker_cli_service_create_test.go" "integration-cli/docker_cli_swarm_test.go" "integration-cli/docker_cli_userns_test.go" "pkg/discovery/discovery_test.go" "pkg/discovery/file/file_test.go" "pkg/discovery/kv/kv_test.go"

Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 491ef7b901)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Tibor Vass 2019-09-09 21:05:57 +00:00 committed by Sebastiaan van Stijn
parent 17e04aa6c2
commit 7b91af803d
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
16 changed files with 49 additions and 49 deletions

View file

@ -389,7 +389,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *testing.T) {
assert.NilError(c, err)
pausedContainers = getPaused(c)
assert.Assert(c, pausedContainers, checker.HasLen, 0, check.Commentf("There should be no paused container."))
assert.Equal(c, len(pausedContainers), 0, check.Commentf("There should be no paused container."))
}
func (s *DockerSuite) TestContainerAPITop(c *testing.T) {
@ -405,12 +405,12 @@ func (s *DockerSuite) TestContainerAPITop(c *testing.T) {
// sort by comm[andline] to make sure order stays the same in case of PID rollover
top, err := cli.ContainerTop(context.Background(), id, []string{"aux", "--sort=comm"})
assert.NilError(c, err)
assert.Assert(c, top.Titles, checker.HasLen, 11, check.Commentf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles))
assert.Equal(c, len(top.Titles), 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)
}
assert.Assert(c, top.Processes, checker.HasLen, 2, check.Commentf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
assert.Equal(c, len(top.Processes), 2, check.Commentf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
assert.Equal(c, top.Processes[0][10], "/bin/sh -c top")
assert.Equal(c, top.Processes[1][10], "top")
}

View file

@ -151,7 +151,7 @@ func (s *DockerRegistrySuite) TestRunByDigest(c *testing.T) {
foundRegex := regexp.MustCompile("found=([^\n]+)")
matches := foundRegex.FindStringSubmatch(out)
assert.Assert(c, matches, checker.HasLen, 2, check.Commentf("unable to parse digest from pull output: %s", out))
assert.Equal(c, len(matches), 2, check.Commentf("unable to parse digest from pull output: %s", out))
assert.Equal(c, matches[1], "1", check.Commentf("Expected %q, got %q", "1", matches[1]))
res := inspectField(c, containerName, "Config.Image")
@ -401,8 +401,8 @@ func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *testing.T) {
var imageJSON []types.ImageInspect
err = json.Unmarshal([]byte(out), &imageJSON)
assert.NilError(c, err)
assert.Assert(c, imageJSON, checker.HasLen, 1)
assert.Assert(c, imageJSON[0].RepoDigests, checker.HasLen, 1)
assert.Equal(c, len(imageJSON), 1)
assert.Equal(c, len(imageJSON[0].RepoDigests), 1)
assert.Check(c, is.Contains(imageJSON[0].RepoDigests, imageReference))
}

View file

@ -123,10 +123,10 @@ func (s *DockerSuite) TestCreateWithPortRange(c *testing.T) {
cont := containers[0]
assert.Assert(c, cont.HostConfig, checker.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)))
assert.Equal(c, len(cont.HostConfig.PortBindings), 4, check.Commentf("Expected 4 ports bindings, got %d", len(cont.HostConfig.PortBindings)))
for k, v := range cont.HostConfig.PortBindings {
assert.Assert(c, v, checker.HasLen, 1, check.Commentf("Expected 1 ports binding, for the port %s but found %s", k, v))
assert.Equal(c, len(v), 1, check.Commentf("Expected 1 ports binding, for the port %s but found %s", k, v))
assert.Equal(c, k.Port(), v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
}
@ -152,10 +152,10 @@ func (s *DockerSuite) TestCreateWithLargePortRange(c *testing.T) {
cont := containers[0]
assert.Assert(c, cont.HostConfig, checker.NotNil, check.Commentf("Expected HostConfig, got none"))
assert.Assert(c, cont.HostConfig.PortBindings, checker.HasLen, 65535)
assert.Equal(c, len(cont.HostConfig.PortBindings), 65535)
for k, v := range cont.HostConfig.PortBindings {
assert.Assert(c, v, checker.HasLen, 1)
assert.Equal(c, len(v), 1)
assert.Equal(c, k.Port(), v[0].HostPort, check.Commentf("Expected host port %s to match published port %s", k.Port(), v[0].HostPort))
}

View file

@ -1726,7 +1726,7 @@ func (s *DockerDaemonSuite) TestDaemonStartWithDefaultTLSHost(c *testing.T) {
conn.Close()
assert.Assert(c, certRequestInfo, checker.NotNil)
assert.Assert(c, certRequestInfo.AcceptableCAs, checker.HasLen, 1)
assert.Equal(c, len(certRequestInfo.AcceptableCAs), 1)
assert.DeepEqual(c, certRequestInfo.AcceptableCAs[0], rootCert.RawSubject)
}

View file

@ -488,8 +488,8 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *testing.T) {
var st []vol
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.Equal(c, len(st), 1)
assert.Equal(c, len(st[0].Status), 1, check.Commentf("%v", st[0]))
assert.Equal(c, st[0].Status["Hello"], "world", check.Commentf("%v", st[0].Status))
}
@ -500,7 +500,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c
dockerCmd(c, "run", "--name=test", "-v", "abc1:/foo", "busybox", "true")
var mounts []types.MountPoint
inspectFieldAndUnmarshall(c, "test", "Mounts", &mounts)
assert.Assert(c, mounts, checker.HasLen, 1)
assert.Equal(c, len(mounts), 1)
assert.Equal(c, mounts[0].Driver, volumePluginName)
}
@ -583,7 +583,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *t
var vs []types.Volume
err = json.Unmarshal([]byte(out), &vs)
assert.NilError(c, err)
assert.Assert(c, vs, checker.HasLen, 1)
assert.Equal(c, len(vs), 1)
assert.Equal(c, vs[0].Driver, driverName)
assert.Assert(c, vs[0].Options, checker.NotNil)
assert.Equal(c, vs[0].Options["foo"], "bar")
@ -601,8 +601,8 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *t
vs = nil
err = json.Unmarshal([]byte(out), &vs)
assert.NilError(c, err)
assert.Assert(c, vs, checker.HasLen, 1)
assert.Assert(c, vs[0].Options, checker.HasLen, 0)
assert.Equal(c, len(vs), 1)
assert.Equal(c, len(vs[0].Options), 0)
assert.Equal(c, vs[0].Driver, "local")
}

View file

@ -110,7 +110,7 @@ func (s *DockerSuite) TestImportFileWithMessage(c *testing.T) {
out, _ = dockerCmd(c, "history", image)
split := strings.Split(out, "\n")
assert.Assert(c, split, checker.HasLen, 3, check.Commentf("expected 3 lines from image history"))
assert.Equal(c, len(split), 3, check.Commentf("expected 3 lines from image history"))
r := regexp.MustCompile("[\\s]{2,}")
split = r.Split(split[1], -1)

View file

@ -223,7 +223,7 @@ func (s *DockerSuite) TestInspectBindMountPoint(c *testing.T) {
assert.NilError(c, err)
// check that there is only one mountpoint
assert.Assert(c, mp, checker.HasLen, 1)
assert.Equal(c, len(mp), 1)
m := mp[0]
@ -249,7 +249,7 @@ func (s *DockerSuite) TestInspectNamedMountPoint(c *testing.T) {
assert.NilError(c, err)
// check that there is only one mountpoint
assert.Assert(c, mp, checker.HasLen, 1)
assert.Equal(c, len(mp), 1)
m := mp[0]

View file

@ -530,7 +530,7 @@ func (s *DockerSuite) TestDockerInspectNetworkWithContainerName(c *testing.T) {
var newNetRes []types.NetworkResource
err = json.Unmarshal([]byte(out), &newNetRes)
assert.NilError(c, err)
assert.Assert(c, newNetRes, checker.HasLen, 1)
assert.Equal(c, len(newNetRes), 1)
container1, ok := newNetRes[0].Containers[containerID]
assert.Assert(c, ok)
assert.Equal(c, container1.Name, newName)
@ -1034,7 +1034,7 @@ func (s *DockerSuite) TestInspectAPIMultipleNetworks(c *testing.T) {
var inspect121 types.ContainerJSON
err = json.Unmarshal(body, &inspect121)
assert.NilError(c, err)
assert.Assert(c, inspect121.NetworkSettings.Networks, checker.HasLen, 3)
assert.Equal(c, len(inspect121.NetworkSettings.Networks), 3)
bridge := inspect121.NetworkSettings.Networks["bridge"]
assert.Equal(c, bridge.IPAddress, versionedIP)

View file

@ -386,7 +386,7 @@ func checkPsAncestorFilterOutput(c *testing.T, out string, filterName string, ex
sort.Strings(actualIDs)
sort.Strings(expectedIDs)
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))
assert.Equal(c, len(actualIDs), len(expectedIDs), check.Commentf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs))
if len(expectedIDs) > 0 {
same := true
for i := range expectedIDs {
@ -665,7 +665,7 @@ func (s *DockerSuite) TestPsShowMounts(c *testing.T) {
// empty results filtering by unknown volume
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume=this-volume-should-not-exist")
assert.Assert(c, strings.TrimSpace(string(out)), checker.HasLen, 0)
assert.Equal(c, len(strings.TrimSpace(string(out))), 0)
// filter by mount destination
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+mp)
@ -705,7 +705,7 @@ func (s *DockerSuite) TestPsShowMounts(c *testing.T) {
// empty results filtering by unknown mount point
out, _ = dockerCmd(c, "ps", "--format", "{{.Names}} {{.Mounts}}", "--filter", "volume="+prefix+slash+"this-path-was-never-mounted")
assert.Assert(c, strings.TrimSpace(string(out)), checker.HasLen, 0)
assert.Equal(c, len(strings.TrimSpace(string(out))), 0)
}
func (s *DockerSuite) TestPsListContainersFilterNetwork(c *testing.T) {

View file

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

View file

@ -42,7 +42,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
var mountConfig []mount.Mount
assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
assert.Assert(c, mountConfig, checker.HasLen, 1)
assert.Equal(c, len(mountConfig), 1)
assert.Equal(c, mountConfig[0].Source, "foo")
assert.Equal(c, mountConfig[0].Target, "/foo")
@ -56,7 +56,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
var mounts []types.MountPoint
assert.Assert(c, json.Unmarshal([]byte(out), &mounts), checker.IsNil)
assert.Assert(c, mounts, checker.HasLen, 1)
assert.Equal(c, len(mounts), 1)
assert.Equal(c, mounts[0].Type, mount.TypeVolume)
assert.Equal(c, mounts[0].Name, "foo")
@ -385,7 +385,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) {
var mountConfig []mount.Mount
assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig), checker.IsNil)
assert.Assert(c, mountConfig, checker.HasLen, 1)
assert.Equal(c, len(mountConfig), 1)
assert.Equal(c, mountConfig[0].Source, "")
assert.Equal(c, mountConfig[0].Target, "/foo")
@ -399,7 +399,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) {
var mounts []types.MountPoint
assert.Assert(c, json.Unmarshal([]byte(out), &mounts), checker.IsNil)
assert.Assert(c, mounts, checker.HasLen, 1)
assert.Equal(c, len(mounts), 1)
assert.Equal(c, mounts[0].Type, mount.TypeTmpfs)
assert.Equal(c, mounts[0].Name, "")
@ -442,7 +442,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *testing.T) {
// Make sure the only alias seen is the container-id
var aliases []string
assert.Assert(c, json.Unmarshal([]byte(out), &aliases), checker.IsNil)
assert.Assert(c, aliases, checker.HasLen, 1)
assert.Equal(c, len(aliases), 1)
assert.Assert(c, task.Status.ContainerStatus.ContainerID, checker.Contains, aliases[0])
}

View file

@ -65,7 +65,7 @@ func (s *DockerSwarmSuite) TestSwarmUpdate(c *testing.T) {
assert.NilError(c, err)
spec = getSpec()
assert.Assert(c, spec.CAConfig.ExternalCAs, checker.HasLen, 2)
assert.Equal(c, len(spec.CAConfig.ExternalCAs), 2)
assert.Equal(c, spec.CAConfig.ExternalCAs[0].CACert, "")
assert.Equal(c, spec.CAConfig.ExternalCAs[1].CACert, string(expected))
@ -113,7 +113,7 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *testing.T) {
spec := getSpec()
assert.Equal(c, spec.CAConfig.NodeCertExpiry, 30*time.Hour)
assert.Equal(c, spec.Dispatcher.HeartbeatPeriod, 11*time.Second)
assert.Assert(c, spec.CAConfig.ExternalCAs, checker.HasLen, 2)
assert.Equal(c, len(spec.CAConfig.ExternalCAs), 2)
assert.Equal(c, spec.CAConfig.ExternalCAs[0].CACert, "")
assert.Equal(c, spec.CAConfig.ExternalCAs[1].CACert, string(expected))

View file

@ -38,7 +38,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
// we need to find the uid and gid of the remapped root from the daemon's root dir info
uidgid := strings.Split(filepath.Base(s.d.Root), ".")
assert.Assert(c, uidgid, checker.HasLen, 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.Root)))
assert.Equal(c, len(uidgid), 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.Root)))
uid, err := strconv.Atoi(uidgid[0])
assert.NilError(c, err, "Can't parse uid")
gid, err := strconv.Atoi(uidgid[1])

View file

@ -110,25 +110,25 @@ func (s *DiscoverySuite) TestEntriesDiff(c *testing.T) {
// No diff
added, removed := entries.Diff(Entries{entry2, entry1})
assert.Assert(c, added, checker.HasLen, 0)
assert.Assert(c, removed, checker.HasLen, 0)
assert.Equal(c, len(added), 0)
assert.Equal(c, len(removed), 0)
// Add
added, removed = entries.Diff(Entries{entry2, entry3, entry1})
assert.Assert(c, added, checker.HasLen, 1)
assert.Equal(c, len(added), 1)
assert.Equal(c, added.Contains(entry3), true)
assert.Assert(c, removed, checker.HasLen, 0)
assert.Equal(c, len(removed), 0)
// Remove
added, removed = entries.Diff(Entries{entry2})
assert.Assert(c, added, checker.HasLen, 0)
assert.Assert(c, removed, checker.HasLen, 1)
assert.Equal(c, len(added), 0)
assert.Equal(c, len(removed), 1)
assert.Equal(c, removed.Contains(entry1), true)
// Add and remove
added, removed = entries.Diff(Entries{entry1, entry3})
assert.Assert(c, added, checker.HasLen, 1)
assert.Equal(c, len(added), 1)
assert.Equal(c, added.Contains(entry3), true)
assert.Assert(c, removed, checker.HasLen, 1)
assert.Equal(c, len(removed), 1)
assert.Equal(c, removed.Contains(entry2), true)
}

View file

@ -35,7 +35,7 @@ func (s *DiscoverySuite) TestContent(c *testing.T) {
2.2.2.[2:4]:2222
`
ips := parseFileContent([]byte(data))
assert.Assert(c, ips, checker.HasLen, 5)
assert.Equal(c, len(ips), 5)
assert.Equal(c, ips[0], "1.1.1.1:1111")
assert.Equal(c, ips[1], "1.1.1.2:1111")
assert.Equal(c, ips[2], "2.2.2.2:2222")
@ -58,7 +58,7 @@ func (s *DiscoverySuite) TestParsingContentsWithComments(c *testing.T) {
### test ###
`
ips := parseFileContent([]byte(data))
assert.Assert(c, ips, checker.HasLen, 2)
assert.Equal(c, len(ips), 2)
assert.Equal(c, "1.1.1.1:1111", ips[0])
assert.Equal(c, "3.3.3.3:3333", ips[1])
}

View file

@ -30,7 +30,7 @@ func (ds *DiscoverySuite) TestInitialize(c *testing.T) {
d.store = storeMock
s := d.store.(*FakeStore)
assert.Assert(c, s.Endpoints, checker.HasLen, 1)
assert.Equal(c, len(s.Endpoints), 1)
assert.Equal(c, s.Endpoints[0], "127.0.0.1")
assert.Equal(c, d.path, defaultDiscoveryPath)
@ -42,7 +42,7 @@ func (ds *DiscoverySuite) TestInitialize(c *testing.T) {
d.store = storeMock
s = d.store.(*FakeStore)
assert.Assert(c, s.Endpoints, checker.HasLen, 1)
assert.Equal(c, len(s.Endpoints), 1)
assert.Equal(c, s.Endpoints[0], "127.0.0.1:1234")
assert.Equal(c, d.path, "path/"+defaultDiscoveryPath)
@ -54,7 +54,7 @@ func (ds *DiscoverySuite) TestInitialize(c *testing.T) {
d.store = storeMock
s = d.store.(*FakeStore)
assert.Assert(c, s.Endpoints, checker.HasLen, 3)
assert.Equal(c, len(s.Endpoints), 3)
assert.Equal(c, s.Endpoints[0], "127.0.0.1:1234")
assert.Equal(c, s.Endpoints[1], "127.0.0.2:1234")
assert.Equal(c, s.Endpoints[2], "127.0.0.3:1234")
@ -202,7 +202,7 @@ BFrwkQE4HQtQBV60hYQUzzlSk44VFDz+jxIEtacRHaomDRh2FtOTz+I=
s := d.store.(*Mock)
assert.Assert(c, s.Options.TLS, checker.NotNil)
assert.Assert(c, s.Options.TLS.RootCAs, checker.NotNil)
assert.Assert(c, s.Options.TLS.Certificates, checker.HasLen, 1)
assert.Equal(c, len(s.Options.TLS.Certificates), 1)
}
func (ds *DiscoverySuite) TestWatch(c *testing.T) {