From 0553d3d9946381ce7833fe646b4a3642381b7ec4 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Thu, 21 Nov 2024 18:31:04 +1100 Subject: [PATCH] tests: migrate away from assert.Assert(err == nil) Unfortunately, gofmt doesn't know about types so it was necessary to find all of the err == nil statements through trial and error. Note that there is no is.NilError, so for assert.Check(t, err == nil) we need to switch to just doing assert.Check(t, err). If err is an error type, this is equivalent (and there isn't another trivial way of doing it). Here are the full set of rules used: Generic "err == nil": find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, err == nil) -> assert.NilError(t, err)" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, err == nil) -> assert.Check(t, err)" Generic, but with a different variable name: find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, sr.err == nil) -> assert.NilError(t, sr.err)" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, sr.err == nil) -> assert.Check(t, sr.err)" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, err2 == nil) -> assert.NilError(t, err2)" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, err2 == nil) -> assert.Check(t, err2)" JSON-related error assertions: find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, json.Unmarshal(a, b) == nil) -> assert.NilError(t, json.Unmarshal(a, b))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, json.Unmarshal(a, b) == nil) -> assert.Check(t, json.Unmarshal(a, b))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, json.NewDecoder(a).Decode(b) == nil) -> assert.NilError(t, json.NewDecoder(a).Decode(b))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, json.NewDecoder(a).Decode(b) == nil) -> assert.Check(t, json.NewDecoder(a).Decode(b))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, json.NewEncoder(a).Encode(b) == nil) -> assert.NilError(t, json.NewEncoder(a).Encode(b))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, json.NewEncoder(a).Encode(b) == nil) -> assert.Check(t, json.NewEncoder(a).Encode(b))" Process-related error assertions: find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, a.Start() == nil) -> assert.NilError(t, a.Start())" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, a.Start() == nil) -> assert.Check(t, a.Start())" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, a.Kill() == nil) -> assert.NilError(t, a.Kill())" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, a.Kill() == nil) -> assert.Check(t, a.Kill())" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, a.Signal(b) == nil) -> assert.NilError(t, a.Signal(b))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, a.Signal(b) == nil) -> assert.Check(t, a.Signal(b))" waitInspect: find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, waitInspect(a, b, c, d) == nil) -> assert.NilError(t, waitInspect(a, b, c, d))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, waitInspect(a, b, c, d) == nil) -> assert.Check(t, waitInspect(a, b, c, d))" File closing error assertions: find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, a.Close() == nil) -> assert.NilError(t, a.Close())" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, a.Close() == nil) -> assert.Check(t, a.Close())" mount.MakeRShared: find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, mount.MakeRShared(a) == nil) -> assert.NilError(t, mount.MakeRShared(a))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, mount.MakeRShared(a) == nil) -> assert.Check(t, mount.MakeRShared(a))" daemon.SwarmLeave: find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, d.SwarmLeave(a, b, c) == nil) -> assert.NilError(t, d.SwarmLeave(a, b, c))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, d.SwarmLeave(a, b, c) == nil) -> assert.Check(t, d.SwarmLeave(a, b, c))" os.MkdirAll: find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Assert(t, os.MkdirAll(a, b) == nil) -> assert.NilError(t, os.MkdirAll(a, b))" find . -type f -name "*_test.go" | \ xargs gofmt -w -r "assert.Check(t, os.MkdirAll(a, b) == nil) -> assert.Check(t, os.MkdirAll(a, b))" Signed-off-by: Aleksa Sarai --- daemon/list_test.go | 4 ++-- integration-cli/docker_api_containers_test.go | 16 +++++++------- integration-cli/docker_cli_attach_test.go | 4 ++-- integration-cli/docker_cli_build_test.go | 4 ++-- integration-cli/docker_cli_by_digest_test.go | 8 +++---- integration-cli/docker_cli_daemon_test.go | 20 ++++++++--------- .../docker_cli_external_volume_driver_test.go | 8 +++---- .../docker_cli_network_unix_test.go | 6 ++--- integration-cli/docker_cli_run_test.go | 2 +- .../docker_cli_service_create_test.go | 22 +++++++++---------- integration-cli/docker_cli_swarm_test.go | 4 ++-- integration-cli/docker_utils_test.go | 4 ++-- integration/network/macvlan/macvlan_test.go | 10 ++++----- volume/service/service_test.go | 2 +- 14 files changed, 57 insertions(+), 57 deletions(-) diff --git a/daemon/list_test.go b/daemon/list_test.go index 78292b3f22..cb2b6e8589 100644 --- a/daemon/list_test.go +++ b/daemon/list_test.go @@ -81,7 +81,7 @@ func containerListContainsName(containers []*containertypes.Summary, name string func TestListInvalidFilter(t *testing.T) { db, err := container.NewViewDB() - assert.Assert(t, err == nil) + assert.NilError(t, err) d := &Daemon{ containersReplica: db, } @@ -94,7 +94,7 @@ func TestListInvalidFilter(t *testing.T) { func TestNameFilter(t *testing.T) { db, err := container.NewViewDB() - assert.Assert(t, err == nil) + assert.NilError(t, err) d := &Daemon{ containersReplica: db, } diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 384bc1d0ae..6ff2357ae2 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -624,7 +624,7 @@ func (s *DockerAPISuite) TestContainerAPIVerifyHeader(c *testing.T) { create := func(ct string) (*http.Response, io.ReadCloser, error) { jsonData := bytes.NewBuffer(nil) - assert.Assert(c, json.NewEncoder(jsonData).Encode(config) == nil) + assert.NilError(c, json.NewEncoder(jsonData).Encode(config)) return request.Post(testutil.GetContext(c), "/containers/create", request.RawContent(io.NopCloser(jsonData)), request.ContentType(ct)) } @@ -782,7 +782,7 @@ func (s *DockerAPISuite) TestContainerAPIPostCreateNull(c *testing.T) { ID string } var ctr createResp - assert.Assert(c, json.Unmarshal(b, &ctr) == nil) + assert.NilError(c, json.Unmarshal(b, &ctr)) out := inspectField(c, ctr.ID, "HostConfig.CpusetCpus") assert.Equal(c, out, "") @@ -808,7 +808,7 @@ func (s *DockerAPISuite) TestCreateWithTooLowMemoryLimit(c *testing.T) { res, body, err := request.Post(testutil.GetContext(c), "/containers/create", request.RawString(config), request.JSON) assert.NilError(c, err) b, err2 := request.ReadBody(body) - assert.Assert(c, err2 == nil) + assert.NilError(c, err2) assert.Equal(c, res.StatusCode, http.StatusBadRequest) assert.Assert(c, is.Contains(string(b), "Minimum memory limit allowed is 6MB")) @@ -856,7 +856,7 @@ func (s *DockerAPISuite) TestContainerAPIRestart(c *testing.T) { err = apiClient.ContainerRestart(testutil.GetContext(c), name, container.StopOptions{Timeout: &timeout}) assert.NilError(c, err) - assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil) + assert.NilError(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second)) } func (s *DockerAPISuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) { @@ -871,7 +871,7 @@ func (s *DockerAPISuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) { err = apiClient.ContainerRestart(testutil.GetContext(c), name, container.StopOptions{}) assert.NilError(c, err) - assert.Assert(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second) == nil) + assert.NilError(c, waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second)) } func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) { @@ -913,7 +913,7 @@ func (s *DockerAPISuite) TestContainerAPIStop(c *testing.T) { Timeout: &timeout, }) assert.NilError(c, err) - assert.Assert(c, waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second) == nil) + assert.NilError(c, waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second)) // second call to start should give 304 // maybe add ContainerStartWithRaw to test it @@ -1075,7 +1075,7 @@ func (s *DockerAPISuite) TestContainerAPIPostContainerStop(c *testing.T) { err = apiClient.ContainerStop(testutil.GetContext(c), containerID, container.StopOptions{}) assert.NilError(c, err) - assert.Assert(c, waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second) == nil) + assert.NilError(c, waitInspect(containerID, "{{ .State.Running }}", "false", 60*time.Second)) } // #14170 @@ -1437,7 +1437,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) case <-time.After(2 * time.Second): c.Fatal("stream was not closed after container was removed") case sr := <-bc: - assert.Assert(c, sr.err == nil) + assert.NilError(c, sr.err) sr.stats.Body.Close() } } diff --git a/integration-cli/docker_cli_attach_test.go b/integration-cli/docker_cli_attach_test.go index 1137b1d37d..a54d12f1d3 100644 --- a/integration-cli/docker_cli_attach_test.go +++ b/integration-cli/docker_cli_attach_test.go @@ -166,7 +166,7 @@ func (s *DockerCLIAttachSuite) TestAttachDisconnect(c *testing.T) { stdout, err := cmd.StdoutPipe() assert.NilError(c, err) defer stdout.Close() - assert.Assert(c, cmd.Start() == nil) + assert.NilError(c, cmd.Start()) defer func() { cmd.Process.Kill() cmd.Wait() @@ -178,7 +178,7 @@ func (s *DockerCLIAttachSuite) TestAttachDisconnect(c *testing.T) { assert.NilError(c, err) assert.Equal(c, strings.TrimSpace(out), "hello") - assert.Assert(c, stdin.Close() == nil) + assert.NilError(c, stdin.Close()) // Expect container to still be running after stdin is closed running := inspectField(c, id, "State.Running") diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 1ba2978ea5..77bfbbec52 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -5457,8 +5457,8 @@ func (s *DockerCLIBuildSuite) TestBuildCacheFrom(c *testing.T) { var layers1 []string var layers2 []string - assert.Assert(c, json.Unmarshal([]byte(layers1Str), &layers1) == nil) - assert.Assert(c, json.Unmarshal([]byte(layers2Str), &layers2) == nil) + assert.NilError(c, json.Unmarshal([]byte(layers1Str), &layers1)) + assert.NilError(c, json.Unmarshal([]byte(layers2Str), &layers2)) assert.Equal(c, len(layers1), len(layers2)) for i := 0; i < len(layers1)-1; i++ { diff --git a/integration-cli/docker_cli_by_digest_test.go b/integration-cli/docker_cli_by_digest_test.go index a0713d762c..8eb5dee6d7 100644 --- a/integration-cli/docker_cli_by_digest_test.go +++ b/integration-cli/docker_cli_by_digest_test.go @@ -630,14 +630,14 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *testing.T) { skip.If(c, testEnv.UsingSnapshotter(), "Faked layer is already in the content store, so it won't be fetched from the repository at all.") manifestDigest, err := setupImage(c) - assert.Assert(c, err == nil) + assert.NilError(c, err) // Load the target manifest blob. manifestBlob := s.reg.ReadBlobContents(c, manifestDigest) var imgManifest schema2.Manifest err = json.Unmarshal(manifestBlob, &imgManifest) - assert.Assert(c, err == nil) + assert.NilError(c, err) // Next, get the digest of one of the layers from the manifest. targetLayerDigest := imgManifest.Layers[0].Digest @@ -673,14 +673,14 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *testing.T) { func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *testing.T) { testRequires(c, DaemonIsLinux) manifestDigest, err := setupImage(c) - assert.Assert(c, err == nil) + assert.NilError(c, err) // Load the target manifest blob. manifestBlob := s.reg.ReadBlobContents(c, manifestDigest) var imgManifest schema1.Manifest err = json.Unmarshal(manifestBlob, &imgManifest) - assert.Assert(c, err == nil) + assert.NilError(c, err) // Next, get the digest of one of the layers from the manifest. targetLayerDigest := imgManifest.FSLayers[0].BlobSum diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 24a4341bd8..2c97c02e4e 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -1578,7 +1578,7 @@ func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *testing.T) { testDir, err := os.MkdirTemp("", "no-space-left-on-device-test") assert.NilError(c, err) defer os.RemoveAll(testDir) - assert.Assert(c, mount.MakeRShared(testDir) == nil) + assert.NilError(c, mount.MakeRShared(testDir)) defer mount.Unmount(testDir) // create a 3MiB image (with a 2MiB ext4 fs) and mount it as storage root @@ -1828,7 +1828,7 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *testing.T) { id := strings.TrimSpace(out) // kill the daemon - assert.Assert(c, s.d.Kill() == nil) + assert.NilError(c, s.d.Kill()) // 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 @@ -2064,7 +2064,7 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFile(c *testing.T) assert.Assert(c, is.Contains(string(content), expectedMaxConcurrentDownloads)) err = os.WriteFile(configFilePath, []byte(`{ "max-concurrent-uploads" : 7, "max-concurrent-downloads" : 9 }`), 0o666) assert.NilError(c, err) - assert.Assert(c, s.d.Signal(unix.SIGHUP) == nil) + assert.NilError(c, s.d.Signal(unix.SIGHUP)) // unix.Kill(s.d.cmd.Process.Pid, unix.SIGHUP) time.Sleep(3 * time.Second) @@ -2100,7 +2100,7 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *test err = os.WriteFile(configFilePath, []byte(`{ "max-concurrent-uploads" : 1, "max-concurrent-downloads" : null }`), 0o666) assert.NilError(c, err) - assert.Assert(c, s.d.Signal(unix.SIGHUP) == nil) + assert.NilError(c, s.d.Signal(unix.SIGHUP)) // unix.Kill(s.d.cmd.Process.Pid, unix.SIGHUP) time.Sleep(3 * time.Second) @@ -2114,7 +2114,7 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *test err = os.WriteFile(configFilePath, []byte(`{ "labels":["foo=bar"] }`), 0o666) assert.NilError(c, err) - assert.Assert(c, s.d.Signal(unix.SIGHUP) == nil) + assert.NilError(c, s.d.Signal(unix.SIGHUP)) time.Sleep(3 * time.Second) @@ -2204,7 +2204,7 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *testing.T) { } ` os.WriteFile(configName, []byte(config), 0o644) - assert.Assert(c, s.d.Signal(unix.SIGHUP) == nil) + assert.NilError(c, s.d.Signal(unix.SIGHUP)) // Give daemon time to reload config <-time.After(1 * time.Second) @@ -2231,7 +2231,7 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *testing.T) { } ` os.WriteFile(configName, []byte(config), 0o644) - assert.Assert(c, s.d.Signal(unix.SIGHUP) == nil) + assert.NilError(c, s.d.Signal(unix.SIGHUP)) // Give daemon time to reload config <-time.After(1 * time.Second) @@ -2256,7 +2256,7 @@ func (s *DockerDaemonSuite) TestRunWithRuntimeFromConfigFile(c *testing.T) { } ` os.WriteFile(configName, []byte(config), 0o644) - assert.Assert(c, s.d.Signal(unix.SIGHUP) == nil) + assert.NilError(c, s.d.Signal(unix.SIGHUP)) // Give daemon time to reload config <-time.After(1 * time.Second) @@ -2433,7 +2433,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownTimeout(c *testing.T) { _, err := s.d.Cmd("run", "-d", "busybox", "top") assert.NilError(c, err) - assert.Assert(c, s.d.Signal(unix.SIGINT) == nil) + assert.NilError(c, s.d.Signal(unix.SIGINT)) select { case <-s.d.Wait: @@ -2461,7 +2461,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownTimeoutWithConfigFile(c *testing.T err = os.WriteFile(configFilePath, []byte(`{ "shutdown-timeout" : 5 }`), 0o666) assert.NilError(c, err) - assert.Assert(c, s.d.Signal(unix.SIGHUP) == nil) + assert.NilError(c, s.d.Signal(unix.SIGHUP)) select { case <-s.d.Wait: diff --git a/integration-cli/docker_cli_external_volume_driver_test.go b/integration-cli/docker_cli_external_volume_driver_test.go index 0123146590..6fba45b9a3 100644 --- a/integration-cli/docker_cli_external_volume_driver_test.go +++ b/integration-cli/docker_cli_external_volume_driver_test.go @@ -378,10 +378,10 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverLookupNotBlocked(c * cmd1 := exec.Command(dockerBinary, "volume", "create", "-d", "down-driver") cmd2 := exec.Command(dockerBinary, "volume", "create") - assert.Assert(c, cmd1.Start() == nil) + assert.NilError(c, cmd1.Start()) defer cmd1.Process.Kill() time.Sleep(100 * time.Millisecond) // ensure API has been called - assert.Assert(c, cmd2.Start() == nil) + assert.NilError(c, cmd2.Start()) go func() { cmd1.Wait() @@ -450,7 +450,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverBindExternalVolume(c Driver string } out := inspectFieldJSON(c, "testing", "Mounts") - assert.Assert(c, json.NewDecoder(strings.NewReader(out)).Decode(&mounts) == nil) + assert.NilError(c, json.NewDecoder(strings.NewReader(out)).Decode(&mounts)) assert.Equal(c, len(mounts), 1, out) assert.Equal(c, mounts[0].Name, "foo") assert.Equal(c, mounts[0].Driver, volumePluginName) @@ -484,7 +484,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverGet(c *testing.T) { } var st []vol - assert.Assert(c, json.Unmarshal([]byte(out), &st) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &st)) assert.Equal(c, len(st), 1) assert.Equal(c, len(st[0].Status), 1, fmt.Sprintf("%v", st[0])) assert.Equal(c, st[0].Status["Hello"], "world", fmt.Sprintf("%v", st[0].Status)) diff --git a/integration-cli/docker_cli_network_unix_test.go b/integration-cli/docker_cli_network_unix_test.go index 83c8b1b295..a12fa0338f 100644 --- a/integration-cli/docker_cli_network_unix_test.go +++ b/integration-cli/docker_cli_network_unix_test.go @@ -991,7 +991,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkDriverUngracefulRestart(c *testing assert.NilError(c, err) // Kill daemon and restart - assert.Assert(c, s.d.Kill() == nil) + assert.NilError(c, s.d.Kill()) server.Close() @@ -1106,7 +1106,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkMultipleNetworksUngracefulDaemonRe verifyContainerIsConnectedToNetworks(c, s.d, cName, nwList) // Kill daemon and restart - assert.Assert(c, s.d.Kill() == nil) + assert.NilError(c, s.d.Kill()) s.d.Restart(c) // Restart container @@ -1139,7 +1139,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkHostModeUngracefulDaemonRestart(c } // Kill daemon ungracefully and restart - assert.Assert(c, s.d.Kill() == nil) + assert.NilError(c, s.d.Kill()) s.d.Restart(c) // make sure all the containers are up and running diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index aa7f12e978..940c0bdbee 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -3588,7 +3588,7 @@ func (s *DockerCLIRunSuite) TestRunStdinBlockedAfterContainerExit(c *testing.T) stdout := bytes.NewBuffer(nil) cmd.Stdout = stdout cmd.Stderr = stdout - assert.Assert(c, cmd.Start() == nil) + assert.NilError(c, cmd.Start()) waitChan := make(chan error, 1) go func() { diff --git a/integration-cli/docker_cli_service_create_test.go b/integration-cli/docker_cli_service_create_test.go index 4bdd7f69b6..2c12796127 100644 --- a/integration-cli/docker_cli_service_create_test.go +++ b/integration-cli/docker_cli_service_create_test.go @@ -45,7 +45,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) { assert.NilError(c, err, out) var mountConfig []mount.Mount - assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &mountConfig)) assert.Equal(c, len(mountConfig), 1) assert.Equal(c, mountConfig[0].Source, "foo") @@ -59,7 +59,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) { assert.NilError(c, err, out) var mounts []container.MountPoint - assert.Assert(c, json.Unmarshal([]byte(out), &mounts) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &mounts)) assert.Equal(c, len(mounts), 1) assert.Equal(c, mounts[0].Type, mount.TypeVolume) @@ -89,7 +89,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSimple(c *testing.T) { assert.NilError(c, err) var refs []swarm.SecretReference - assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &refs)) assert.Equal(c, len(refs), 1) assert.Equal(c, refs[0].SecretName, testName) @@ -139,7 +139,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *testi assert.NilError(c, err) var refs []swarm.SecretReference - assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &refs)) assert.Equal(c, len(refs), len(testPaths)) var tasks []swarm.Task @@ -190,7 +190,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *testing assert.NilError(c, err) var refs []swarm.SecretReference - assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &refs)) assert.Equal(c, len(refs), 2) var tasks []swarm.Task @@ -240,7 +240,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSimple(c *testing.T) { assert.NilError(c, err) var refs []swarm.ConfigReference - assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &refs)) assert.Equal(c, len(refs), 1) assert.Equal(c, refs[0].ConfigName, testName) @@ -289,7 +289,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *testi assert.NilError(c, err) var refs []swarm.ConfigReference - assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &refs)) assert.Equal(c, len(refs), len(testPaths)) var tasks []swarm.Task @@ -340,7 +340,7 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *testing assert.NilError(c, err) var refs []swarm.ConfigReference - assert.Assert(c, json.Unmarshal([]byte(out), &refs) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &refs)) assert.Equal(c, len(refs), 2) var tasks []swarm.Task @@ -395,7 +395,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) { assert.NilError(c, err, out) var mountConfig []mount.Mount - assert.Assert(c, json.Unmarshal([]byte(out), &mountConfig) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &mountConfig)) assert.Equal(c, len(mountConfig), 1) assert.Equal(c, mountConfig[0].Source, "") @@ -409,7 +409,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) { assert.NilError(c, err, out) var mounts []container.MountPoint - assert.Assert(c, json.Unmarshal([]byte(out), &mounts) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &mounts)) assert.Equal(c, len(mounts), 1) assert.Equal(c, mounts[0].Type, mount.TypeTmpfs) @@ -453,7 +453,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) == nil) + assert.NilError(c, json.Unmarshal([]byte(out), &aliases)) assert.Equal(c, len(aliases), 1) assert.Assert(c, is.Contains(task.Status.ContainerStatus.ContainerID, aliases[0])) diff --git a/integration-cli/docker_cli_swarm_test.go b/integration-cli/docker_cli_swarm_test.go index 858b407c05..5989e629eb 100644 --- a/integration-cli/docker_cli_swarm_test.go +++ b/integration-cli/docker_cli_swarm_test.go @@ -123,7 +123,7 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *testing.T) { assert.Equal(c, spec.CAConfig.ExternalCAs[0].CACert, "") assert.Equal(c, spec.CAConfig.ExternalCAs[1].CACert, string(expected)) - assert.Assert(c, d.SwarmLeave(ctx, c, true) == nil) + assert.NilError(c, d.SwarmLeave(ctx, c, true)) cli.Docker(cli.Args("swarm", "init"), cli.Daemon(d)).Assert(c, icmd.Success) spec = getSpec() @@ -443,7 +443,7 @@ func (s *DockerSwarmSuite) TestOverlayAttachableOnSwarmLeave(c *testing.T) { assert.NilError(c, err, out) // Leave the swarm - assert.Assert(c, d.SwarmLeave(ctx, c, true) == nil) + assert.NilError(c, d.SwarmLeave(ctx, c, true)) // Check the container is disconnected out, err = d.Cmd("inspect", "c1", "--format", "{{.NetworkSettings.Networks."+nwName+"}}") diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index e0ce4b7266..490188c5ae 100644 --- a/integration-cli/docker_utils_test.go +++ b/integration-cli/docker_utils_test.go @@ -177,7 +177,7 @@ func buildImage(name string, cmdOperators ...cli.CmdOperator) *icmd.Result { func writeFile(dst, content string, c *testing.T) { c.Helper() // Create subdirectories if necessary - assert.Assert(c, os.MkdirAll(path.Dir(dst), 0o700) == nil) + assert.NilError(c, os.MkdirAll(path.Dir(dst), 0o700)) f, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o600) assert.NilError(c, err) defer f.Close() @@ -408,7 +408,7 @@ func waitForGoroutines(ctx context.Context, t poll.TestingT, apiClient client.AP func getErrorMessage(c *testing.T, body []byte) string { c.Helper() var resp types.ErrorResponse - assert.Assert(c, json.Unmarshal(body, &resp) == nil) + assert.NilError(c, json.Unmarshal(body, &resp)) return strings.TrimSpace(resp.Message) } diff --git a/integration/network/macvlan/macvlan_test.go b/integration/network/macvlan/macvlan_test.go index e854a0d350..fa7b6854e7 100644 --- a/integration/network/macvlan/macvlan_test.go +++ b/integration/network/macvlan/macvlan_test.go @@ -128,7 +128,7 @@ func testMacvlanOverlapParent(t *testing.T, ctx context.Context, client client.A _, err := net.Create(ctx, client, overlapNetName, net.WithMacvlan(parentName), ) - assert.Check(t, err == nil) + assert.Check(t, err) // delete the second network while preserving the parent link err = client.NetworkRemove(ctx, overlapNetName) @@ -217,7 +217,7 @@ func testMacvlanOverlapDeleteCreatedSecond(t *testing.T, ctx context.Context, cl _, err := net.Create(ctx, client, overlapNetName, net.WithMacvlan(parentName), ) - assert.Check(t, err == nil) + assert.Check(t, err) // delete the original network while preserving the parent link err = client.NetworkRemove(ctx, netName) @@ -252,7 +252,7 @@ func testMacvlanOverlapKeepExisting(t *testing.T, ctx context.Context, client cl _, err := net.Create(ctx, client, overlapNetName, net.WithMacvlan(master), ) - assert.Check(t, err == nil) + assert.Check(t, err) err = client.NetworkRemove(ctx, overlapNetName) assert.NilError(t, err) @@ -298,7 +298,7 @@ func testMacvlanNilParent(t *testing.T, ctx context.Context, client client.APICl id2 := container.Run(ctx, t, client, container.WithNetworkMode(netName)) _, err := container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1}) - assert.Check(t, err == nil) + assert.Check(t, err) } func testMacvlanInternalMode(t *testing.T, ctx context.Context, client client.APIClient) { @@ -317,7 +317,7 @@ func testMacvlanInternalMode(t *testing.T, ctx context.Context, client client.AP assert.Check(t, is.Contains(result.Combined(), "Network is unreachable")) _, err := container.Exec(ctx, client, id2, []string{"ping", "-c", "1", id1}) - assert.Check(t, err == nil) + assert.Check(t, err) } func testMacvlanMultiSubnetWithParent(t *testing.T, ctx context.Context, client client.APIClient) { diff --git a/volume/service/service_test.go b/volume/service/service_test.go index e6af2ed57c..1b205a6577 100644 --- a/volume/service/service_test.go +++ b/volume/service/service_test.go @@ -149,7 +149,7 @@ func TestServiceGet(t *testing.T) { _, err = service.Get(ctx, "test", opts.WithGetDriver("notarealdriver")) assert.Assert(t, errdefs.IsConflict(err), err) v, err = service.Get(ctx, "test", opts.WithGetDriver("d1")) - assert.Assert(t, err == nil) + assert.NilError(t, err) assert.Assert(t, is.DeepEqual(created, v)) assert.Assert(t, ds.Register(testutils.NewFakeDriver("d2"), "d2"))