From 9b5d8cd1864e305ebd2bf2de609f20faede07fc4 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 22 May 2025 11:41:49 +0200 Subject: [PATCH] fix thelper linter Signed-off-by: Matthieu MOREL --- .golangci.yml | 25 ++ integration-cli/benchmark_test.go | 8 +- integration-cli/check_test.go | 142 +++--- integration-cli/daemon/daemon_swarm.go | 28 +- integration-cli/daemon_swarm_hack_test.go | 8 +- integration-cli/docker_api_build_test.go | 4 +- integration-cli/docker_api_containers_test.go | 18 +- integration-cli/docker_api_exec_test.go | 50 +-- integration-cli/docker_api_logs_test.go | 16 +- integration-cli/docker_api_network_test.go | 78 ++-- integration-cli/docker_api_stats_test.go | 18 +- .../docker_api_swarm_service_test.go | 4 +- integration-cli/docker_api_swarm_test.go | 48 +-- integration-cli/docker_api_test.go | 8 +- integration-cli/docker_cli_attach_test.go | 8 +- integration-cli/docker_cli_build_test.go | 30 +- integration-cli/docker_cli_by_digest_test.go | 408 +++++++++--------- integration-cli/docker_cli_commit_test.go | 8 +- integration-cli/docker_cli_cp_test.go | 8 +- integration-cli/docker_cli_cp_utils_test.go | 52 +-- integration-cli/docker_cli_create_test.go | 8 +- integration-cli/docker_cli_daemon_test.go | 36 +- integration-cli/docker_cli_events_test.go | 8 +- integration-cli/docker_cli_exec_test.go | 8 +- .../docker_cli_external_volume_driver_test.go | 20 +- integration-cli/docker_cli_health_test.go | 20 +- integration-cli/docker_cli_history_test.go | 8 +- integration-cli/docker_cli_images_test.go | 8 +- integration-cli/docker_cli_import_test.go | 8 +- integration-cli/docker_cli_info_test.go | 14 +- integration-cli/docker_cli_inspect_test.go | 8 +- integration-cli/docker_cli_links_test.go | 24 +- integration-cli/docker_cli_login_test.go | 8 +- integration-cli/docker_cli_logs_test.go | 18 +- integration-cli/docker_cli_netmode_test.go | 14 +- integration-cli/docker_cli_network_test.go | 8 +- .../docker_cli_network_unix_test.go | 94 ++-- .../docker_cli_plugins_logdriver_test.go | 8 +- integration-cli/docker_cli_plugins_test.go | 8 +- integration-cli/docker_cli_port_test.go | 20 +- integration-cli/docker_cli_proxy_test.go | 8 +- integration-cli/docker_cli_prune_unix_test.go | 20 +- integration-cli/docker_cli_ps_test.go | 16 +- integration-cli/docker_cli_pull_local_test.go | 94 ++-- integration-cli/docker_cli_pull_test.go | 8 +- integration-cli/docker_cli_push_test.go | 8 +- .../docker_cli_registry_user_agent_test.go | 8 +- integration-cli/docker_cli_restart_test.go | 12 +- integration-cli/docker_cli_rmi_test.go | 8 +- integration-cli/docker_cli_run_test.go | 60 +-- integration-cli/docker_cli_save_load_test.go | 8 +- integration-cli/docker_cli_search_test.go | 8 +- .../docker_cli_service_create_test.go | 56 +-- .../docker_cli_service_health_test.go | 30 +- .../docker_cli_service_logs_test.go | 4 +- integration-cli/docker_cli_sni_test.go | 8 +- integration-cli/docker_cli_start_test.go | 8 +- integration-cli/docker_cli_stats_test.go | 8 +- integration-cli/docker_cli_swarm_test.go | 44 +- integration-cli/docker_cli_top_test.go | 8 +- .../docker_cli_update_unix_test.go | 8 +- integration-cli/docker_cli_userns_test.go | 6 +- integration-cli/docker_cli_volume_test.go | 12 +- integration-cli/docker_hub_pull_suite_test.go | 26 +- integration-cli/docker_utils_test.go | 170 ++++---- integration-cli/events_utils_test.go | 28 +- integration-cli/fixtures_linux_daemon_test.go | 50 +-- integration-cli/utils_test.go | 12 +- 68 files changed, 1039 insertions(+), 1014 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e4fd8bae72..99ead7e661 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -42,6 +42,7 @@ linters: - revive # Metalinter; drop-in replacement for golint. - spancheck # Detects mistakes with OpenTelemetry/Census spans. - staticcheck + - thelper - unconvert # Detects unnecessary type conversions. - unused - usestdlibvars # Detects the possibility to use variables/constants from the Go standard library. @@ -164,6 +165,30 @@ linters: - record-error # check that `span.RecordError(err)` is called when an error is returned - set-status # check that `span.SetStatus(codes.Error, msg)` is called when an error is returned + thelper: + test: + # Check *testing.T is first param (or after context.Context) of helper function. + first: false + # Check t.Helper() begins helper function. + begin: false + benchmark: + # Check *testing.B is first param (or after context.Context) of helper function. + first: false + # Check b.Helper() begins helper function. + begin: false + tb: + # Check *testing.TB is first param (or after context.Context) of helper function. + first: false + # Check *testing.TB param has name tb. + name: false + # Check tb.Helper() begins helper function. + begin: false + fuzz: + # Check *testing.F is first param (or after context.Context) of helper function. + first: false + # Check f.Helper() begins helper function. + begin: false + usestdlibvars: # Suggest the use of http.MethodXX. http-method: true diff --git a/integration-cli/benchmark_test.go b/integration-cli/benchmark_test.go index 498910294f..49d20ea325 100644 --- a/integration-cli/benchmark_test.go +++ b/integration-cli/benchmark_test.go @@ -18,12 +18,12 @@ type DockerBenchmarkSuite struct { ds *DockerSuite } -func (s *DockerBenchmarkSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerBenchmarkSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerBenchmarkSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerBenchmarkSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B) { diff --git a/integration-cli/check_test.go b/integration-cli/check_test.go index d6e0b2c0e2..c7dbf24bec 100644 --- a/integration-cli/check_test.go +++ b/integration-cli/check_test.go @@ -418,19 +418,19 @@ func TestDockerHubPullSuite(t *testing.T) { type DockerSuite struct{} -func (s *DockerSuite) OnTimeout(c *testing.T) { +func (s *DockerSuite) OnTimeout(t *testing.T) { if testEnv.IsRemoteDaemon() { return } path := filepath.Join(os.Getenv("DEST"), "docker.pid") b, err := os.ReadFile(path) if err != nil { - c.Fatalf("Failed to get daemon PID from %s\n", path) + t.Fatalf("Failed to get daemon PID from %s\n", path) } rawPid, err := strconv.ParseInt(string(b), 10, 32) if err != nil { - c.Fatalf("Failed to parse pid from %s: %s\n", path, err) + t.Fatalf("Failed to parse pid from %s: %s\n", path, err) } daemonPid := int(rawPid) @@ -439,8 +439,8 @@ func (s *DockerSuite) OnTimeout(c *testing.T) { } } -func (s *DockerSuite) TearDownTest(ctx context.Context, c *testing.T) { - testEnv.Clean(ctx, c) +func (s *DockerSuite) TearDownTest(ctx context.Context, t *testing.T) { + testEnv.Clean(ctx, t) } type DockerRegistrySuite struct { @@ -449,25 +449,25 @@ type DockerRegistrySuite struct { d *daemon.Daemon } -func (s *DockerRegistrySuite) OnTimeout(c *testing.T) { +func (s *DockerRegistrySuite) OnTimeout(t *testing.T) { s.d.DumpStackAndQuit() } -func (s *DockerRegistrySuite) SetUpTest(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon) - s.reg = registry.NewV2(c) - s.reg.WaitReady(c) - s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) +func (s *DockerRegistrySuite) SetUpTest(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon) + s.reg = registry.NewV2(t) + s.reg.WaitReady(t) + s.d = daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } -func (s *DockerRegistrySuite) TearDownTest(ctx context.Context, c *testing.T) { +func (s *DockerRegistrySuite) TearDownTest(ctx context.Context, t *testing.T) { if s.reg != nil { s.reg.Close() } if s.d != nil { - s.d.Stop(c) + s.d.Stop(t) } - s.ds.TearDownTest(ctx, c) + s.ds.TearDownTest(ctx, t) } type DockerRegistryAuthHtpasswdSuite struct { @@ -476,27 +476,27 @@ type DockerRegistryAuthHtpasswdSuite struct { d *daemon.Daemon } -func (s *DockerRegistryAuthHtpasswdSuite) OnTimeout(c *testing.T) { +func (s *DockerRegistryAuthHtpasswdSuite) OnTimeout(t *testing.T) { s.d.DumpStackAndQuit() } -func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon) - s.reg = registry.NewV2(c, registry.Htpasswd) - s.reg.WaitReady(c) - s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) +func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon) + s.reg = registry.NewV2(t, registry.Htpasswd) + s.reg.WaitReady(t) + s.d = daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } -func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(ctx context.Context, c *testing.T) { +func (s *DockerRegistryAuthHtpasswdSuite) TearDownTest(ctx context.Context, t *testing.T) { if s.reg != nil { out, err := s.d.Cmd("logout", privateRegistryURL) - assert.NilError(c, err, out) + assert.NilError(t, err, out) s.reg.Close() } if s.d != nil { - s.d.Stop(c) + s.d.Stop(t) } - s.ds.TearDownTest(ctx, c) + s.ds.TearDownTest(ctx, t) } type DockerRegistryAuthTokenSuite struct { @@ -505,33 +505,33 @@ type DockerRegistryAuthTokenSuite struct { d *daemon.Daemon } -func (s *DockerRegistryAuthTokenSuite) OnTimeout(c *testing.T) { +func (s *DockerRegistryAuthTokenSuite) OnTimeout(t *testing.T) { s.d.DumpStackAndQuit() } -func (s *DockerRegistryAuthTokenSuite) SetUpTest(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon) - s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) +func (s *DockerRegistryAuthTokenSuite) SetUpTest(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux, RegistryHosting, testEnv.IsLocalDaemon) + s.d = daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } -func (s *DockerRegistryAuthTokenSuite) TearDownTest(ctx context.Context, c *testing.T) { +func (s *DockerRegistryAuthTokenSuite) TearDownTest(ctx context.Context, t *testing.T) { if s.reg != nil { out, err := s.d.Cmd("logout", privateRegistryURL) - assert.NilError(c, err, out) + assert.NilError(t, err, out) s.reg.Close() } if s.d != nil { - s.d.Stop(c) + s.d.Stop(t) } - s.ds.TearDownTest(ctx, c) + s.ds.TearDownTest(ctx, t) } -func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(c *testing.T, tokenURL string) { +func (s *DockerRegistryAuthTokenSuite) setupRegistryWithTokenService(t *testing.T, tokenURL string) { if s == nil { - c.Fatal("registry suite isn't initialized") + t.Fatal("registry suite isn't initialized") } - s.reg = registry.NewV2(c, registry.Token(tokenURL)) - s.reg.WaitReady(c) + s.reg = registry.NewV2(t, registry.Token(tokenURL)) + s.reg.WaitReady(t) } type DockerDaemonSuite struct { @@ -539,24 +539,24 @@ type DockerDaemonSuite struct { d *daemon.Daemon } -func (s *DockerDaemonSuite) OnTimeout(c *testing.T) { +func (s *DockerDaemonSuite) OnTimeout(t *testing.T) { s.d.DumpStackAndQuit() } -func (s *DockerDaemonSuite) SetUpTest(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) - s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) +func (s *DockerDaemonSuite) SetUpTest(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux, testEnv.IsLocalDaemon) + s.d = daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } -func (s *DockerDaemonSuite) TearDownTest(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) +func (s *DockerDaemonSuite) TearDownTest(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux, testEnv.IsLocalDaemon) if s.d != nil { - s.d.Stop(c) + s.d.Stop(t) } - s.ds.TearDownTest(ctx, c) + s.ds.TearDownTest(ctx, t) } -func (s *DockerDaemonSuite) TearDownSuite(ctx context.Context, c *testing.T) { +func (s *DockerDaemonSuite) TearDownSuite(ctx context.Context, t *testing.T) { filepath.Walk(testdaemon.SockRoot, func(path string, fi os.FileInfo, err error) error { if err != nil { // ignore errors here @@ -581,7 +581,7 @@ type DockerSwarmSuite struct { portIndex int } -func (s *DockerSwarmSuite) OnTimeout(c *testing.T) { +func (s *DockerSwarmSuite) OnTimeout(t *testing.T) { s.daemonsLock.Lock() defer s.daemonsLock.Unlock() for _, d := range s.daemons { @@ -589,24 +589,24 @@ func (s *DockerSwarmSuite) OnTimeout(c *testing.T) { } } -func (s *DockerSwarmSuite) SetUpTest(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) +func (s *DockerSwarmSuite) SetUpTest(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux, testEnv.IsLocalDaemon) } -func (s *DockerSwarmSuite) AddDaemon(ctx context.Context, c *testing.T, joinSwarm, manager bool) *daemon.Daemon { - c.Helper() - d := daemon.New(c, dockerBinary, dockerdBinary, +func (s *DockerSwarmSuite) AddDaemon(ctx context.Context, t *testing.T, joinSwarm, manager bool) *daemon.Daemon { + t.Helper() + d := daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution), testdaemon.WithSwarmPort(defaultSwarmPort+s.portIndex), ) if joinSwarm { if len(s.daemons) > 0 { - d.StartAndSwarmJoin(ctx, c, s.daemons[0].Daemon, manager) + d.StartAndSwarmJoin(ctx, t, s.daemons[0].Daemon, manager) } else { - d.StartAndSwarmInit(ctx, c) + d.StartAndSwarmInit(ctx, t) } } else { - d.StartNodeWithBusybox(ctx, c) + d.StartNodeWithBusybox(ctx, t) } s.daemonsLock.Lock() @@ -617,22 +617,22 @@ func (s *DockerSwarmSuite) AddDaemon(ctx context.Context, c *testing.T, joinSwar return d } -func (s *DockerSwarmSuite) TearDownTest(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux) +func (s *DockerSwarmSuite) TearDownTest(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux) s.daemonsLock.Lock() for _, d := range s.daemons { if d != nil { - if c.Failed() { - d.TailLogsT(c, 100) + if t.Failed() { + d.TailLogsT(t, 100) } - d.Stop(c) - d.Cleanup(c) + d.Stop(t) + d.Cleanup(t) } } s.daemons = nil s.portIndex = 0 s.daemonsLock.Unlock() - s.ds.TearDownTest(ctx, c) + s.ds.TearDownTest(ctx, t) } type DockerPluginSuite struct { @@ -652,28 +652,28 @@ func (ps *DockerPluginSuite) getPluginRepoWithTag() string { return ps.getPluginRepo() + ":" + "latest" } -func (ps *DockerPluginSuite) SetUpSuite(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux, RegistryHosting) - ps.registry = registry.NewV2(c) - ps.registry.WaitReady(c) +func (ps *DockerPluginSuite) SetUpSuite(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux, RegistryHosting) + ps.registry = registry.NewV2(t) + ps.registry.WaitReady(t) ctx, cancel := context.WithTimeout(ctx, 60*time.Second) defer cancel() err := plugin.CreateInRegistry(ctx, ps.getPluginRepo(), nil) - assert.NilError(c, err, "failed to create plugin") + assert.NilError(t, err, "failed to create plugin") } -func (ps *DockerPluginSuite) TearDownSuite(ctx context.Context, c *testing.T) { +func (ps *DockerPluginSuite) TearDownSuite(ctx context.Context, t *testing.T) { if ps.registry != nil { ps.registry.Close() } } -func (ps *DockerPluginSuite) TearDownTest(ctx context.Context, c *testing.T) { - ps.ds.TearDownTest(ctx, c) +func (ps *DockerPluginSuite) TearDownTest(ctx context.Context, t *testing.T) { + ps.ds.TearDownTest(ctx, t) } -func (ps *DockerPluginSuite) OnTimeout(c *testing.T) { - ps.ds.OnTimeout(c) +func (ps *DockerPluginSuite) OnTimeout(t *testing.T) { + ps.ds.OnTimeout(t) } diff --git a/integration-cli/daemon/daemon_swarm.go b/integration-cli/daemon/daemon_swarm.go index bec4647861..9bb24e14df 100644 --- a/integration-cli/daemon/daemon_swarm.go +++ b/integration-cli/daemon/daemon_swarm.go @@ -15,8 +15,8 @@ import ( // CheckServiceTasksInState returns the number of tasks with a matching state, // and optional message substring. func (d *Daemon) CheckServiceTasksInState(ctx context.Context, service string, state swarm.TaskState, message string) func(*testing.T) (interface{}, string) { - return func(c *testing.T) (interface{}, string) { - tasks := d.GetServiceTasks(ctx, c, service) + return func(t *testing.T) (interface{}, string) { + tasks := d.GetServiceTasks(ctx, t, service) var count int for _, task := range tasks { if task.Status.State == state { @@ -32,8 +32,8 @@ func (d *Daemon) CheckServiceTasksInState(ctx context.Context, service string, s // CheckServiceTasksInStateWithError returns the number of tasks with a matching state, // and optional message substring. func (d *Daemon) CheckServiceTasksInStateWithError(ctx context.Context, service string, state swarm.TaskState, errorMessage string) func(*testing.T) (interface{}, string) { - return func(c *testing.T) (interface{}, string) { - tasks := d.GetServiceTasks(ctx, c, service) + return func(t *testing.T) (interface{}, string) { + tasks := d.GetServiceTasks(ctx, t, service) var count int for _, task := range tasks { if task.Status.State == state { @@ -53,8 +53,8 @@ func (d *Daemon) CheckServiceRunningTasks(ctx context.Context, service string) f // CheckServiceUpdateState returns the current update state for the specified service func (d *Daemon) CheckServiceUpdateState(ctx context.Context, service string) func(*testing.T) (interface{}, string) { - return func(c *testing.T) (interface{}, string) { - service := d.GetService(ctx, c, service) + return func(t *testing.T) (interface{}, string) { + service := d.GetService(ctx, t, service) if service.UpdateStatus == nil { return "", "" } @@ -64,34 +64,34 @@ func (d *Daemon) CheckServiceUpdateState(ctx context.Context, service string) fu // CheckPluginRunning returns the runtime state of the plugin func (d *Daemon) CheckPluginRunning(ctx context.Context, plugin string) func(c *testing.T) (interface{}, string) { - return func(c *testing.T) (interface{}, string) { - apiclient := d.NewClientT(c) + return func(t *testing.T) (interface{}, string) { + apiclient := d.NewClientT(t) resp, _, err := apiclient.PluginInspectWithRaw(ctx, plugin) if cerrdefs.IsNotFound(err) { return false, fmt.Sprintf("%v", err) } - assert.NilError(c, err) + assert.NilError(t, err) return resp.Enabled, fmt.Sprintf("%+v", resp) } } // CheckPluginImage returns the runtime state of the plugin func (d *Daemon) CheckPluginImage(ctx context.Context, plugin string) func(c *testing.T) (interface{}, string) { - return func(c *testing.T) (interface{}, string) { - apiclient := d.NewClientT(c) + return func(t *testing.T) (interface{}, string) { + apiclient := d.NewClientT(t) resp, _, err := apiclient.PluginInspectWithRaw(ctx, plugin) if cerrdefs.IsNotFound(err) { return false, fmt.Sprintf("%v", err) } - assert.NilError(c, err) + assert.NilError(t, err) return resp.PluginReference, fmt.Sprintf("%+v", resp) } } // CheckServiceTasks returns the number of tasks for the specified service func (d *Daemon) CheckServiceTasks(ctx context.Context, service string) func(*testing.T) (interface{}, string) { - return func(c *testing.T) (interface{}, string) { - tasks := d.GetServiceTasks(ctx, c, service) + return func(t *testing.T) (interface{}, string) { + tasks := d.GetServiceTasks(ctx, t, service) return len(tasks), "" } } diff --git a/integration-cli/daemon_swarm_hack_test.go b/integration-cli/daemon_swarm_hack_test.go index 4152f735f7..506166b62d 100644 --- a/integration-cli/daemon_swarm_hack_test.go +++ b/integration-cli/daemon_swarm_hack_test.go @@ -6,7 +6,7 @@ import ( "github.com/docker/docker/integration-cli/daemon" ) -func (s *DockerSwarmSuite) getDaemon(c *testing.T, nodeID string) *daemon.Daemon { +func (s *DockerSwarmSuite) getDaemon(t *testing.T, nodeID string) *daemon.Daemon { s.daemonsLock.Lock() defer s.daemonsLock.Unlock() for _, d := range s.daemons { @@ -14,11 +14,11 @@ func (s *DockerSwarmSuite) getDaemon(c *testing.T, nodeID string) *daemon.Daemon return d } } - c.Fatalf("could not find node with id: %s", nodeID) + t.Fatalf("could not find node with id: %s", nodeID) return nil } // nodeCmd executes a command on a given node via the normal docker socket -func (s *DockerSwarmSuite) nodeCmd(c *testing.T, id string, args ...string) (string, error) { - return s.getDaemon(c, id).Cmd(args...) +func (s *DockerSwarmSuite) nodeCmd(t *testing.T, id string, args ...string) (string, error) { + return s.getDaemon(t, id).Cmd(args...) } diff --git a/integration-cli/docker_api_build_test.go b/integration-cli/docker_api_build_test.go index a163e5ab08..e573a942a8 100644 --- a/integration-cli/docker_api_build_test.go +++ b/integration-cli/docker_api_build_test.go @@ -555,14 +555,14 @@ type buildLine struct { } } -func getImageIDsFromBuild(c *testing.T, output []byte) []string { +func getImageIDsFromBuild(t *testing.T, output []byte) []string { var ids []string for _, line := range bytes.Split(output, []byte("\n")) { if len(line) == 0 { continue } entry := buildLine{} - assert.NilError(c, json.Unmarshal(line, &entry)) + assert.NilError(t, json.Unmarshal(line, &entry)) if entry.Aux.ID != "" { ids = append(ids, entry.Aux.ID) } diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 964d760bb7..d504e82404 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -361,8 +361,8 @@ func (s *DockerAPISuite) TestContainerAPIPause(c *testing.T) { // Problematic on Windows as Windows does not support pause testRequires(c, DaemonIsLinux) - getPaused := func(c *testing.T) []string { - return strings.Fields(cli.DockerCmd(c, "ps", "-f", "status=paused", "-q", "-a").Combined()) + getPaused := func(t *testing.T) []string { + return strings.Fields(cli.DockerCmd(t, "ps", "-f", "status=paused", "-q", "-a").Combined()) } out := cli.DockerCmd(c, "run", "-d", "busybox", "sleep", "30").Combined() @@ -564,7 +564,7 @@ func (s *DockerAPISuite) TestContainerAPICreateOtherNetworkModes(c *testing.T) { UtilCreateNetworkMode(c, "container:web1") } -func UtilCreateNetworkMode(c *testing.T, networkMode container.NetworkMode) { +func UtilCreateNetworkMode(t *testing.T, networkMode container.NetworkMode) { config := container.Config{ Image: "busybox", } @@ -574,16 +574,16 @@ func UtilCreateNetworkMode(c *testing.T, networkMode container.NetworkMode) { } apiClient, err := client.NewClientWithOpts(client.FromEnv) - assert.NilError(c, err) + assert.NilError(t, err) defer apiClient.Close() - ctr, err := apiClient.ContainerCreate(testutil.GetContext(c), &config, &hostConfig, &network.NetworkingConfig{}, nil, "") - assert.NilError(c, err) + ctr, err := apiClient.ContainerCreate(testutil.GetContext(t), &config, &hostConfig, &network.NetworkingConfig{}, nil, "") + assert.NilError(t, err) - containerJSON, err := apiClient.ContainerInspect(testutil.GetContext(c), ctr.ID) - assert.NilError(c, err) + containerJSON, err := apiClient.ContainerInspect(testutil.GetContext(t), ctr.ID) + assert.NilError(t, err) - assert.Equal(c, containerJSON.HostConfig.NetworkMode, networkMode, "Mismatched NetworkMode") + assert.Equal(t, containerJSON.HostConfig.NetworkMode, networkMode, "Mismatched NetworkMode") } func (s *DockerAPISuite) TestContainerAPICreateWithCpuSharesCpuset(c *testing.T) { diff --git a/integration-cli/docker_api_exec_test.go b/integration-cli/docker_api_exec_test.go index 41dbe670b4..21093d83f1 100644 --- a/integration-cli/docker_api_exec_test.go +++ b/integration-cli/docker_api_exec_test.go @@ -193,9 +193,9 @@ func (s *DockerAPISuite) TestExecStateCleanup(c *testing.T) { stateDir := "/var/run/docker/containerd/" + cid - checkReadDir := func(c *testing.T) (interface{}, string) { + checkReadDir := func(t *testing.T) (interface{}, string) { fi, err := os.ReadDir(stateDir) - assert.NilError(c, err) + assert.NilError(t, err) return len(fi), "" } @@ -223,63 +223,63 @@ func (s *DockerAPISuite) TestExecStateCleanup(c *testing.T) { assert.Assert(c, os.IsNotExist(err)) } -func createExec(c *testing.T, name string) string { - return createExecCmd(c, name, "true") +func createExec(t *testing.T, name string) string { + return createExecCmd(t, name, "true") } -func createExecCmd(c *testing.T, name string, cmd string) string { - _, reader, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": []string{cmd}})) - assert.NilError(c, err) +func createExecCmd(t *testing.T, name string, cmd string) string { + _, reader, err := request.Post(testutil.GetContext(t), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": []string{cmd}})) + assert.NilError(t, err) b, err := io.ReadAll(reader) - assert.NilError(c, err) + assert.NilError(t, err) defer reader.Close() createResp := struct { ID string `json:"Id"` }{} - assert.NilError(c, json.Unmarshal(b, &createResp), string(b)) + assert.NilError(t, json.Unmarshal(b, &createResp), string(b)) return createResp.ID } -func startExec(c *testing.T, id string, code int) { - resp, body, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON) - assert.NilError(c, err) +func startExec(t *testing.T, id string, code int) { + resp, body, err := request.Post(testutil.GetContext(t), fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON) + assert.NilError(t, err) b, err := request.ReadBody(body) - assert.NilError(c, err, "response body: %s", b) - assert.Equal(c, resp.StatusCode, code, "response body: %s", b) + assert.NilError(t, err, "response body: %s", b) + assert.Equal(t, resp.StatusCode, code, "response body: %s", b) } -func inspectExec(ctx context.Context, c *testing.T, id string, out interface{}) { +func inspectExec(ctx context.Context, t *testing.T, id string, out interface{}) { resp, body, err := request.Get(ctx, fmt.Sprintf("/exec/%s/json", id)) - assert.NilError(c, err) + assert.NilError(t, err) defer body.Close() - assert.Equal(c, resp.StatusCode, http.StatusOK) + assert.Equal(t, resp.StatusCode, http.StatusOK) err = json.NewDecoder(body).Decode(out) - assert.NilError(c, err) + assert.NilError(t, err) } -func waitForExec(ctx context.Context, c *testing.T, id string) { +func waitForExec(ctx context.Context, t *testing.T, id string) { timeout := time.After(60 * time.Second) var execJSON struct{ Running bool } for { select { case <-timeout: - c.Fatal("timeout waiting for exec to start") + t.Fatal("timeout waiting for exec to start") default: } - inspectExec(ctx, c, id, &execJSON) + inspectExec(ctx, t, id, &execJSON) if !execJSON.Running { break } } } -func inspectContainer(ctx context.Context, c *testing.T, id string, out interface{}) { +func inspectContainer(ctx context.Context, t *testing.T, id string, out interface{}) { resp, body, err := request.Get(ctx, "/containers/"+id+"/json") - assert.NilError(c, err) + assert.NilError(t, err) defer body.Close() - assert.Equal(c, resp.StatusCode, http.StatusOK) + assert.Equal(t, resp.StatusCode, http.StatusOK) err = json.NewDecoder(body).Decode(out) - assert.NilError(c, err) + assert.NilError(t, err) } diff --git a/integration-cli/docker_api_logs_test.go b/integration-cli/docker_api_logs_test.go index 39eb6cf552..8d481ef938 100644 --- a/integration-cli/docker_api_logs_test.go +++ b/integration-cli/docker_api_logs_test.go @@ -171,14 +171,14 @@ func (s *DockerAPISuite) TestLogsAPIUntil(c *testing.T) { c.Fatal(err) } - extractBody := func(c *testing.T, cfg container.LogsOptions) []string { - reader, err := apiClient.ContainerLogs(testutil.GetContext(c), name, cfg) - assert.NilError(c, err) + extractBody := func(t *testing.T, cfg container.LogsOptions) []string { + reader, err := apiClient.ContainerLogs(testutil.GetContext(t), name, cfg) + assert.NilError(t, err) actualStdout := new(bytes.Buffer) actualStderr := io.Discard _, err = stdcopy.StdCopy(actualStdout, actualStderr, reader) - assert.NilError(c, err) + assert.NilError(t, err) return strings.Split(actualStdout.String(), "\n") } @@ -208,14 +208,14 @@ func (s *DockerAPISuite) TestLogsAPIUntilDefaultValue(c *testing.T) { c.Fatal(err) } - extractBody := func(c *testing.T, cfg container.LogsOptions) []string { - reader, err := apiClient.ContainerLogs(testutil.GetContext(c), name, cfg) - assert.NilError(c, err) + extractBody := func(t *testing.T, cfg container.LogsOptions) []string { + reader, err := apiClient.ContainerLogs(testutil.GetContext(t), name, cfg) + assert.NilError(t, err) actualStdout := new(bytes.Buffer) actualStderr := io.Discard _, err = stdcopy.StdCopy(actualStdout, actualStderr, reader) - assert.NilError(c, err) + assert.NilError(t, err) return strings.Split(actualStdout.String(), "\n") } diff --git a/integration-cli/docker_api_network_test.go b/integration-cli/docker_api_network_test.go index 5e1c47e7c1..ba343d1fd8 100644 --- a/integration-cli/docker_api_network_test.go +++ b/integration-cli/docker_api_network_test.go @@ -203,23 +203,23 @@ func (s *DockerAPISuite) TestAPICreateDeletePredefinedNetworks(c *testing.T) { createDeletePredefinedNetwork(c, "host") } -func createDeletePredefinedNetwork(c *testing.T, name string) { +func createDeletePredefinedNetwork(t *testing.T, name string) { // Create pre-defined network config := network.CreateRequest{Name: name} expectedStatus := http.StatusForbidden - createNetwork(c, config, expectedStatus) - deleteNetwork(c, name, false) + createNetwork(t, config, expectedStatus) + deleteNetwork(t, name, false) } -func isNetworkAvailable(c *testing.T, name string) bool { - resp, body, err := request.Get(testutil.GetContext(c), "/networks") - assert.NilError(c, err) +func isNetworkAvailable(t *testing.T, name string) bool { + resp, body, err := request.Get(testutil.GetContext(t), "/networks") + assert.NilError(t, err) defer resp.Body.Close() - assert.Equal(c, resp.StatusCode, http.StatusOK) + assert.Equal(t, resp.StatusCode, http.StatusOK) var nJSON []network.Inspect err = json.NewDecoder(body).Decode(&nJSON) - assert.NilError(c, err) + assert.NilError(t, err) for _, n := range nJSON { if n.Name == name { @@ -229,19 +229,19 @@ func isNetworkAvailable(c *testing.T, name string) bool { return false } -func getNetworkIDByName(c *testing.T, name string) string { +func getNetworkIDByName(t *testing.T, name string) string { filterJSON, err := filters.ToJSON(filters.NewArgs(filters.Arg("name", name))) - assert.NilError(c, err) + assert.NilError(t, err) v := url.Values{} v.Set("filters", filterJSON) - resp, body, err := request.Get(testutil.GetContext(c), "/networks?"+v.Encode()) - assert.Equal(c, resp.StatusCode, http.StatusOK) - assert.NilError(c, err) + resp, body, err := request.Get(testutil.GetContext(t), "/networks?"+v.Encode()) + assert.Equal(t, resp.StatusCode, http.StatusOK) + assert.NilError(t, err) var nJSON []network.Inspect err = json.NewDecoder(body).Decode(&nJSON) - assert.NilError(c, err) + assert.NilError(t, err) var res string for _, n := range nJSON { // Find exact match @@ -249,70 +249,70 @@ func getNetworkIDByName(c *testing.T, name string) string { res = n.ID } } - assert.Assert(c, res != "") + assert.Assert(t, res != "") return res } -func getNetworkResource(c *testing.T, id string) *network.Inspect { - _, obj, err := request.Get(testutil.GetContext(c), "/networks/"+id) - assert.NilError(c, err) +func getNetworkResource(t *testing.T, id string) *network.Inspect { + _, obj, err := request.Get(testutil.GetContext(t), "/networks/"+id) + assert.NilError(t, err) nr := network.Inspect{} err = json.NewDecoder(obj).Decode(&nr) - assert.NilError(c, err) + assert.NilError(t, err) return &nr } -func createNetwork(c *testing.T, config network.CreateRequest, expectedStatusCode int) string { - c.Helper() +func createNetwork(t *testing.T, config network.CreateRequest, expectedStatusCode int) string { + t.Helper() - resp, body, err := request.Post(testutil.GetContext(c), "/networks/create", request.JSONBody(config)) - assert.NilError(c, err) + resp, body, err := request.Post(testutil.GetContext(t), "/networks/create", request.JSONBody(config)) + assert.NilError(t, err) defer resp.Body.Close() if expectedStatusCode >= 0 { - assert.Equal(c, resp.StatusCode, expectedStatusCode) + assert.Equal(t, resp.StatusCode, expectedStatusCode) } else { - assert.Assert(c, resp.StatusCode != -expectedStatusCode) + assert.Assert(t, resp.StatusCode != -expectedStatusCode) } if expectedStatusCode == http.StatusCreated || expectedStatusCode < 0 { var nr network.CreateResponse err = json.NewDecoder(body).Decode(&nr) - assert.NilError(c, err) + assert.NilError(t, err) return nr.ID } return "" } -func connectNetwork(c *testing.T, nid, cid string) { - resp, _, err := request.Post(testutil.GetContext(c), "/networks/"+nid+"/connect", request.JSONBody(network.ConnectOptions{ +func connectNetwork(t *testing.T, nid, cid string) { + resp, _, err := request.Post(testutil.GetContext(t), "/networks/"+nid+"/connect", request.JSONBody(network.ConnectOptions{ Container: cid, })) - assert.NilError(c, err) - assert.Equal(c, resp.StatusCode, http.StatusOK) + assert.NilError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) } -func disconnectNetwork(c *testing.T, nid, cid string) { +func disconnectNetwork(t *testing.T, nid, cid string) { config := network.ConnectOptions{ Container: cid, } - resp, _, err := request.Post(testutil.GetContext(c), "/networks/"+nid+"/disconnect", request.JSONBody(config)) - assert.NilError(c, err) - assert.Equal(c, resp.StatusCode, http.StatusOK) + resp, _, err := request.Post(testutil.GetContext(t), "/networks/"+nid+"/disconnect", request.JSONBody(config)) + assert.NilError(t, err) + assert.Equal(t, resp.StatusCode, http.StatusOK) } -func deleteNetwork(c *testing.T, id string, shouldSucceed bool) { - resp, _, err := request.Delete(testutil.GetContext(c), "/networks/"+id) - assert.NilError(c, err) +func deleteNetwork(t *testing.T, id string, shouldSucceed bool) { + resp, _, err := request.Delete(testutil.GetContext(t), "/networks/"+id) + assert.NilError(t, err) defer resp.Body.Close() if !shouldSucceed { - assert.Assert(c, resp.StatusCode != http.StatusOK) + assert.Assert(t, resp.StatusCode != http.StatusOK) return } - assert.Equal(c, resp.StatusCode, http.StatusNoContent) + assert.Equal(t, resp.StatusCode, http.StatusNoContent) } diff --git a/integration-cli/docker_api_stats_test.go b/integration-cli/docker_api_stats_test.go index 066c871ee3..5e23bdeecc 100644 --- a/integration-cli/docker_api_stats_test.go +++ b/integration-cli/docker_api_stats_test.go @@ -174,14 +174,14 @@ func (s *DockerAPISuite) TestAPIStatsNetworkStatsVersioning(c *testing.T) { assert.Assert(c, jsonBlobHasGTE121NetworkStats(statsJSONBlob), "Stats JSON blob from API does not look like a >=v1.21 API stats structure", statsJSONBlob) } -func getNetworkStats(c *testing.T, id string) map[string]container.NetworkStats { +func getNetworkStats(t *testing.T, id string) map[string]container.NetworkStats { var st *container.StatsResponse - _, body, err := request.Get(testutil.GetContext(c), "/containers/"+id+"/stats?stream=false") - assert.NilError(c, err) + _, body, err := request.Get(testutil.GetContext(t), "/containers/"+id+"/stats?stream=false") + assert.NilError(t, err) err = json.NewDecoder(body).Decode(&st) - assert.NilError(c, err) + assert.NilError(t, err) body.Close() return st.Networks @@ -191,16 +191,16 @@ func getNetworkStats(c *testing.T, id string) map[string]container.NetworkStats // container with id using an API call with version apiVersion. Since the // stats result type differs between API versions, we simply return // map[string]interface{}. -func getStats(c *testing.T, id string) map[string]interface{} { - c.Helper() +func getStats(t *testing.T, id string) map[string]interface{} { + t.Helper() stats := make(map[string]interface{}) - _, body, err := request.Get(testutil.GetContext(c), "/containers/"+id+"/stats?stream=false") - assert.NilError(c, err) + _, body, err := request.Get(testutil.GetContext(t), "/containers/"+id+"/stats?stream=false") + assert.NilError(t, err) defer body.Close() err = json.NewDecoder(body).Decode(&stats) - assert.NilError(c, err, "failed to decode stat: %s", err) + assert.NilError(t, err, "failed to decode stat: %s", err) return stats } diff --git a/integration-cli/docker_api_swarm_service_test.go b/integration-cli/docker_api_swarm_service_test.go index 40e2b3a93e..506d16d722 100644 --- a/integration-cli/docker_api_swarm_service_test.go +++ b/integration-cli/docker_api_swarm_service_test.go @@ -224,8 +224,8 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) { checkStartingTasks := func(expected int) []swarm.Task { var startingTasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks := d.GetServiceTasks(ctx, c, id) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks := d.GetServiceTasks(ctx, t, id) startingTasks = nil for _, t := range tasks { if t.Status.State == swarm.TaskStateStarting { diff --git a/integration-cli/docker_api_swarm_test.go b/integration-cli/docker_api_swarm_test.go index 8545b80ae7..8d613f3e2d 100644 --- a/integration-cli/docker_api_swarm_test.go +++ b/integration-cli/docker_api_swarm_test.go @@ -228,7 +228,7 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) { // back to manager quickly might cause the node to pause for awhile // while waiting for the role to change to worker, and the test can // time out during this interval. - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { certBytes, err := os.ReadFile(filepath.Join(d2.Folder, "root", "swarm", "certificates", "swarm-node.crt")) if err != nil { return "", fmt.Sprintf("error: %v", err) @@ -324,12 +324,12 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) { ) var lastErr error checkLeader := func(nodes ...*daemon.Daemon) checkF { - return func(c *testing.T) (interface{}, string) { + return func(t *testing.T) (interface{}, string) { // clear these out before each run leader = nil followers = nil for _, d := range nodes { - n := d.GetNode(ctx, c, d.NodeID(), func(err error) bool { + n := d.GetNode(ctx, t, d.NodeID(), func(err error) bool { if strings.Contains(err.Error(), context.DeadlineExceeded.Error()) || strings.Contains(err.Error(), "swarm does not have a leader") { lastErr = err return true @@ -412,8 +412,8 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *testing.T) { defer cli.Close() // d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - _, err := cli.ServiceCreate(testutil.GetContext(c), service.Spec, swarm.ServiceCreateOptions{}) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + _, err := cli.ServiceCreate(testutil.GetContext(t), service.Spec, swarm.ServiceCreateOptions{}) return err.Error(), "" }, checker.Contains("Make sure more than half of the managers are online.")), poll.WithTimeout(defaultReconciliationTimeout*2)) @@ -745,21 +745,21 @@ func setGlobalMode(s *swarm.Service) { } } -func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerCount int) { +func checkClusterHealth(t *testing.T, cl []*daemon.Daemon, managerCount, workerCount int) { var totalMCount, totalWCount int - ctx := testutil.GetContext(c) + ctx := testutil.GetContext(t) for _, d := range cl { var info swarm.Info // check info in a poll.WaitOn(), because if the cluster doesn't have a leader, `info` will return an error - checkInfo := func(c *testing.T) (interface{}, string) { - client := d.NewClientT(c) + checkInfo := func(t *testing.T) (interface{}, string) { + client := d.NewClientT(t) daemonInfo, err := client.Info(ctx) info = daemonInfo.Swarm return err, "cluster not ready in time" } - poll.WaitOn(c, pollCheck(c, checkInfo, checker.IsNil()), poll.WithTimeout(defaultReconciliationTimeout)) + poll.WaitOn(t, pollCheck(t, checkInfo, checker.IsNil()), poll.WithTimeout(defaultReconciliationTimeout)) if !info.ControlAvailable { totalWCount++ continue @@ -769,44 +769,44 @@ func checkClusterHealth(c *testing.T, cl []*daemon.Daemon, managerCount, workerC totalMCount++ var mCount, wCount int - for _, n := range d.ListNodes(ctx, c) { - waitReady := func(c *testing.T) (interface{}, string) { + for _, n := range d.ListNodes(ctx, t) { + waitReady := func(t *testing.T) (interface{}, string) { if n.Status.State == swarm.NodeStateReady { return true, "" } - nn := d.GetNode(ctx, c, n.ID) + nn := d.GetNode(ctx, t, n.ID) n = *nn return n.Status.State == swarm.NodeStateReady, fmt.Sprintf("state of node %s, reported by %s", n.ID, d.NodeID()) } - poll.WaitOn(c, pollCheck(c, waitReady, checker.True()), poll.WithTimeout(defaultReconciliationTimeout)) + poll.WaitOn(t, pollCheck(t, waitReady, checker.True()), poll.WithTimeout(defaultReconciliationTimeout)) - waitActive := func(c *testing.T) (interface{}, string) { + waitActive := func(t *testing.T) (interface{}, string) { if n.Spec.Availability == swarm.NodeAvailabilityActive { return true, "" } - nn := d.GetNode(ctx, c, n.ID) + nn := d.GetNode(ctx, t, n.ID) n = *nn return n.Spec.Availability == swarm.NodeAvailabilityActive, fmt.Sprintf("availability of node %s, reported by %s", n.ID, d.NodeID()) } - poll.WaitOn(c, pollCheck(c, waitActive, checker.True()), poll.WithTimeout(defaultReconciliationTimeout)) + poll.WaitOn(t, pollCheck(t, waitActive, checker.True()), poll.WithTimeout(defaultReconciliationTimeout)) if n.Spec.Role == swarm.NodeRoleManager { - assert.Assert(c, n.ManagerStatus != nil, "manager status of node %s (manager), reported by %s", n.ID, d.NodeID()) + assert.Assert(t, n.ManagerStatus != nil, "manager status of node %s (manager), reported by %s", n.ID, d.NodeID()) if n.ManagerStatus.Leader { leaderFound = true } mCount++ } else { - assert.Assert(c, n.ManagerStatus == nil, "manager status of node %s (worker), reported by %s", n.ID, d.NodeID()) + assert.Assert(t, n.ManagerStatus == nil, "manager status of node %s (worker), reported by %s", n.ID, d.NodeID()) wCount++ } } - assert.Equal(c, leaderFound, true, "lack of leader reported by node %s", info.NodeID) - assert.Equal(c, mCount, managerCount, "managers count reported by node %s", info.NodeID) - assert.Equal(c, wCount, workerCount, "workers count reported by node %s", info.NodeID) + assert.Equal(t, leaderFound, true, "lack of leader reported by node %s", info.NodeID) + assert.Equal(t, mCount, managerCount, "managers count reported by node %s", info.NodeID) + assert.Equal(t, wCount, workerCount, "workers count reported by node %s", info.NodeID) } - assert.Equal(c, totalMCount, managerCount) - assert.Equal(c, totalWCount, workerCount) + assert.Equal(t, totalMCount, managerCount) + assert.Equal(t, totalWCount, workerCount) } func (s *DockerSwarmSuite) TestAPISwarmRestartCluster(c *testing.T) { diff --git a/integration-cli/docker_api_test.go b/integration-cli/docker_api_test.go index 7afa9f0c71..b7832b93ee 100644 --- a/integration-cli/docker_api_test.go +++ b/integration-cli/docker_api_test.go @@ -22,12 +22,12 @@ type DockerAPISuite struct { ds *DockerSuite } -func (s *DockerAPISuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerAPISuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerAPISuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerAPISuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerAPISuite) TestAPIOptionsRoute(c *testing.T) { diff --git a/integration-cli/docker_cli_attach_test.go b/integration-cli/docker_cli_attach_test.go index a54d12f1d3..825ba3e335 100644 --- a/integration-cli/docker_cli_attach_test.go +++ b/integration-cli/docker_cli_attach_test.go @@ -23,12 +23,12 @@ type DockerCLIAttachSuite struct { ds *DockerSuite } -func (s *DockerCLIAttachSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIAttachSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIAttachSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIAttachSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIAttachSuite) TestAttachMultipleAndRestart(c *testing.T) { diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 59f1fab57f..308c3d7e09 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -38,12 +38,12 @@ type DockerCLIBuildSuite struct { ds *DockerSuite } -func (s *DockerCLIBuildSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIBuildSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIBuildSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIBuildSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIBuildSuite) TestBuildJSONEmptyRun(c *testing.T) { @@ -2009,8 +2009,8 @@ func (s *DockerCLIBuildSuite) TestBuildAddLocalAndRemoteFilesWithAndWithoutCache } } -func testContextTar(c *testing.T, comp compression.Compression) { - ctx := fakecontext.New(c, "", +func testContextTar(t *testing.T, comp compression.Compression) { + ctx := fakecontext.New(t, "", fakecontext.WithDockerfile(`FROM busybox ADD foo /foo CMD ["cat", "/foo"]`), @@ -2021,11 +2021,11 @@ CMD ["cat", "/foo"]`), defer ctx.Close() buildContext, err := archive.Tar(ctx.Dir, comp) if err != nil { - c.Fatalf("failed to build context tar: %v", err) + t.Fatalf("failed to build context tar: %v", err) } const name = "contexttar" - cli.BuildCmd(c, name, build.WithStdinContext(buildContext)) + cli.BuildCmd(t, name, build.WithStdinContext(buildContext)) } func (s *DockerCLIBuildSuite) TestBuildContextTarGzip(c *testing.T) { @@ -2093,15 +2093,15 @@ func (s *DockerCLIBuildSuite) TestBuildDockerfileStdinDockerignoreIgnored(c *tes s.testBuildDockerfileStdinNoExtraFiles(c, true, true) } -func (s *DockerCLIBuildSuite) testBuildDockerfileStdinNoExtraFiles(c *testing.T, hasDockerignore, ignoreDockerignore bool) { +func (s *DockerCLIBuildSuite) testBuildDockerfileStdinNoExtraFiles(t *testing.T, hasDockerignore, ignoreDockerignore bool) { const name = "stdindockerfilenoextra" tmpDir, err := os.MkdirTemp("", "fake-context") - assert.NilError(c, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) writeFile := func(filename, content string) { err = os.WriteFile(filepath.Join(tmpDir, filename), []byte(content), 0o600) - assert.NilError(c, err) + assert.NilError(t, err) } writeFile("foo", "bar") @@ -2123,13 +2123,13 @@ func (s *DockerCLIBuildSuite) testBuildDockerfileStdinNoExtraFiles(c *testing.T, `FROM busybox COPY . /baz`), }) - result.Assert(c, icmd.Success) + result.Assert(t, icmd.Success) - result = cli.DockerCmd(c, "run", "--rm", name, "ls", "-A", "/baz") + result = cli.DockerCmd(t, "run", "--rm", name, "ls", "-A", "/baz") if hasDockerignore && !ignoreDockerignore { - assert.Equal(c, result.Stdout(), ".dockerignore\nfoo\n") + assert.Equal(t, result.Stdout(), ".dockerignore\nfoo\n") } else { - assert.Equal(c, result.Stdout(), "foo\n") + assert.Equal(t, result.Stdout(), "foo\n") } } diff --git a/integration-cli/docker_cli_by_digest_test.go b/integration-cli/docker_cli_by_digest_test.go index cd85b3176f..354fb78841 100644 --- a/integration-cli/docker_cli_by_digest_test.go +++ b/integration-cli/docker_cli_by_digest_test.go @@ -30,510 +30,510 @@ var ( digestRegex = lazyregexp.New(`Digest: ([\S]+)`) ) -func setupImage(c *testing.T) (digest.Digest, error) { - return setupImageWithTag(c, "latest") +func setupImage(t *testing.T) (digest.Digest, error) { + return setupImageWithTag(t, "latest") } -func setupImageWithTag(c *testing.T, tag string) (digest.Digest, error) { +func setupImageWithTag(t *testing.T, tag string) (digest.Digest, error) { const containerName = "busyboxbydigest" // new file is committed because this layer is used for detecting malicious // changes. if this was committed as empty layer it would be skipped on pull // and malicious changes would never be detected. - cli.DockerCmd(c, "run", "-e", "digest=1", "--name", containerName, "busybox", "touch", "anewfile") + cli.DockerCmd(t, "run", "-e", "digest=1", "--name", containerName, "busybox", "touch", "anewfile") // tag the image to upload it to the private registry repoAndTag := repoName + ":" + tag - cli.DockerCmd(c, "commit", containerName, repoAndTag) + cli.DockerCmd(t, "commit", containerName, repoAndTag) // delete the container as we don't need it any more - cli.DockerCmd(c, "rm", "-fv", containerName) + cli.DockerCmd(t, "rm", "-fv", containerName) // push the image - out := cli.DockerCmd(c, "push", repoAndTag).Combined() + out := cli.DockerCmd(t, "push", repoAndTag).Combined() // delete our local repo that we previously tagged - cli.DockerCmd(c, "rmi", repoAndTag) + cli.DockerCmd(t, "rmi", repoAndTag) matches := pushDigestRegex.FindStringSubmatch(out) - assert.Equal(c, len(matches), 2, "unable to parse digest from push output: %s", out) + assert.Equal(t, len(matches), 2, "unable to parse digest from push output: %s", out) pushDigest := matches[1] return digest.Digest(pushDigest), nil } -func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(c *testing.T) { - testRequires(c, DaemonIsLinux) - pushDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestPullByTagDisplaysDigest(t *testing.T) { + testRequires(t, DaemonIsLinux) + pushDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") // pull from the registry using the tag - out := cli.DockerCmd(c, "pull", repoName).Combined() + out := cli.DockerCmd(t, "pull", repoName).Combined() // the pull output includes "Digest: ", so find that matches := digestRegex.FindStringSubmatch(out) - assert.Equal(c, len(matches), 2, "unable to parse digest from push output: %s", out) + assert.Equal(t, len(matches), 2, "unable to parse digest from push output: %s", out) pullDigest := matches[1] // make sure the pushed and pull digests match - assert.Equal(c, pushDigest.String(), pullDigest) + assert.Equal(t, pushDigest.String(), pullDigest) } -func (s *DockerRegistrySuite) TestPullByDigest(c *testing.T) { - testRequires(c, DaemonIsLinux) - pushDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestPullByDigest(t *testing.T) { + testRequires(t, DaemonIsLinux) + pushDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") // pull from the registry using the @ reference imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - out := cli.DockerCmd(c, "pull", imageReference).Combined() + out := cli.DockerCmd(t, "pull", imageReference).Combined() // the pull output includes "Digest: ", so find that matches := digestRegex.FindStringSubmatch(out) - assert.Equal(c, len(matches), 2, "unable to parse digest from push output: %s", out) + assert.Equal(t, len(matches), 2, "unable to parse digest from push output: %s", out) pullDigest := matches[1] // make sure the pushed and pull digests match - assert.Equal(c, pushDigest.String(), pullDigest) + assert.Equal(t, pushDigest.String(), pullDigest) } -func (s *DockerRegistrySuite) TestPullByDigestNoFallback(c *testing.T) { - testRequires(c, DaemonIsLinux) +func (s *DockerRegistrySuite) TestPullByDigestNoFallback(t *testing.T) { + testRequires(t, DaemonIsLinux) // pull from the registry using the @ reference imageReference := fmt.Sprintf("%s@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", repoName) out, _, err := dockerCmdWithError("pull", imageReference) - assert.Assert(c, err != nil, "expected non-zero exit status and correct error message when pulling non-existing image") + assert.Assert(t, err != nil, "expected non-zero exit status and correct error message when pulling non-existing image") expectedMsg := fmt.Sprintf("manifest for %s not found", imageReference) if testEnv.UsingSnapshotter() { expectedMsg = fmt.Sprintf("%s: not found", imageReference) } - assert.Check(c, is.Contains(out, expectedMsg), "expected non-zero exit status and correct error message when pulling non-existing image") + assert.Check(t, is.Contains(out, expectedMsg), "expected non-zero exit status and correct error message when pulling non-existing image") } -func (s *DockerRegistrySuite) TestCreateByDigest(c *testing.T) { - pushDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestCreateByDigest(t *testing.T) { + pushDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) const containerName = "createByDigest" - cli.DockerCmd(c, "create", "--name", containerName, imageReference) + cli.DockerCmd(t, "create", "--name", containerName, imageReference) - res := inspectField(c, containerName, "Config.Image") - assert.Equal(c, res, imageReference) + res := inspectField(t, containerName, "Config.Image") + assert.Equal(t, res, imageReference) } -func (s *DockerRegistrySuite) TestRunByDigest(c *testing.T) { - pushDigest, err := setupImage(c) - assert.NilError(c, err) +func (s *DockerRegistrySuite) TestRunByDigest(t *testing.T) { + pushDigest, err := setupImage(t) + assert.NilError(t, err) imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) const containerName = "runByDigest" - out := cli.DockerCmd(c, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest").Combined() + out := cli.DockerCmd(t, "run", "--name", containerName, imageReference, "sh", "-c", "echo found=$digest").Combined() foundRegex := regexp.MustCompile("found=([^\n]+)") matches := foundRegex.FindStringSubmatch(out) - assert.Equal(c, len(matches), 2, fmt.Sprintf("unable to parse digest from pull output: %s", out)) - assert.Equal(c, matches[1], "1", fmt.Sprintf("Expected %q, got %q", "1", matches[1])) + assert.Equal(t, len(matches), 2, fmt.Sprintf("unable to parse digest from pull output: %s", out)) + assert.Equal(t, matches[1], "1", fmt.Sprintf("Expected %q, got %q", "1", matches[1])) - res := inspectField(c, containerName, "Config.Image") - assert.Equal(c, res, imageReference) + res := inspectField(t, containerName, "Config.Image") + assert.Equal(t, res, imageReference) } -func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *testing.T) { - imgDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestRemoveImageByDigest(t *testing.T) { + imgDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest) // pull from the registry using the @ reference - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) // make sure inspect runs ok - inspectField(c, imageReference, "Id") + inspectField(t, imageReference, "Id") // do the delete err = deleteImages(imageReference) - assert.NilError(c, err, "unexpected error deleting image") + assert.NilError(t, err, "unexpected error deleting image") // try to inspect again - it should error this time _, err = inspectFieldWithError(imageReference, "Id") // unexpected nil err trying to inspect what should be a non-existent image - assert.ErrorContains(c, err, "No such object") + assert.ErrorContains(t, err, "No such object") } -func (s *DockerRegistrySuite) TestBuildByDigest(c *testing.T) { - imgDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestBuildByDigest(t *testing.T) { + imgDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest) // pull from the registry using the @ reference - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) // do the build const name = "buildbydigest" - buildImageSuccessfully(c, name, build.WithDockerfile(fmt.Sprintf( + buildImageSuccessfully(t, name, build.WithDockerfile(fmt.Sprintf( `FROM %s CMD ["/bin/echo", "Hello World"]`, imageReference))) - assert.NilError(c, err) + assert.NilError(t, err) // verify the build was ok - res := inspectField(c, name, "Config.Cmd") - assert.Equal(c, res, `[/bin/echo Hello World]`) + res := inspectField(t, name, "Config.Cmd") + assert.Equal(t, res, `[/bin/echo Hello World]`) } -func (s *DockerRegistrySuite) TestTagByDigest(c *testing.T) { - imgDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestTagByDigest(t *testing.T) { + imgDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest) // pull from the registry using the @ reference - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) // tag it const tag = "tagbydigest" - cli.DockerCmd(c, "tag", imageReference, tag) + cli.DockerCmd(t, "tag", imageReference, tag) - expectedID := inspectField(c, imageReference, "Id") + expectedID := inspectField(t, imageReference, "Id") - tagID := inspectField(c, tag, "Id") - assert.Equal(c, tagID, expectedID) + tagID := inspectField(t, tag, "Id") + assert.Equal(t, tagID, expectedID) } -func (s *DockerRegistrySuite) TestListImagesWithoutDigests(c *testing.T) { - imgDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestListImagesWithoutDigests(t *testing.T) { + imgDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest) // pull from the registry using the @ reference - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) - out := cli.DockerCmd(c, "images").Stdout() - assert.Assert(c, !strings.Contains(out, "DIGEST"), "list output should not have contained DIGEST header") + out := cli.DockerCmd(t, "images").Stdout() + assert.Assert(t, !strings.Contains(out, "DIGEST"), "list output should not have contained DIGEST header") } -func (s *DockerRegistrySuite) TestListImagesWithDigests(c *testing.T) { +func (s *DockerRegistrySuite) TestListImagesWithDigests(t *testing.T) { // setup image1 - digest1, err := setupImageWithTag(c, "tag1") - assert.NilError(c, err, "error setting up image") + digest1, err := setupImageWithTag(t, "tag1") + assert.NilError(t, err, "error setting up image") imageReference1 := fmt.Sprintf("%s@%s", repoName, digest1) - c.Logf("imageReference1 = %s", imageReference1) + t.Logf("imageReference1 = %s", imageReference1) // pull image1 by digest - cli.DockerCmd(c, "pull", imageReference1) + cli.DockerCmd(t, "pull", imageReference1) // list images - out := cli.DockerCmd(c, "images", "--digests").Combined() + out := cli.DockerCmd(t, "images", "--digests").Combined() // make sure repo shown, tag=, digest = $digest1 re1 := regexp.MustCompile(`\s*` + repoName + `\s*\s*` + digest1.String() + `\s`) - assert.Assert(c, re1.MatchString(out), "expected %q: %s", re1.String(), out) + assert.Assert(t, re1.MatchString(out), "expected %q: %s", re1.String(), out) // setup image2 - digest2, err := setupImageWithTag(c, "tag2") - assert.NilError(c, err, "error setting up image") + digest2, err := setupImageWithTag(t, "tag2") + assert.NilError(t, err, "error setting up image") imageReference2 := fmt.Sprintf("%s@%s", repoName, digest2) - c.Logf("imageReference2 = %s", imageReference2) + t.Logf("imageReference2 = %s", imageReference2) // pull image1 by digest - cli.DockerCmd(c, "pull", imageReference1) + cli.DockerCmd(t, "pull", imageReference1) // pull image2 by digest - cli.DockerCmd(c, "pull", imageReference2) + cli.DockerCmd(t, "pull", imageReference2) // list images - out = cli.DockerCmd(c, "images", "--digests").Stdout() + out = cli.DockerCmd(t, "images", "--digests").Stdout() // make sure repo shown, tag=, digest = $digest1 - assert.Assert(c, re1.MatchString(out), "expected %q: %s", re1.String(), out) + assert.Assert(t, re1.MatchString(out), "expected %q: %s", re1.String(), out) // make sure repo shown, tag=, digest = $digest2 re2 := regexp.MustCompile(`\s*` + repoName + `\s*\s*` + digest2.String() + `\s`) - assert.Assert(c, re2.MatchString(out), "expected %q: %s", re2.String(), out) + assert.Assert(t, re2.MatchString(out), "expected %q: %s", re2.String(), out) // pull tag1 - cli.DockerCmd(c, "pull", repoName+":tag1") + cli.DockerCmd(t, "pull", repoName+":tag1") // list images - out = cli.DockerCmd(c, "images", "--digests").Stdout() + out = cli.DockerCmd(t, "images", "--digests").Stdout() // make sure image 1 has repo, tag, AND repo, , digest reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*tag1\s*` + digest1.String() + `\s`) - assert.Assert(c, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out) + assert.Assert(t, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out) // make sure image 2 has repo, , digest - assert.Assert(c, re2.MatchString(out), "expected %q: %s", re2.String(), out) + assert.Assert(t, re2.MatchString(out), "expected %q: %s", re2.String(), out) // pull tag 2 - cli.DockerCmd(c, "pull", repoName+":tag2") + cli.DockerCmd(t, "pull", repoName+":tag2") // list images - out = cli.DockerCmd(c, "images", "--digests").Stdout() + out = cli.DockerCmd(t, "images", "--digests").Stdout() // make sure image 1 has repo, tag, digest - assert.Assert(c, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out) + assert.Assert(t, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out) // make sure image 2 has repo, tag, digest reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*tag2\s*` + digest2.String() + `\s`) - assert.Assert(c, reWithDigest2.MatchString(out), "expected %q: %s", reWithDigest2.String(), out) + assert.Assert(t, reWithDigest2.MatchString(out), "expected %q: %s", reWithDigest2.String(), out) // list images - out = cli.DockerCmd(c, "images", "--digests").Stdout() + out = cli.DockerCmd(t, "images", "--digests").Stdout() // make sure image 1 has repo, tag, digest - assert.Assert(c, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out) + assert.Assert(t, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out) // make sure image 2 has repo, tag, digest - assert.Assert(c, reWithDigest2.MatchString(out), "expected %q: %s", reWithDigest2.String(), out) + assert.Assert(t, reWithDigest2.MatchString(out), "expected %q: %s", reWithDigest2.String(), out) // We always have a digest when using containerd to store images if !testEnv.UsingSnapshotter() { // make sure busybox has tag, but not digest busyboxRe := regexp.MustCompile(`\s*busybox\s*latest\s*\s`) - assert.Assert(c, busyboxRe.MatchString(out), "expected %q: %s", busyboxRe.String(), out) + assert.Assert(t, busyboxRe.MatchString(out), "expected %q: %s", busyboxRe.String(), out) } } -func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(c *testing.T) { +func (s *DockerRegistrySuite) TestListDanglingImagesWithDigests(t *testing.T) { // See https://github.com/moby/moby/pull/46856 - skip.If(c, testEnv.UsingSnapshotter(), "dangling=true filter behaves a bit differently with c8d") + skip.If(t, testEnv.UsingSnapshotter(), "dangling=true filter behaves a bit differently with c8d") // setup image1 - digest1, err := setupImageWithTag(c, "dangle1") - assert.NilError(c, err, "error setting up image") + digest1, err := setupImageWithTag(t, "dangle1") + assert.NilError(t, err, "error setting up image") imageReference1 := fmt.Sprintf("%s@%s", repoName, digest1) - c.Logf("imageReference1 = %s", imageReference1) + t.Logf("imageReference1 = %s", imageReference1) // pull image1 by digest - cli.DockerCmd(c, "pull", imageReference1) + cli.DockerCmd(t, "pull", imageReference1) // list images - out := cli.DockerCmd(c, "images", "--digests").Stdout() + out := cli.DockerCmd(t, "images", "--digests").Stdout() // make sure repo shown, tag=, digest = $digest1 re1 := regexp.MustCompile(`\s*` + repoName + `\s*\s*` + digest1.String() + `\s`) - assert.Assert(c, re1.MatchString(out), "expected %q: %s", re1.String(), out) + assert.Assert(t, re1.MatchString(out), "expected %q: %s", re1.String(), out) // setup image2 - digest2, err := setupImageWithTag(c, "dangle2") + digest2, err := setupImageWithTag(t, "dangle2") // error setting up image - assert.NilError(c, err) + assert.NilError(t, err) imageReference2 := fmt.Sprintf("%s@%s", repoName, digest2) - c.Logf("imageReference2 = %s", imageReference2) + t.Logf("imageReference2 = %s", imageReference2) // pull image1 by digest - cli.DockerCmd(c, "pull", imageReference1) + cli.DockerCmd(t, "pull", imageReference1) // pull image2 by digest - cli.DockerCmd(c, "pull", imageReference2) + cli.DockerCmd(t, "pull", imageReference2) // list images - out = cli.DockerCmd(c, "images", "--digests", "--filter=dangling=true").Stdout() + out = cli.DockerCmd(t, "images", "--digests", "--filter=dangling=true").Stdout() // make sure repo shown, tag=, digest = $digest1 - assert.Assert(c, re1.MatchString(out), "expected %q: %s", re1.String(), out) + assert.Assert(t, re1.MatchString(out), "expected %q: %s", re1.String(), out) // make sure repo shown, tag=, digest = $digest2 re2 := regexp.MustCompile(`\s*` + repoName + `\s*\s*` + digest2.String() + `\s`) - assert.Assert(c, re2.MatchString(out), "expected %q: %s", re2.String(), out) + assert.Assert(t, re2.MatchString(out), "expected %q: %s", re2.String(), out) // pull dangle1 tag - cli.DockerCmd(c, "pull", repoName+":dangle1") + cli.DockerCmd(t, "pull", repoName+":dangle1") // list images - out = cli.DockerCmd(c, "images", "--digests", "--filter=dangling=true").Stdout() + out = cli.DockerCmd(t, "images", "--digests", "--filter=dangling=true").Stdout() // make sure image 1 has repo, tag, AND repo, , digest reWithDigest1 := regexp.MustCompile(`\s*` + repoName + `\s*dangle1\s*` + digest1.String() + `\s`) - assert.Assert(c, !reWithDigest1.MatchString(out), "unexpected %q: %s", reWithDigest1.String(), out) + assert.Assert(t, !reWithDigest1.MatchString(out), "unexpected %q: %s", reWithDigest1.String(), out) // make sure image 2 has repo, , digest - assert.Assert(c, re2.MatchString(out), "expected %q: %s", re2.String(), out) + assert.Assert(t, re2.MatchString(out), "expected %q: %s", re2.String(), out) // pull dangle2 tag - cli.DockerCmd(c, "pull", repoName+":dangle2") + cli.DockerCmd(t, "pull", repoName+":dangle2") // list images, show tagged images - out = cli.DockerCmd(c, "images", "--digests").Stdout() + out = cli.DockerCmd(t, "images", "--digests").Stdout() // make sure image 1 has repo, tag, digest - assert.Assert(c, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out) + assert.Assert(t, reWithDigest1.MatchString(out), "expected %q: %s", reWithDigest1.String(), out) // make sure image 2 has repo, tag, digest reWithDigest2 := regexp.MustCompile(`\s*` + repoName + `\s*dangle2\s*` + digest2.String() + `\s`) - assert.Assert(c, reWithDigest2.MatchString(out), "expected %q: %s", reWithDigest2.String(), out) + assert.Assert(t, reWithDigest2.MatchString(out), "expected %q: %s", reWithDigest2.String(), out) // list images, no longer dangling, should not match - out = cli.DockerCmd(c, "images", "--digests", "--filter=dangling=true").Stdout() + out = cli.DockerCmd(t, "images", "--digests", "--filter=dangling=true").Stdout() // make sure image 1 has repo, tag, digest - assert.Assert(c, !reWithDigest1.MatchString(out), "unexpected %q: %s", reWithDigest1.String(), out) + assert.Assert(t, !reWithDigest1.MatchString(out), "unexpected %q: %s", reWithDigest1.String(), out) // make sure image 2 has repo, tag, digest - assert.Assert(c, !reWithDigest2.MatchString(out), "unexpected %q: %s", reWithDigest2.String(), out) + assert.Assert(t, !reWithDigest2.MatchString(out), "unexpected %q: %s", reWithDigest2.String(), out) } -func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *testing.T) { - imgDigest, err := setupImage(c) - assert.Assert(c, err == nil, "error setting up image") +func (s *DockerRegistrySuite) TestInspectImageWithDigests(t *testing.T) { + imgDigest, err := setupImage(t) + assert.Assert(t, err == nil, "error setting up image") imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest) // pull from the registry using the @ reference - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) - out := cli.DockerCmd(c, "inspect", imageReference).Stdout() + out := cli.DockerCmd(t, "inspect", imageReference).Stdout() var imageJSON []image.InspectResponse err = json.Unmarshal([]byte(out), &imageJSON) - assert.NilError(c, err) - assert.Equal(c, len(imageJSON), 1) - assert.Equal(c, len(imageJSON[0].RepoDigests), 1) - assert.Check(c, is.Contains(imageJSON[0].RepoDigests, imageReference)) + assert.NilError(t, err) + assert.Equal(t, len(imageJSON), 1) + assert.Equal(t, len(imageJSON[0].RepoDigests), 1) + assert.Check(t, is.Contains(imageJSON[0].RepoDigests, imageReference)) } -func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c *testing.T) { - existingContainers := ExistingContainerIDs(c) +func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(t *testing.T) { + existingContainers := ExistingContainerIDs(t) - imgDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") + imgDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") imageReference := fmt.Sprintf("%s@%s", repoName, imgDigest) // pull from the registry using the @ reference - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) // build an image from it const imageName1 = "images_ps_filter_test" - buildImageSuccessfully(c, imageName1, build.WithDockerfile(fmt.Sprintf( + buildImageSuccessfully(t, imageName1, build.WithDockerfile(fmt.Sprintf( `FROM %s LABEL match me 1`, imageReference))) // run a container based on that - cli.DockerCmd(c, "run", "--name=test1", imageReference, "echo", "hello") - expectedID := getIDByName(c, "test1") + cli.DockerCmd(t, "run", "--name=test1", imageReference, "echo", "hello") + expectedID := getIDByName(t, "test1") // run a container based on the a descendant of that too - cli.DockerCmd(c, "run", "--name=test2", imageName1, "echo", "hello") - expectedID1 := getIDByName(c, "test2") + cli.DockerCmd(t, "run", "--name=test2", imageName1, "echo", "hello") + expectedID1 := getIDByName(t, "test2") expectedIDs := []string{expectedID, expectedID1} // Invalid imageReference - out := cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc", fmt.Sprintf("--filter=ancestor=busybox@%s", imgDigest)).Stdout() - assert.Equal(c, strings.TrimSpace(out), "", "Filter container for ancestor filter should be empty") + out := cli.DockerCmd(t, "ps", "-a", "-q", "--no-trunc", fmt.Sprintf("--filter=ancestor=busybox@%s", imgDigest)).Stdout() + assert.Equal(t, strings.TrimSpace(out), "", "Filter container for ancestor filter should be empty") // Valid imageReference - out = cli.DockerCmd(c, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageReference).Stdout() - checkPsAncestorFilterOutput(c, RemoveOutputForExistingElements(out, existingContainers), imageReference, expectedIDs) + out = cli.DockerCmd(t, "ps", "-a", "-q", "--no-trunc", "--filter=ancestor="+imageReference).Stdout() + checkPsAncestorFilterOutput(t, RemoveOutputForExistingElements(out, existingContainers), imageReference, expectedIDs) } -func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(c *testing.T) { - pushDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestDeleteImageByIDOnlyPulledByDigest(t *testing.T) { + pushDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") // pull from the registry using the @ reference imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) // just in case... - cli.DockerCmd(c, "tag", imageReference, repoName+":sometag") + cli.DockerCmd(t, "tag", imageReference, repoName+":sometag") - imageID := inspectField(c, imageReference, "Id") + imageID := inspectField(t, imageReference, "Id") - cli.DockerCmd(c, "rmi", imageID) + cli.DockerCmd(t, "rmi", imageID) _, err = inspectFieldWithError(imageID, "Id") - assert.ErrorContains(c, err, "", "image should have been deleted") + assert.ErrorContains(t, err, "", "image should have been deleted") } -func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(c *testing.T) { - pushDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndTag(t *testing.T) { + pushDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") // pull from the registry using the @ reference imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) - imageID := inspectField(c, imageReference, "Id") + imageID := inspectField(t, imageReference, "Id") const repoTag = repoName + ":sometag" const repoTag2 = repoName + ":othertag" - cli.DockerCmd(c, "tag", imageReference, repoTag) - cli.DockerCmd(c, "tag", imageReference, repoTag2) + cli.DockerCmd(t, "tag", imageReference, repoTag) + cli.DockerCmd(t, "tag", imageReference, repoTag2) - cli.DockerCmd(c, "rmi", repoTag2) + cli.DockerCmd(t, "rmi", repoTag2) // rmi should have deleted only repoTag2, because there's another tag - inspectField(c, repoTag, "Id") + inspectField(t, repoTag, "Id") - cli.DockerCmd(c, "rmi", repoTag) + cli.DockerCmd(t, "rmi", repoTag) // rmi should have deleted the tag, the digest reference, and the image itself _, err = inspectFieldWithError(imageID, "Id") - assert.ErrorContains(c, err, "", "image should have been deleted") + assert.ErrorContains(t, err, "", "image should have been deleted") } -func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(c *testing.T) { - pushDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestDeleteImageWithDigestAndMultiRepoTag(t *testing.T) { + pushDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") repo2 := fmt.Sprintf("%s/%s", repoName, "repo2") // pull from the registry using the @ reference imageReference := fmt.Sprintf("%s@%s", repoName, pushDigest) - cli.DockerCmd(c, "pull", imageReference) + cli.DockerCmd(t, "pull", imageReference) - imageID := inspectField(c, imageReference, "Id") + imageID := inspectField(t, imageReference, "Id") repoTag := repoName + ":sometag" repoTag2 := repo2 + ":othertag" - cli.DockerCmd(c, "tag", imageReference, repoTag) - cli.DockerCmd(c, "tag", imageReference, repoTag2) + cli.DockerCmd(t, "tag", imageReference, repoTag) + cli.DockerCmd(t, "tag", imageReference, repoTag2) - cli.DockerCmd(c, "rmi", repoTag) + cli.DockerCmd(t, "rmi", repoTag) // rmi should have deleted repoTag and image reference, but left repoTag2 - inspectField(c, repoTag2, "Id") + inspectField(t, repoTag2, "Id") _, err = inspectFieldWithError(imageReference, "Id") - assert.ErrorContains(c, err, "", "image digest reference should have been removed") + assert.ErrorContains(t, err, "", "image digest reference should have been removed") _, err = inspectFieldWithError(repoTag, "Id") - assert.ErrorContains(c, err, "", "image tag reference should have been removed") + assert.ErrorContains(t, err, "", "image tag reference should have been removed") - cli.DockerCmd(c, "rmi", repoTag2) + cli.DockerCmd(t, "rmi", repoTag2) // rmi should have deleted the tag, the digest reference, and the image itself _, err = inspectFieldWithError(imageID, "Id") - assert.ErrorContains(c, err, "", "image should have been deleted") + assert.ErrorContains(t, err, "", "image should have been deleted") } // TestPullFailsWithAlteredManifest tests that a `docker pull` fails when // we have modified a manifest blob and its digest cannot be verified. // This is the schema2 version of the test. -func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *testing.T) { - testRequires(c, DaemonIsLinux) - manifestDigest, err := setupImage(c) - assert.NilError(c, err, "error setting up image") +func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(t *testing.T) { + testRequires(t, DaemonIsLinux) + manifestDigest, err := setupImage(t) + assert.NilError(t, err, "error setting up image") // Load the target manifest blob. - manifestBlob := s.reg.ReadBlobContents(c, manifestDigest) + manifestBlob := s.reg.ReadBlobContents(t, manifestDigest) var imgManifest schema2.Manifest err = json.Unmarshal(manifestBlob, &imgManifest) - assert.NilError(c, err, "unable to decode image manifest from blob") + assert.NilError(t, err, "unable to decode image manifest from blob") // Change a layer in the manifest. imgManifest.Layers[0].Digest = digest.Digest("sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") // Move the existing data file aside, so that we can replace it with a // malicious blob of data. NOTE: we defer the returned undo func. - undo := s.reg.TempMoveBlobData(c, manifestDigest) + undo := s.reg.TempMoveBlobData(t, manifestDigest) defer undo() alteredManifestBlob, err := json.MarshalIndent(imgManifest, "", " ") - assert.NilError(c, err, "unable to encode altered image manifest to JSON") + assert.NilError(t, err, "unable to encode altered image manifest to JSON") - s.reg.WriteBlobContents(c, manifestDigest, alteredManifestBlob) + s.reg.WriteBlobContents(t, manifestDigest, alteredManifestBlob) // Now try pulling that image by digest. We should get an error about // digest verification for the manifest digest. @@ -541,57 +541,57 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredManifest(c *testing.T) { // Pull from the registry using the @ reference. imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest) out, exitStatus, _ := dockerCmdWithError("pull", imageReference) - assert.Assert(c, exitStatus != 0) + assert.Assert(t, exitStatus != 0) if testEnv.UsingSnapshotter() { - assert.Assert(c, is.Contains(out, "unexpected commit digest")) - assert.Assert(c, is.Contains(out, "expected "+manifestDigest)) + assert.Assert(t, is.Contains(out, "unexpected commit digest")) + assert.Assert(t, is.Contains(out, "expected "+manifestDigest)) } else { - assert.Assert(c, is.Contains(out, fmt.Sprintf("manifest verification failed for digest %s", manifestDigest))) + assert.Assert(t, is.Contains(out, fmt.Sprintf("manifest verification failed for digest %s", manifestDigest))) } } // TestPullFailsWithAlteredLayer tests that a `docker pull` fails when // we have modified a layer blob and its digest cannot be verified. // This is the schema2 version of the test. -func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *testing.T) { - testRequires(c, DaemonIsLinux) - skip.If(c, testEnv.UsingSnapshotter(), "Faked layer is already in the content store, so it won't be fetched from the repository at all.") +func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(t *testing.T) { + testRequires(t, DaemonIsLinux) + skip.If(t, 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.NilError(c, err) + manifestDigest, err := setupImage(t) + assert.NilError(t, err) // Load the target manifest blob. - manifestBlob := s.reg.ReadBlobContents(c, manifestDigest) + manifestBlob := s.reg.ReadBlobContents(t, manifestDigest) var imgManifest schema2.Manifest err = json.Unmarshal(manifestBlob, &imgManifest) - assert.NilError(c, err) + assert.NilError(t, err) // Next, get the digest of one of the layers from the manifest. targetLayerDigest := imgManifest.Layers[0].Digest // Move the existing data file aside, so that we can replace it with a // malicious blob of data. NOTE: we defer the returned undo func. - undo := s.reg.TempMoveBlobData(c, targetLayerDigest) + undo := s.reg.TempMoveBlobData(t, targetLayerDigest) defer undo() // Now make a fake data blob in this directory. - s.reg.WriteBlobContents(c, targetLayerDigest, []byte("This is not the data you are looking for.")) + s.reg.WriteBlobContents(t, targetLayerDigest, []byte("This is not the data you are looking for.")) // Now try pulling that image by digest. We should get an error about // digest verification for the target layer digest. // Remove distribution cache to force a re-pull of the blobs if err := os.RemoveAll(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "image", s.d.StorageDriver(), "distribution")); err != nil { - c.Fatalf("error clearing distribution cache: %v", err) + t.Fatalf("error clearing distribution cache: %v", err) } // Pull from the registry using the @ reference. imageReference := fmt.Sprintf("%s@%s", repoName, manifestDigest) out, exitStatus, _ := dockerCmdWithError("pull", imageReference) - assert.Assert(c, exitStatus != 0, "expected a non-zero exit status") + assert.Assert(t, exitStatus != 0, "expected a non-zero exit status") expectedErrorMsg := fmt.Sprintf("filesystem layer verification failed for digest %s", targetLayerDigest) - assert.Assert(c, strings.Contains(out, expectedErrorMsg), "expected error message in output: %s", out) + assert.Assert(t, strings.Contains(out, expectedErrorMsg), "expected error message in output: %s", out) } diff --git a/integration-cli/docker_cli_commit_test.go b/integration-cli/docker_cli_commit_test.go index 4b3ac4604e..f2acb8e8b8 100644 --- a/integration-cli/docker_cli_commit_test.go +++ b/integration-cli/docker_cli_commit_test.go @@ -15,12 +15,12 @@ type DockerCLICommitSuite struct { ds *DockerSuite } -func (s *DockerCLICommitSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLICommitSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLICommitSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLICommitSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLICommitSuite) TestCommitAfterContainerIsDone(c *testing.T) { diff --git a/integration-cli/docker_cli_cp_test.go b/integration-cli/docker_cli_cp_test.go index 9ef2ea65e3..28ca6212a9 100644 --- a/integration-cli/docker_cli_cp_test.go +++ b/integration-cli/docker_cli_cp_test.go @@ -32,12 +32,12 @@ type DockerCLICpSuite struct { ds *DockerSuite } -func (s *DockerCLICpSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLICpSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLICpSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLICpSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // Ensure that an all-local path case returns an error. diff --git a/integration-cli/docker_cli_cp_utils_test.go b/integration-cli/docker_cli_cp_utils_test.go index 21988aa41d..95e083d252 100644 --- a/integration-cli/docker_cli_cp_utils_test.go +++ b/integration-cli/docker_cli_cp_utils_test.go @@ -94,21 +94,21 @@ func defaultMkContentCommand() string { return mkFilesCommand(defaultFileData) } -func makeTestContentInDir(c *testing.T, dir string) { - c.Helper() +func makeTestContentInDir(t *testing.T, dir string) { + t.Helper() for _, fd := range defaultFileData { path := filepath.Join(dir, filepath.FromSlash(fd.path)) switch fd.filetype { case ftRegular: - assert.NilError(c, os.WriteFile(path, []byte(fd.contents+"\n"), os.FileMode(fd.mode))) + assert.NilError(t, os.WriteFile(path, []byte(fd.contents+"\n"), os.FileMode(fd.mode))) case ftDir: - assert.NilError(c, os.Mkdir(path, os.FileMode(fd.mode))) + assert.NilError(t, os.Mkdir(path, os.FileMode(fd.mode))) case ftSymlink: - assert.NilError(c, os.Symlink(fd.contents, path)) + assert.NilError(t, os.Symlink(fd.contents, path)) } if fd.filetype != ftSymlink && runtime.GOOS != "windows" { - assert.NilError(c, os.Chown(path, fd.uid, fd.gid)) + assert.NilError(t, os.Chown(path, fd.uid, fd.gid)) } } } @@ -121,8 +121,8 @@ type testContainerOptions struct { command string } -func makeTestContainer(c *testing.T, options testContainerOptions) (containerID string) { - c.Helper() +func makeTestContainer(t *testing.T, options testContainerOptions) (containerID string) { + t.Helper() if options.addContent { mkContentCmd := defaultMkContentCommand() if options.command == "" { @@ -152,17 +152,17 @@ func makeTestContainer(c *testing.T, options testContainerOptions) (containerID args = append(args, "busybox", "/bin/sh", "-c", options.command) - out := cli.DockerCmd(c, args...).Combined() + out := cli.DockerCmd(t, args...).Combined() containerID = strings.TrimSpace(out) - out = cli.DockerCmd(c, "wait", containerID).Combined() + out = cli.DockerCmd(t, "wait", containerID).Combined() exitCode := strings.TrimSpace(out) if exitCode != "0" { - out = cli.DockerCmd(c, "logs", containerID).Combined() + out = cli.DockerCmd(t, "logs", containerID).Combined() } - assert.Equal(c, exitCode, "0", "failed to make test container: %s", out) + assert.Equal(t, exitCode, "0", "failed to make test container: %s", out) return containerID } @@ -192,8 +192,8 @@ func containerCpPathTrailingSep(containerID string, pathElements ...string) stri return fmt.Sprintf("%s/", containerCpPath(containerID, pathElements...)) } -func runDockerCp(c *testing.T, src, dst string) error { - c.Helper() +func runDockerCp(t *testing.T, src, dst string) error { + t.Helper() args := []string{"cp", src, dst} if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, args...)); err != nil { @@ -202,8 +202,8 @@ func runDockerCp(c *testing.T, src, dst string) error { return nil } -func startContainerGetOutput(c *testing.T, containerID string) (string, error) { - c.Helper() +func startContainerGetOutput(t *testing.T, containerID string) (string, error) { + t.Helper() args := []string{"start", "-a", containerID} @@ -215,13 +215,13 @@ func startContainerGetOutput(c *testing.T, containerID string) (string, error) { return out, nil } -func getTestDir(c *testing.T, label string) (tmpDir string) { - c.Helper() +func getTestDir(t *testing.T, label string) (tmpDir string) { + t.Helper() var err error tmpDir, err = os.MkdirTemp("", label) // unable to make temporary directory - assert.NilError(c, err) + assert.NilError(t, err) return tmpDir } @@ -234,8 +234,8 @@ func isCpCannotCopyDir(err error) is.Comparison { return is.ErrorContains(err, archive.ErrCannotCopyDir.Error()) } -func fileContentEquals(c *testing.T, filename, contents string) error { - c.Helper() +func fileContentEquals(t *testing.T, filename, contents string) error { + t.Helper() fileBytes, err := os.ReadFile(filename) if err != nil { @@ -254,8 +254,8 @@ func fileContentEquals(c *testing.T, filename, contents string) error { return nil } -func symlinkTargetEquals(c *testing.T, symlink, expectedTarget string) error { - c.Helper() +func symlinkTargetEquals(t *testing.T, symlink, expectedTarget string) error { + t.Helper() actualTarget, err := os.Readlink(symlink) if err != nil { @@ -269,10 +269,10 @@ func symlinkTargetEquals(c *testing.T, symlink, expectedTarget string) error { return nil } -func containerStartOutputEquals(c *testing.T, containerID, contents string) error { - c.Helper() +func containerStartOutputEquals(t *testing.T, containerID, contents string) error { + t.Helper() - out, err := startContainerGetOutput(c, containerID) + out, err := startContainerGetOutput(t, containerID) if err != nil { return err } diff --git a/integration-cli/docker_cli_create_test.go b/integration-cli/docker_cli_create_test.go index 4a0824d9c6..4e49637e56 100644 --- a/integration-cli/docker_cli_create_test.go +++ b/integration-cli/docker_cli_create_test.go @@ -21,12 +21,12 @@ type DockerCLICreateSuite struct { ds *DockerSuite } -func (s *DockerCLICreateSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLICreateSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLICreateSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLICreateSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // Make sure we can create a simple container with some args diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 58ea0863d8..41205c0269 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -379,15 +379,15 @@ func (s *DockerDaemonSuite) TestDaemonBridgeNone(c *testing.T) { assert.Assert(c, is.Contains(out, "No such network")) } -func createInterface(c *testing.T, ifType string, ifName string, ipNet string) { - icmd.RunCommand("ip", "link", "add", "name", ifName, "type", ifType).Assert(c, icmd.Success) - icmd.RunCommand("ifconfig", ifName, ipNet, "up").Assert(c, icmd.Success) +func createInterface(t *testing.T, ifType string, ifName string, ipNet string) { + icmd.RunCommand("ip", "link", "add", "name", ifName, "type", ifType).Assert(t, icmd.Success) + icmd.RunCommand("ifconfig", ifName, ipNet, "up").Assert(t, icmd.Success) } -func deleteInterface(c *testing.T, ifName string) { - icmd.RunCommand("ip", "link", "delete", ifName).Assert(c, icmd.Success) - icmd.RunCommand("iptables", "-t", "nat", "--flush").Assert(c, icmd.Success) - icmd.RunCommand("iptables", "--flush").Assert(c, icmd.Success) +func deleteInterface(t *testing.T, ifName string) { + icmd.RunCommand("ip", "link", "delete", ifName).Assert(t, icmd.Success) + icmd.RunCommand("iptables", "-t", "nat", "--flush").Assert(t, icmd.Success) + icmd.RunCommand("iptables", "--flush").Assert(t, icmd.Success) } func (s *DockerDaemonSuite) TestDaemonUlimitDefaults(c *testing.T) { @@ -2129,35 +2129,35 @@ func (s *DockerDaemonSuite) TestShmSizeReload(c *testing.T) { assert.Equal(c, strings.TrimSpace(out), fmt.Sprintf("%v", size)) } -func testDaemonStartIpcMode(c *testing.T, from, mode string, valid bool) { - d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) - c.Logf("Checking IpcMode %s set from %s\n", mode, from) +func testDaemonStartIpcMode(t *testing.T, from, mode string, valid bool) { + d := daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) + t.Logf("Checking IpcMode %s set from %s\n", mode, from) var serr error switch from { case "config": f, err := os.CreateTemp("", "test-daemon-ipc-config") - assert.NilError(c, err) + assert.NilError(t, err) defer os.Remove(f.Name()) config := `{"default-ipc-mode": "` + mode + `"}` _, err = f.WriteString(config) - assert.NilError(c, f.Close()) - assert.NilError(c, err) + assert.NilError(t, f.Close()) + assert.NilError(t, err) serr = d.StartWithError("--config-file", f.Name()) case "cli": serr = d.StartWithError("--default-ipc-mode", mode) default: - c.Fatalf("testDaemonStartIpcMode: invalid 'from' argument") + t.Fatalf("testDaemonStartIpcMode: invalid 'from' argument") } if serr == nil { - d.Stop(c) + d.Stop(t) } if valid { - assert.NilError(c, serr) + assert.NilError(t, serr) } else { - assert.ErrorContains(c, serr, "") - icmd.RunCommand("grep", "-E", "IPC .* is (invalid|not supported)", d.LogFileName()).Assert(c, icmd.Success) + assert.ErrorContains(t, serr, "") + icmd.RunCommand("grep", "-E", "IPC .* is (invalid|not supported)", d.LogFileName()).Assert(t, icmd.Success) } } diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index 5c67881bc9..875bf6c061 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -29,12 +29,12 @@ type DockerCLIEventSuite struct { ds *DockerSuite } -func (s *DockerCLIEventSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIEventSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIEventSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIEventSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) { diff --git a/integration-cli/docker_cli_exec_test.go b/integration-cli/docker_cli_exec_test.go index e5de66e7d1..ae7f7e3c80 100644 --- a/integration-cli/docker_cli_exec_test.go +++ b/integration-cli/docker_cli_exec_test.go @@ -27,12 +27,12 @@ type DockerCLIExecSuite struct { ds *DockerSuite } -func (s *DockerCLIExecSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIExecSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIExecSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIExecSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIExecSuite) TestExec(c *testing.T) { diff --git a/integration-cli/docker_cli_external_volume_driver_test.go b/integration-cli/docker_cli_external_volume_driver_test.go index cf2a447a1e..df3c4b1bd4 100644 --- a/integration-cli/docker_cli_external_volume_driver_test.go +++ b/integration-cli/docker_cli_external_volume_driver_test.go @@ -47,21 +47,21 @@ type DockerExternalVolumeSuite struct { *volumePlugin } -func (s *DockerExternalVolumeSuite) SetUpTest(ctx context.Context, c *testing.T) { - testRequires(c, testEnv.IsLocalDaemon) - s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) +func (s *DockerExternalVolumeSuite) SetUpTest(ctx context.Context, t *testing.T) { + testRequires(t, testEnv.IsLocalDaemon) + s.d = daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) s.ec = &eventCounter{} } -func (s *DockerExternalVolumeSuite) TearDownTest(ctx context.Context, c *testing.T) { +func (s *DockerExternalVolumeSuite) TearDownTest(ctx context.Context, t *testing.T) { if s.d != nil { - s.d.Stop(c) - s.ds.TearDownTest(ctx, c) + s.d.Stop(t) + s.ds.TearDownTest(ctx, t) } } -func (s *DockerExternalVolumeSuite) SetUpSuite(ctx context.Context, c *testing.T) { - s.volumePlugin = newVolumePlugin(c, volumePluginName) +func (s *DockerExternalVolumeSuite) SetUpSuite(ctx context.Context, t *testing.T) { + s.volumePlugin = newVolumePlugin(t, volumePluginName) } type volumePlugin struct { @@ -274,11 +274,11 @@ func newVolumePlugin(t *testing.T, name string) *volumePlugin { return s } -func (s *DockerExternalVolumeSuite) TearDownSuite(ctx context.Context, c *testing.T) { +func (s *DockerExternalVolumeSuite) TearDownSuite(ctx context.Context, t *testing.T) { s.volumePlugin.Close() err := os.RemoveAll("/etc/docker/plugins") - assert.NilError(c, err) + assert.NilError(t, err) } func (s *DockerExternalVolumeSuite) TestVolumeCLICreateOptionConflict(c *testing.T) { diff --git a/integration-cli/docker_cli_health_test.go b/integration-cli/docker_cli_health_test.go index ccb7d38587..87358d71d9 100644 --- a/integration-cli/docker_cli_health_test.go +++ b/integration-cli/docker_cli_health_test.go @@ -18,23 +18,23 @@ type DockerCLIHealthSuite struct { ds *DockerSuite } -func (s *DockerCLIHealthSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIHealthSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIHealthSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIHealthSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } -func waitForHealthStatus(c *testing.T, name string, prev string, expected string) { +func waitForHealthStatus(t *testing.T, name string, prev string, expected string) { prev = prev + "\n" expected = expected + "\n" for { - out := cli.DockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name).Stdout() + out := cli.DockerCmd(t, "inspect", "--format={{.State.Health.Status}}", name).Stdout() if out == expected { return } - assert.Equal(c, out, prev) + assert.Equal(t, out, prev) if out != prev { return } @@ -42,11 +42,11 @@ func waitForHealthStatus(c *testing.T, name string, prev string, expected string } } -func getHealth(c *testing.T, name string) *container.Health { - out := cli.DockerCmd(c, "inspect", "--format={{json .State.Health}}", name).Stdout() +func getHealth(t *testing.T, name string) *container.Health { + out := cli.DockerCmd(t, "inspect", "--format={{json .State.Health}}", name).Stdout() var health container.Health err := json.Unmarshal([]byte(out), &health) - assert.Equal(c, err, nil) + assert.Equal(t, err, nil) return &health } diff --git a/integration-cli/docker_cli_history_test.go b/integration-cli/docker_cli_history_test.go index a6b0daf268..1f7421d3a0 100644 --- a/integration-cli/docker_cli_history_test.go +++ b/integration-cli/docker_cli_history_test.go @@ -18,12 +18,12 @@ type DockerCLIHistorySuite struct { ds *DockerSuite } -func (s *DockerCLIHistorySuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIHistorySuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIHistorySuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIHistorySuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // This is a heisen-test. Because the created timestamp of images and the behavior of diff --git a/integration-cli/docker_cli_images_test.go b/integration-cli/docker_cli_images_test.go index 4e625f993a..ca18cde19b 100644 --- a/integration-cli/docker_cli_images_test.go +++ b/integration-cli/docker_cli_images_test.go @@ -23,12 +23,12 @@ type DockerCLIImagesSuite struct { ds *DockerSuite } -func (s *DockerCLIImagesSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIImagesSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIImagesSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIImagesSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIImagesSuite) TestImagesEnsureImageIsListed(c *testing.T) { diff --git a/integration-cli/docker_cli_import_test.go b/integration-cli/docker_cli_import_test.go index 14a2c2c08f..b8cb403d46 100644 --- a/integration-cli/docker_cli_import_test.go +++ b/integration-cli/docker_cli_import_test.go @@ -18,12 +18,12 @@ type DockerCLIImportSuite struct { ds *DockerSuite } -func (s *DockerCLIImportSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIImportSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIImportSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIImportSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIImportSuite) TestImportDisplay(c *testing.T) { diff --git a/integration-cli/docker_cli_info_test.go b/integration-cli/docker_cli_info_test.go index 7f5a24542b..b527f67e41 100644 --- a/integration-cli/docker_cli_info_test.go +++ b/integration-cli/docker_cli_info_test.go @@ -16,12 +16,12 @@ type DockerCLIInfoSuite struct { ds *DockerSuite } -func (s *DockerCLIInfoSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIInfoSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIInfoSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIInfoSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // ensure docker info succeeds @@ -114,11 +114,11 @@ func (s *DockerCLIInfoSuite) TestInfoDisplaysStoppedContainers(c *testing.T) { assert.Assert(c, is.Contains(out, fmt.Sprintf(" Stopped: %d\n", existing["ContainersStopped"]+1))) } -func existingContainerStates(c *testing.T) map[string]int { - out := cli.DockerCmd(c, "info", "--format", "{{json .}}").Stdout() +func existingContainerStates(t *testing.T) map[string]int { + out := cli.DockerCmd(t, "info", "--format", "{{json .}}").Stdout() var m map[string]interface{} err := json.Unmarshal([]byte(out), &m) - assert.NilError(c, err) + assert.NilError(t, err) res := map[string]int{} res["Containers"] = int(m["Containers"].(float64)) res["ContainersRunning"] = int(m["ContainersRunning"].(float64)) diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index 0853e86ba6..c8c7102e73 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/integration-cli/docker_cli_inspect_test.go @@ -23,12 +23,12 @@ type DockerCLIInspectSuite struct { ds *DockerSuite } -func (s *DockerCLIInspectSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIInspectSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIInspectSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIInspectSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIInspectSuite) TestInspectImage(c *testing.T) { diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index 06deefaf70..0f5eb93250 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -19,12 +19,12 @@ type DockerCLILinksSuite struct { ds *DockerSuite } -func (s *DockerCLILinksSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLILinksSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLILinksSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLILinksSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLILinksSuite) TestLinksPingUnlinkedContainers(c *testing.T) { @@ -53,7 +53,7 @@ func (s *DockerCLILinksSuite) TestLinksPingLinkedContainers(c *testing.T) { testLinkPingOnNetwork(c, "bridge") } -func testLinkPingOnNetwork(c *testing.T, network string) { +func testLinkPingOnNetwork(t *testing.T, network string) { var postArgs []string if network != "" { postArgs = append(postArgs, []string{"--net", network}...) @@ -63,8 +63,8 @@ func testLinkPingOnNetwork(c *testing.T, network string) { runArgs2 := append([]string{"run", "-d", "--name", "container2", "--hostname", "wilma"}, postArgs...) // Run the two named containers - cli.DockerCmd(c, runArgs1...) - cli.DockerCmd(c, runArgs2...) + cli.DockerCmd(t, runArgs1...) + cli.DockerCmd(t, runArgs2...) postArgs = []string{} if network != "" { @@ -78,15 +78,15 @@ func testLinkPingOnNetwork(c *testing.T, network string) { // test ping by alias, ping by name, and ping by hostname // 1. Ping by alias - cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "alias1", "alias2"))...) + cli.DockerCmd(t, append(runArgs, fmt.Sprintf(pingCmd, "alias1", "alias2"))...) // 2. Ping by container name - cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "container1", "container2"))...) + cli.DockerCmd(t, append(runArgs, fmt.Sprintf(pingCmd, "container1", "container2"))...) // 3. Ping by hostname - cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...) + cli.DockerCmd(t, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...) // Clean for next round - cli.DockerCmd(c, "rm", "-f", "container1") - cli.DockerCmd(c, "rm", "-f", "container2") + cli.DockerCmd(t, "rm", "-f", "container1") + cli.DockerCmd(t, "rm", "-f", "container2") } func (s *DockerCLILinksSuite) TestLinksPingLinkedContainersAfterRename(c *testing.T) { diff --git a/integration-cli/docker_cli_login_test.go b/integration-cli/docker_cli_login_test.go index 374b5dbb2d..34ad02cbc5 100644 --- a/integration-cli/docker_cli_login_test.go +++ b/integration-cli/docker_cli_login_test.go @@ -15,12 +15,12 @@ type DockerCLILoginSuite struct { ds *DockerSuite } -func (s *DockerCLILoginSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLILoginSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLILoginSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLILoginSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLILoginSuite) TestLoginWithoutTTY(c *testing.T) { diff --git a/integration-cli/docker_cli_logs_test.go b/integration-cli/docker_cli_logs_test.go index 4909d9951e..b9fbdb0b77 100644 --- a/integration-cli/docker_cli_logs_test.go +++ b/integration-cli/docker_cli_logs_test.go @@ -24,12 +24,12 @@ type DockerCLILogsSuite struct { ds *DockerSuite } -func (s *DockerCLILogsSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLILogsSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLILogsSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLILogsSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // This used to work, it test a log of PageSize-1 (gh#4851) @@ -47,12 +47,12 @@ func (s *DockerCLILogsSuite) TestLogsContainerMuchBiggerThanPage(c *testing.T) { testLogsContainerPagination(c, 33000) } -func testLogsContainerPagination(c *testing.T, testLen int) { - id := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen)).Stdout() +func testLogsContainerPagination(t *testing.T, testLen int) { + id := cli.DockerCmd(t, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen)).Stdout() id = strings.TrimSpace(id) - cli.DockerCmd(c, "wait", id) - out := cli.DockerCmd(c, "logs", id).Combined() - assert.Equal(c, len(out), testLen+1) + cli.DockerCmd(t, "wait", id) + out := cli.DockerCmd(t, "logs", id).Combined() + assert.Equal(t, len(out), testLen+1) } func (s *DockerCLILogsSuite) TestLogsTimestamps(c *testing.T) { diff --git a/integration-cli/docker_cli_netmode_test.go b/integration-cli/docker_cli_netmode_test.go index 6d1467c49b..33fcd258c7 100644 --- a/integration-cli/docker_cli_netmode_test.go +++ b/integration-cli/docker_cli_netmode_test.go @@ -21,20 +21,20 @@ type DockerCLINetmodeSuite struct { ds *DockerSuite } -func (s *DockerCLINetmodeSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLINetmodeSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLINetmodeSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLINetmodeSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // DockerCmdWithFail executes a docker command that is supposed to fail and returns // the output. If the command returns a Nil error, it will fail and stop the tests. -func dockerCmdWithFail(c *testing.T, args ...string) string { - c.Helper() +func dockerCmdWithFail(t *testing.T, args ...string) string { + t.Helper() out, _, err := dockerCmdWithError(args...) - assert.Assert(c, err != nil, "%v", out) + assert.Assert(t, err != nil, "%v", out) return out } diff --git a/integration-cli/docker_cli_network_test.go b/integration-cli/docker_cli_network_test.go index 4670f71a17..7e66eebbc5 100644 --- a/integration-cli/docker_cli_network_test.go +++ b/integration-cli/docker_cli_network_test.go @@ -12,12 +12,12 @@ type DockerCLINetworkSuite struct { ds *DockerSuite } -func (s *DockerCLINetworkSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLINetworkSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLINetworkSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLINetworkSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } type DockerNetworkSuite struct { diff --git a/integration-cli/docker_cli_network_unix_test.go b/integration-cli/docker_cli_network_unix_test.go index c62577e24f..e26de3de57 100644 --- a/integration-cli/docker_cli_network_unix_test.go +++ b/integration-cli/docker_cli_network_unix_test.go @@ -43,22 +43,22 @@ const ( var remoteDriverNetworkRequest remoteapi.CreateNetworkRequest -func (s *DockerNetworkSuite) SetUpTest(ctx context.Context, c *testing.T) { - s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) +func (s *DockerNetworkSuite) SetUpTest(ctx context.Context, t *testing.T) { + s.d = daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) } -func (s *DockerNetworkSuite) TearDownTest(ctx context.Context, c *testing.T) { +func (s *DockerNetworkSuite) TearDownTest(ctx context.Context, t *testing.T) { if s.d != nil { - s.d.Stop(c) - s.ds.TearDownTest(ctx, c) + s.d.Stop(t) + s.ds.TearDownTest(ctx, t) } } -func (s *DockerNetworkSuite) SetUpSuite(ctx context.Context, c *testing.T) { +func (s *DockerNetworkSuite) SetUpSuite(ctx context.Context, t *testing.T) { mux := http.NewServeMux() s.server = httptest.NewServer(mux) - assert.Assert(c, s.server != nil, "Failed to start an HTTP Server") - setupRemoteNetworkDrivers(c, mux, s.server.URL, dummyNetworkDriver, dummyIPAMDriver) + assert.Assert(t, s.server != nil, "Failed to start an HTTP Server") + setupRemoteNetworkDrivers(t, mux, s.server.URL, dummyNetworkDriver, dummyIPAMDriver) } func setupRemoteNetworkDrivers(t *testing.T, mux *http.ServeMux, url, netDrv, ipamDrv string) { @@ -238,7 +238,7 @@ func setupRemoteNetworkDrivers(t *testing.T, mux *http.ServeMux, url, netDrv, ip assert.NilError(t, err) } -func (s *DockerNetworkSuite) TearDownSuite(ctx context.Context, c *testing.T) { +func (s *DockerNetworkSuite) TearDownSuite(ctx context.Context, t *testing.T) { if s.server == nil { return } @@ -246,23 +246,23 @@ func (s *DockerNetworkSuite) TearDownSuite(ctx context.Context, c *testing.T) { s.server.Close() err := os.RemoveAll("/etc/docker/plugins") - assert.NilError(c, err) + assert.NilError(t, err) } -func assertNwIsAvailable(c *testing.T, name string) { - if !isNwPresent(c, name) { - c.Fatalf("Network %s not found in network ls o/p", name) +func assertNwIsAvailable(t *testing.T, name string) { + if !isNwPresent(t, name) { + t.Fatalf("Network %s not found in network ls o/p", name) } } -func assertNwNotAvailable(c *testing.T, name string) { - if isNwPresent(c, name) { - c.Fatalf("Found network %s in network ls o/p", name) +func assertNwNotAvailable(t *testing.T, name string) { + if isNwPresent(t, name) { + t.Fatalf("Found network %s in network ls o/p", name) } } -func isNwPresent(c *testing.T, name string) bool { - out := cli.DockerCmd(c, "network", "ls").Stdout() +func isNwPresent(t *testing.T, name string) bool { + out := cli.DockerCmd(t, "network", "ls").Stdout() lines := strings.Split(out, "\n") for i := 1; i < len(lines)-1; i++ { netFields := strings.Fields(lines[i]) @@ -276,7 +276,7 @@ func isNwPresent(c *testing.T, name string) bool { // assertNwList checks network list retrieved with ls command // equals to expected network list // note: out should be `network ls [option]` result -func assertNwList(c *testing.T, out string, expectNws []string) { +func assertNwList(t *testing.T, out string, expectNws []string) { lines := strings.Split(out, "\n") var nwList []string for _, line := range lines[1 : len(lines)-1] { @@ -286,14 +286,14 @@ func assertNwList(c *testing.T, out string, expectNws []string) { } // network ls should contains all expected networks - assert.DeepEqual(c, nwList, expectNws) + assert.DeepEqual(t, nwList, expectNws) } -func getNwResource(c *testing.T, name string) *network.Inspect { - out := cli.DockerCmd(c, "network", "inspect", name).Stdout() +func getNwResource(t *testing.T, name string) *network.Inspect { + out := cli.DockerCmd(t, "network", "inspect", name).Stdout() var nr []network.Inspect err := json.Unmarshal([]byte(out), &nr) - assert.NilError(c, err) + assert.NilError(t, err) return &nr[0] } @@ -1051,26 +1051,26 @@ func (s *DockerCLINetworkSuite) TestInspectAPIMultipleNetworks(c *testing.T) { assert.Equal(c, bridge.IPAddress, inspectCurrent.NetworkSettings.IPAddress) } -func connectContainerToNetworks(c *testing.T, d *daemon.Daemon, cName string, nws []string) { +func connectContainerToNetworks(t *testing.T, d *daemon.Daemon, cName string, nws []string) { // Run a container on the default network out, err := d.Cmd("run", "-d", "--name", cName, "busybox", "top") - assert.NilError(c, err, out) + assert.NilError(t, err, out) // Attach the container to other networks for _, nw := range nws { out, err = d.Cmd("network", "create", nw) - assert.NilError(c, err, out) + assert.NilError(t, err, out) out, err = d.Cmd("network", "connect", nw, cName) - assert.NilError(c, err, out) + assert.NilError(t, err, out) } } -func verifyContainerIsConnectedToNetworks(c *testing.T, d *daemon.Daemon, cName string, nws []string) { +func verifyContainerIsConnectedToNetworks(t *testing.T, d *daemon.Daemon, cName string, nws []string) { // Verify container is connected to all the networks for _, nw := range nws { out, err := d.Cmd("inspect", "-f", fmt.Sprintf("{{.NetworkSettings.Networks.%s}}", nw), cName) - assert.NilError(c, err, out) - assert.Assert(c, out != "\n") + assert.NilError(t, err, out) + assert.Assert(t, out != "\n") } } @@ -1173,12 +1173,12 @@ func (s *DockerNetworkSuite) TestDockerNetworkConnectWithPortMapping(c *testing. cli.DockerCmd(c, "network", "connect", "test1", "c1") } -func verifyPortMap(c *testing.T, container, port, originalMapping string, mustBeEqual bool) { - currentMapping := cli.DockerCmd(c, "port", container, port).Stdout() +func verifyPortMap(t *testing.T, container, port, originalMapping string, mustBeEqual bool) { + currentMapping := cli.DockerCmd(t, "port", container, port).Stdout() if mustBeEqual { - assert.Equal(c, currentMapping, originalMapping) + assert.Equal(t, currentMapping, originalMapping) } else { - assert.Assert(c, currentMapping != originalMapping) + assert.Assert(t, currentMapping != originalMapping) } } @@ -1370,30 +1370,30 @@ func (s *DockerNetworkSuite) TestDockerNetworkUnsupportedRequiredIP(c *testing.T assertNwNotAvailable(c, "n0") } -func checkUnsupportedNetworkAndIP(c *testing.T, nwMode string) { +func checkUnsupportedNetworkAndIP(t *testing.T, nwMode string) { out, _, err := dockerCmdWithError("run", "-d", "--net", nwMode, "--ip", "172.28.99.88", "--ip6", "2001:db8:1234::9988", "busybox", "top") - assert.Assert(c, err != nil, "out: %s", out) - assert.Assert(c, is.Contains(out, runconfig.ErrUnsupportedNetworkAndIP.Error())) + assert.Assert(t, err != nil, "out: %s", out) + assert.Assert(t, is.Contains(out, runconfig.ErrUnsupportedNetworkAndIP.Error())) } -func verifyIPAddressConfig(c *testing.T, cName, nwname, ipv4, ipv6 string) { +func verifyIPAddressConfig(t *testing.T, cName, nwname, ipv4, ipv6 string) { if ipv4 != "" { - out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAMConfig.IPv4Address", nwname)) - assert.Equal(c, strings.TrimSpace(out), ipv4) + out := inspectField(t, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAMConfig.IPv4Address", nwname)) + assert.Equal(t, strings.TrimSpace(out), ipv4) } if ipv6 != "" { - out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAMConfig.IPv6Address", nwname)) - assert.Equal(c, strings.TrimSpace(out), ipv6) + out := inspectField(t, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAMConfig.IPv6Address", nwname)) + assert.Equal(t, strings.TrimSpace(out), ipv6) } } -func verifyIPAddresses(c *testing.T, cName, nwname, ipv4, ipv6 string) { - out := inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAddress", nwname)) - assert.Equal(c, strings.TrimSpace(out), ipv4) +func verifyIPAddresses(t *testing.T, cName, nwname, ipv4, ipv6 string) { + out := inspectField(t, cName, fmt.Sprintf("NetworkSettings.Networks.%s.IPAddress", nwname)) + assert.Equal(t, strings.TrimSpace(out), ipv4) - out = inspectField(c, cName, fmt.Sprintf("NetworkSettings.Networks.%s.GlobalIPv6Address", nwname)) - assert.Equal(c, strings.TrimSpace(out), ipv6) + out = inspectField(t, cName, fmt.Sprintf("NetworkSettings.Networks.%s.GlobalIPv6Address", nwname)) + assert.Equal(t, strings.TrimSpace(out), ipv6) } func (s *DockerNetworkSuite) TestDockerNetworkConnectLinkLocalIP(c *testing.T) { diff --git a/integration-cli/docker_cli_plugins_logdriver_test.go b/integration-cli/docker_cli_plugins_logdriver_test.go index 5b100e991b..a21d456606 100644 --- a/integration-cli/docker_cli_plugins_logdriver_test.go +++ b/integration-cli/docker_cli_plugins_logdriver_test.go @@ -16,12 +16,12 @@ type DockerCLIPluginLogDriverSuite struct { ds *DockerSuite } -func (s *DockerCLIPluginLogDriverSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIPluginLogDriverSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIPluginLogDriverSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIPluginLogDriverSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIPluginLogDriverSuite) TestPluginLogDriver(c *testing.T) { diff --git a/integration-cli/docker_cli_plugins_test.go b/integration-cli/docker_cli_plugins_test.go index 162000dfbe..8ebf53e0f0 100644 --- a/integration-cli/docker_cli_plugins_test.go +++ b/integration-cli/docker_cli_plugins_test.go @@ -35,12 +35,12 @@ type DockerCLIPluginsSuite struct { ds *DockerSuite } -func (s *DockerCLIPluginsSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIPluginsSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIPluginsSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIPluginsSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (ps *DockerPluginSuite) TestPluginBasicOps(c *testing.T) { diff --git a/integration-cli/docker_cli_port_test.go b/integration-cli/docker_cli_port_test.go index af6c1560a0..0bb2568cba 100644 --- a/integration-cli/docker_cli_port_test.go +++ b/integration-cli/docker_cli_port_test.go @@ -19,12 +19,12 @@ type DockerCLIPortSuite struct { ds *DockerSuite } -func (s *DockerCLIPortSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIPortSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIPortSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIPortSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIPortSuite) TestPortList(c *testing.T) { @@ -163,10 +163,10 @@ func (s *DockerCLIPortSuite) TestPortList(c *testing.T) { cli.DockerCmd(c, "rm", "-f", id) } -func assertPortList(c *testing.T, out string, expected []string) { - c.Helper() +func assertPortList(t *testing.T, out string, expected []string) { + t.Helper() lines := strings.Split(strings.Trim(out, "\n "), "\n") - assert.Assert(c, is.Len(lines, len(expected)), "expected: %s", strings.Join(expected, ", ")) + assert.Assert(t, is.Len(lines, len(expected)), "expected: %s", strings.Join(expected, ", ")) sort.Strings(lines) sort.Strings(expected) @@ -184,7 +184,7 @@ func assertPortList(c *testing.T, out string, expected []string) { if lines[i] == expected[i] { continue } - assert.Equal(c, lines[i], oldFormat(expected[i])) + assert.Equal(t, lines[i], oldFormat(expected[i])) } } @@ -233,8 +233,8 @@ func assertPortRange(ctx context.Context, id string, expectedTCP, expectedUDP [] return nil } -func stopRemoveContainer(id string, c *testing.T) { - cli.DockerCmd(c, "rm", "-f", id) +func stopRemoveContainer(id string, t *testing.T) { + cli.DockerCmd(t, "rm", "-f", id) } func (s *DockerCLIPortSuite) TestUnpublishedPortsInPsOutput(c *testing.T) { diff --git a/integration-cli/docker_cli_proxy_test.go b/integration-cli/docker_cli_proxy_test.go index 551dfcb973..2c2c40c7ce 100644 --- a/integration-cli/docker_cli_proxy_test.go +++ b/integration-cli/docker_cli_proxy_test.go @@ -14,12 +14,12 @@ type DockerCLIProxySuite struct { ds *DockerSuite } -func (s *DockerCLIProxySuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIProxySuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIProxySuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIProxySuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIProxySuite) TestCLIProxyDisableProxyUnixSock(c *testing.T) { diff --git a/integration-cli/docker_cli_prune_unix_test.go b/integration-cli/docker_cli_prune_unix_test.go index 0f1369d530..429782739e 100644 --- a/integration-cli/docker_cli_prune_unix_test.go +++ b/integration-cli/docker_cli_prune_unix_test.go @@ -22,30 +22,30 @@ import ( "gotest.tools/v3/poll" ) -func (s *DockerCLIPruneSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIPruneSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIPruneSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIPruneSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } -func pruneNetworkAndVerify(c *testing.T, d *daemon.Daemon, kept, pruned []string) { +func pruneNetworkAndVerify(t *testing.T, d *daemon.Daemon, kept, pruned []string) { _, err := d.Cmd("network", "prune", "--force") - assert.NilError(c, err) + assert.NilError(t, err) for _, s := range kept { - poll.WaitOn(c, pollCheck(c, func(*testing.T) (interface{}, string) { + poll.WaitOn(t, pollCheck(t, func(*testing.T) (interface{}, string) { out, err := d.Cmd("network", "ls", "--format", "{{.Name}}") - assert.NilError(c, err) + assert.NilError(t, err) return out, "" }, checker.Contains(s)), poll.WithTimeout(defaultReconciliationTimeout)) } for _, s := range pruned { - poll.WaitOn(c, pollCheck(c, func(*testing.T) (interface{}, string) { + poll.WaitOn(t, pollCheck(t, func(*testing.T) (interface{}, string) { out, err := d.Cmd("network", "ls", "--format", "{{.Name}}") - assert.NilError(c, err) + assert.NilError(t, err) return out, "" }, checker.Not(checker.Contains(s))), poll.WithTimeout(defaultReconciliationTimeout)) } diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index 0896bad596..24a0bcfb22 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -22,12 +22,12 @@ type DockerCLIPsSuite struct { ds *DockerSuite } -func (s *DockerCLIPsSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIPsSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIPsSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIPsSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIPsSuite) TestPsListContainersBase(c *testing.T) { @@ -391,7 +391,7 @@ func (s *DockerCLIPsSuite) TestPsListContainersFilterAncestorImage(c *testing.T) checkPsAncestorFilterOutput(c, RemoveOutputForExistingElements(out, existingContainers), imageName2+","+imageName1Tagged, []string{fourthID, fifthID}) } -func checkPsAncestorFilterOutput(c *testing.T, out string, filterName string, expectedIDs []string) { +func checkPsAncestorFilterOutput(t *testing.T, out string, filterName string, expectedIDs []string) { var actualIDs []string if out != "" { actualIDs = strings.Split(out[:len(out)-1], "\n") @@ -399,17 +399,17 @@ func checkPsAncestorFilterOutput(c *testing.T, out string, filterName string, ex sort.Strings(actualIDs) sort.Strings(expectedIDs) - assert.Equal(c, len(actualIDs), len(expectedIDs), fmt.Sprintf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs)) + assert.Equal(t, len(actualIDs), len(expectedIDs), fmt.Sprintf("Expected filtered container(s) for %s ancestor filter to be %v:%v, got %v:%v", filterName, len(expectedIDs), expectedIDs, len(actualIDs), actualIDs)) if len(expectedIDs) > 0 { same := true for i := range expectedIDs { if actualIDs[i] != expectedIDs[i] { - c.Logf("%s, %s", actualIDs[i], expectedIDs[i]) + t.Logf("%s, %s", actualIDs[i], expectedIDs[i]) same = false break } } - assert.Equal(c, same, true, fmt.Sprintf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs)) + assert.Equal(t, same, true, fmt.Sprintf("Expected filtered container(s) for %s ancestor filter to be %v, got %v", filterName, expectedIDs, actualIDs)) } } diff --git a/integration-cli/docker_cli_pull_local_test.go b/integration-cli/docker_cli_pull_local_test.go index 239aac0ca2..eb8ea2c9e7 100644 --- a/integration-cli/docker_cli_pull_local_test.go +++ b/integration-cli/docker_cli_pull_local_test.go @@ -26,7 +26,7 @@ import ( // tags for the same image) are not also pulled down. // // Ref: docker/docker#8141 -func (s *DockerRegistrySuite) TestPullImageWithAliases(c *testing.T) { +func (s *DockerRegistrySuite) TestPullImageWithAliases(t *testing.T) { const imgRepo = privateRegistryURL + "/dockercli/busybox" var repos []string @@ -36,44 +36,44 @@ func (s *DockerRegistrySuite) TestPullImageWithAliases(c *testing.T) { // Tag and push the same image multiple times. for _, repo := range repos { - cli.DockerCmd(c, "tag", "busybox", repo) - cli.DockerCmd(c, "push", repo) + cli.DockerCmd(t, "tag", "busybox", repo) + cli.DockerCmd(t, "push", repo) } // Clear local images store. args := append([]string{"rmi"}, repos...) - cli.DockerCmd(c, args...) + cli.DockerCmd(t, args...) // Pull a single tag and verify it doesn't bring down all aliases. - cli.DockerCmd(c, "pull", repos[0]) - cli.DockerCmd(c, "inspect", repos[0]) + cli.DockerCmd(t, "pull", repos[0]) + cli.DockerCmd(t, "inspect", repos[0]) for _, repo := range repos[1:] { _, _, err := dockerCmdWithError("inspect", repo) - assert.ErrorContains(c, err, "", "Image %v shouldn't have been pulled down", repo) + assert.ErrorContains(t, err, "", "Image %v shouldn't have been pulled down", repo) } } // TestConcurrentPullWholeRepo pulls the same repo concurrently. -func (s *DockerRegistrySuite) TestConcurrentPullWholeRepo(c *testing.T) { +func (s *DockerRegistrySuite) TestConcurrentPullWholeRepo(t *testing.T) { const imgRepo = privateRegistryURL + "/dockercli/busybox" var repos []string for _, tag := range []string{"recent", "fresh", "todays"} { repo := fmt.Sprintf("%v:%v", imgRepo, tag) - buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf(` + buildImageSuccessfully(t, repo, build.WithDockerfile(fmt.Sprintf(` FROM busybox ENTRYPOINT ["/bin/echo"] ENV FOO foo ENV BAR bar CMD echo %s `, repo))) - cli.DockerCmd(c, "push", repo) + cli.DockerCmd(t, "push", repo) repos = append(repos, repo) } // Clear local images store. args := append([]string{"rmi"}, repos...) - cli.DockerCmd(c, args...) + cli.DockerCmd(t, args...) // Run multiple re-pulls concurrently numPulls := 3 @@ -90,19 +90,19 @@ func (s *DockerRegistrySuite) TestConcurrentPullWholeRepo(c *testing.T) { // package is not goroutine-safe. for i := 0; i != numPulls; i++ { err := <-results - assert.NilError(c, err, "concurrent pull failed with error: %v", err) + assert.NilError(t, err, "concurrent pull failed with error: %v", err) } // Ensure all tags were pulled successfully for _, repo := range repos { - cli.DockerCmd(c, "inspect", repo) - out := cli.DockerCmd(c, "run", "--rm", repo).Combined() - assert.Equal(c, strings.TrimSpace(out), "/bin/sh -c echo "+repo) + cli.DockerCmd(t, "inspect", repo) + out := cli.DockerCmd(t, "run", "--rm", repo).Combined() + assert.Equal(t, strings.TrimSpace(out), "/bin/sh -c echo "+repo) } } // TestConcurrentFailingPull tries a concurrent pull that doesn't succeed. -func (s *DockerRegistrySuite) TestConcurrentFailingPull(c *testing.T) { +func (s *DockerRegistrySuite) TestConcurrentFailingPull(t *testing.T) { const imgRepo = privateRegistryURL + "/dockercli/busybox" // Run multiple pulls concurrently @@ -120,32 +120,32 @@ func (s *DockerRegistrySuite) TestConcurrentFailingPull(c *testing.T) { // package is not goroutine-safe. for i := 0; i != numPulls; i++ { err := <-results - assert.ErrorContains(c, err, "", "expected pull to fail") + assert.ErrorContains(t, err, "", "expected pull to fail") } } // TestConcurrentPullMultipleTags pulls multiple tags from the same repo // concurrently. -func (s *DockerRegistrySuite) TestConcurrentPullMultipleTags(c *testing.T) { +func (s *DockerRegistrySuite) TestConcurrentPullMultipleTags(t *testing.T) { const imgRepo = privateRegistryURL + "/dockercli/busybox" var repos []string for _, tag := range []string{"recent", "fresh", "todays"} { repo := fmt.Sprintf("%v:%v", imgRepo, tag) - buildImageSuccessfully(c, repo, build.WithDockerfile(fmt.Sprintf(` + buildImageSuccessfully(t, repo, build.WithDockerfile(fmt.Sprintf(` FROM busybox ENTRYPOINT ["/bin/echo"] ENV FOO foo ENV BAR bar CMD echo %s `, repo))) - cli.DockerCmd(c, "push", repo) + cli.DockerCmd(t, "push", repo) repos = append(repos, repo) } // Clear local images store. args := append([]string{"rmi"}, repos...) - cli.DockerCmd(c, args...) + cli.DockerCmd(t, args...) // Re-pull individual tags, in parallel results := make(chan error, len(repos)) @@ -161,24 +161,24 @@ func (s *DockerRegistrySuite) TestConcurrentPullMultipleTags(c *testing.T) { // package is not goroutine-safe. for range repos { err := <-results - assert.NilError(c, err, "concurrent pull failed with error: %v", err) + assert.NilError(t, err, "concurrent pull failed with error: %v", err) } // Ensure all tags were pulled successfully for _, repo := range repos { - cli.DockerCmd(c, "inspect", repo) - out := cli.DockerCmd(c, "run", "--rm", repo).Combined() - assert.Equal(c, strings.TrimSpace(out), "/bin/sh -c echo "+repo) + cli.DockerCmd(t, "inspect", repo) + out := cli.DockerCmd(t, "run", "--rm", repo).Combined() + assert.Equal(t, strings.TrimSpace(out), "/bin/sh -c echo "+repo) } } // TestPullIDStability verifies that pushing an image and pulling it back // preserves the image ID. -func (s *DockerRegistrySuite) TestPullIDStability(c *testing.T) { +func (s *DockerRegistrySuite) TestPullIDStability(t *testing.T) { const derivedImage = privateRegistryURL + "/dockercli/id-stability" const baseImage = "busybox" - buildImageSuccessfully(c, derivedImage, build.WithDockerfile(fmt.Sprintf(` + buildImageSuccessfully(t, derivedImage, build.WithDockerfile(fmt.Sprintf(` FROM %s ENV derived true ENV asdf true @@ -186,54 +186,54 @@ func (s *DockerRegistrySuite) TestPullIDStability(c *testing.T) { CMD echo %s `, baseImage, derivedImage))) - originalID := getIDByName(c, derivedImage) - cli.DockerCmd(c, "push", derivedImage) + originalID := getIDByName(t, derivedImage) + cli.DockerCmd(t, "push", derivedImage) // Pull - out := cli.DockerCmd(c, "pull", derivedImage).Combined() + out := cli.DockerCmd(t, "pull", derivedImage).Combined() if strings.Contains(out, "Pull complete") { - c.Fatalf("repull redownloaded a layer: %s", out) + t.Fatalf("repull redownloaded a layer: %s", out) } - derivedIDAfterPull := getIDByName(c, derivedImage) + derivedIDAfterPull := getIDByName(t, derivedImage) if derivedIDAfterPull != originalID { - c.Fatal("image's ID unexpectedly changed after a repush/repull") + t.Fatal("image's ID unexpectedly changed after a repush/repull") } // Make sure the image runs correctly - out = cli.DockerCmd(c, "run", "--rm", derivedImage).Combined() + out = cli.DockerCmd(t, "run", "--rm", derivedImage).Combined() if strings.TrimSpace(out) != derivedImage { - c.Fatalf("expected %s; got %s", derivedImage, out) + t.Fatalf("expected %s; got %s", derivedImage, out) } // Confirm that repushing and repulling does not change the computed ID - cli.DockerCmd(c, "push", derivedImage) - cli.DockerCmd(c, "rmi", derivedImage) - cli.DockerCmd(c, "pull", derivedImage) + cli.DockerCmd(t, "push", derivedImage) + cli.DockerCmd(t, "rmi", derivedImage) + cli.DockerCmd(t, "pull", derivedImage) - derivedIDAfterPull = getIDByName(c, derivedImage) + derivedIDAfterPull = getIDByName(t, derivedImage) if derivedIDAfterPull != originalID { - c.Fatal("image's ID unexpectedly changed after a repush/repull") + t.Fatal("image's ID unexpectedly changed after a repush/repull") } // Make sure the image still runs - out = cli.DockerCmd(c, "run", "--rm", derivedImage).Combined() + out = cli.DockerCmd(t, "run", "--rm", derivedImage).Combined() if strings.TrimSpace(out) != derivedImage { - c.Fatalf("expected %s; got %s", derivedImage, out) + t.Fatalf("expected %s; got %s", derivedImage, out) } } // #21213 -func (s *DockerRegistrySuite) TestPullNoLayers(c *testing.T) { +func (s *DockerRegistrySuite) TestPullNoLayers(t *testing.T) { const imgRepo = privateRegistryURL + "/dockercli/scratch" - buildImageSuccessfully(c, imgRepo, build.WithDockerfile(` + buildImageSuccessfully(t, imgRepo, build.WithDockerfile(` FROM scratch ENV foo bar`)) - cli.DockerCmd(c, "push", imgRepo) - cli.DockerCmd(c, "rmi", imgRepo) - cli.DockerCmd(c, "pull", imgRepo) + cli.DockerCmd(t, "push", imgRepo) + cli.DockerCmd(t, "rmi", imgRepo) + cli.DockerCmd(t, "pull", imgRepo) } func (s *DockerRegistrySuite) TestPullManifestList(c *testing.T) { diff --git a/integration-cli/docker_cli_pull_test.go b/integration-cli/docker_cli_pull_test.go index fd897188a8..37afaacaf2 100644 --- a/integration-cli/docker_cli_pull_test.go +++ b/integration-cli/docker_cli_pull_test.go @@ -17,12 +17,12 @@ type DockerCLIPullSuite struct { ds *DockerSuite } -func (s *DockerCLIPullSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIPullSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIPullSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIPullSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // TestPullFromCentralRegistry pulls an image from the central registry and verifies that the client diff --git a/integration-cli/docker_cli_push_test.go b/integration-cli/docker_cli_push_test.go index 9d2dc6e60d..81c6d334d1 100644 --- a/integration-cli/docker_cli_push_test.go +++ b/integration-cli/docker_cli_push_test.go @@ -24,12 +24,12 @@ type DockerCLIPushSuite struct { ds *DockerSuite } -func (s *DockerCLIPushSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIPushSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIPushSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIPushSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerRegistrySuite) TestPushBusyboxImage(c *testing.T) { diff --git a/integration-cli/docker_cli_registry_user_agent_test.go b/integration-cli/docker_cli_registry_user_agent_test.go index 9e6ea59a17..8ad3876f9e 100644 --- a/integration-cli/docker_cli_registry_user_agent_test.go +++ b/integration-cli/docker_cli_registry_user_agent_test.go @@ -28,25 +28,25 @@ func unescapeBackslashSemicolonParens(s string) string { return string(ret) } -func regexpCheckUA(c *testing.T, ua string) { +func regexpCheckUA(t *testing.T, ua string) { re := regexp.MustCompile("(?P.+) UpstreamClient(?P.+)") substrArr := re.FindStringSubmatch(ua) - assert.Equal(c, len(substrArr), 3, "Expected 'UpstreamClient()' with upstream client UA") + assert.Equal(t, len(substrArr), 3, "Expected 'UpstreamClient()' with upstream client UA") dockerUA := substrArr[1] upstreamUAEscaped := substrArr[2] // check dockerUA looks correct reDockerUA := regexp.MustCompile("^docker/[0-9A-Za-z+]") bMatchDockerUA := reDockerUA.MatchString(dockerUA) - assert.Assert(c, bMatchDockerUA, "Docker Engine User-Agent malformed") + assert.Assert(t, bMatchDockerUA, "Docker Engine User-Agent malformed") // check upstreamUA looks correct // Expecting something like: Docker-Client/1.11.0-dev (linux) upstreamUA := unescapeBackslashSemicolonParens(upstreamUAEscaped) reUpstreamUA := regexp.MustCompile(`^\(Docker-Client/[0-9A-Za-z+]`) bMatchUpstreamUA := reUpstreamUA.MatchString(upstreamUA) - assert.Assert(c, bMatchUpstreamUA, "(Upstream) Docker Client User-Agent malformed") + assert.Assert(t, bMatchUpstreamUA, "(Upstream) Docker Client User-Agent malformed") } // registerUserAgentHandler registers a handler for the `/v2/*` endpoint. diff --git a/integration-cli/docker_cli_restart_test.go b/integration-cli/docker_cli_restart_test.go index 7214188104..bf5c5fbae0 100644 --- a/integration-cli/docker_cli_restart_test.go +++ b/integration-cli/docker_cli_restart_test.go @@ -20,12 +20,12 @@ type DockerCLIRestartSuite struct { ds *DockerSuite } -func (s *DockerCLIRestartSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIRestartSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIRestartSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIRestartSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIRestartSuite) TestRestartStoppedContainer(c *testing.T) { @@ -50,8 +50,8 @@ func (s *DockerCLIRestartSuite) TestRestartRunningContainer(c *testing.T) { cID = strings.TrimSpace(cID) cli.WaitRun(c, cID) - getLogs := func(c *testing.T) (interface{}, string) { - out := cli.DockerCmd(c, "logs", cID).Combined() + getLogs := func(t *testing.T) (interface{}, string) { + out := cli.DockerCmd(t, "logs", cID).Combined() return out, "" } diff --git a/integration-cli/docker_cli_rmi_test.go b/integration-cli/docker_cli_rmi_test.go index e48d1dabbf..49747af06d 100644 --- a/integration-cli/docker_cli_rmi_test.go +++ b/integration-cli/docker_cli_rmi_test.go @@ -20,12 +20,12 @@ type DockerCLIRmiSuite struct { ds *DockerSuite } -func (s *DockerCLIRmiSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIRmiSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIRmiSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIRmiSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIRmiSuite) TestRmiWithContainerFails(c *testing.T) { diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 7e0343e7e9..524b1c8f51 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -46,12 +46,12 @@ type DockerCLIRunSuite struct { ds *DockerSuite } -func (s *DockerCLIRunSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIRunSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIRunSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIRunSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // "test123" should be printed by docker run @@ -1812,24 +1812,24 @@ func (s *DockerCLIRunSuite) TestRunWriteSpecialFilesAndNotCommit(c *testing.T) { testRunWriteSpecialFilesAndNotCommit(c, "writeresolv", "/etc/resolv.conf") } -func testRunWriteSpecialFilesAndNotCommit(c *testing.T, name, path string) { +func testRunWriteSpecialFilesAndNotCommit(t *testing.T, name, path string) { command := fmt.Sprintf("echo test2267 >> %s && cat %s", path, path) - out := cli.DockerCmd(c, "run", "--name", name, "busybox", "sh", "-c", command).Combined() + out := cli.DockerCmd(t, "run", "--name", name, "busybox", "sh", "-c", command).Combined() if !strings.Contains(out, "test2267") { - c.Fatalf("%s should contain 'test2267'", path) + t.Fatalf("%s should contain 'test2267'", path) } - out = cli.DockerCmd(c, "diff", name).Combined() - if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, c) { - c.Fatal("diff should be empty") + out = cli.DockerCmd(t, "diff", name).Combined() + if len(strings.Trim(out, "\r\n")) != 0 && !eqToBaseDiff(out, t) { + t.Fatal("diff should be empty") } } -func eqToBaseDiff(out string, c *testing.T) bool { +func eqToBaseDiff(out string, t *testing.T) bool { name := "eqToBaseDiff" + testutil.GenerateRandomAlphaOnlyString(32) - cli.DockerCmd(c, "run", "--name", name, "busybox", "echo", "hello") - cID := getIDByName(c, name) - baseDiff := cli.DockerCmd(c, "diff", cID).Combined() + cli.DockerCmd(t, "run", "--name", name, "busybox", "echo", "hello") + cID := getIDByName(t, name) + baseDiff := cli.DockerCmd(t, "diff", cID).Combined() baseArr := strings.Split(baseDiff, "\n") sort.Strings(baseArr) outArr := strings.Split(out, "\n") @@ -2661,14 +2661,14 @@ func (s *DockerCLIRunSuite) TestPermissionsPtsReadonlyRootfs(c *testing.T) { } } -func testReadOnlyFile(c *testing.T, testPriv bool, filenames ...string) { +func testReadOnlyFile(t *testing.T, testPriv bool, filenames ...string) { touch := "touch " + strings.Join(filenames, " ") out, _, err := dockerCmdWithError("run", "--read-only", "--rm", "busybox", "sh", "-c", touch) - assert.ErrorContains(c, err, "") + assert.ErrorContains(t, err, "") for _, f := range filenames { expected := "touch: " + f + ": Read-only file system" - assert.Assert(c, is.Contains(out, expected)) + assert.Assert(t, is.Contains(out, expected)) } if !testPriv { @@ -2676,11 +2676,11 @@ func testReadOnlyFile(c *testing.T, testPriv bool, filenames ...string) { } out, _, err = dockerCmdWithError("run", "--read-only", "--privileged", "--rm", "busybox", "sh", "-c", touch) - assert.ErrorContains(c, err, "") + assert.ErrorContains(t, err, "") for _, f := range filenames { expected := "touch: " + f + ": Read-only file system" - assert.Assert(c, is.Contains(out, expected)) + assert.Assert(t, is.Contains(out, expected)) } } @@ -3197,16 +3197,16 @@ func (s *DockerCLIRunSuite) TestRunContainerWithCgroupParent(c *testing.T) { testRunContainerWithCgroupParent(c, "/cgroup-parent/test", "cgroup-test-absolute") } -func testRunContainerWithCgroupParent(c *testing.T, cgroupParent, name string) { +func testRunContainerWithCgroupParent(t *testing.T, cgroupParent, name string) { out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup") if err != nil { - c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", out, err) + t.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", out, err) } cgroupPaths := ParseCgroupPaths(out) if len(cgroupPaths) == 0 { - c.Fatalf("unexpected output - %q", out) + t.Fatalf("unexpected output - %q", out) } - id := getIDByName(c, name) + id := getIDByName(t, name) expectedCgroup := path.Join(cgroupParent, id) found := false for _, p := range cgroupPaths { @@ -3216,7 +3216,7 @@ func testRunContainerWithCgroupParent(c *testing.T, cgroupParent, name string) { } } if !found { - c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) + t.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) } } @@ -3231,23 +3231,23 @@ func (s *DockerCLIRunSuite) TestRunInvalidCgroupParent(c *testing.T) { testRunInvalidCgroupParent(c, "/../../../../../../../../SHOULD_NOT_EXIST", "/SHOULD_NOT_EXIST", "cgroup-absolute-invalid-test") } -func testRunInvalidCgroupParent(c *testing.T, cgroupParent, cleanCgroupParent, name string) { +func testRunInvalidCgroupParent(t *testing.T, cgroupParent, cleanCgroupParent, name string) { out, _, err := dockerCmdWithError("run", "--cgroup-parent", cgroupParent, "--name", name, "busybox", "cat", "/proc/self/cgroup") if err != nil { // XXX: This may include a daemon crash. - c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", out, err) + t.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", out, err) } // We expect "/SHOULD_NOT_EXIST" to not exist. If not, we have a security issue. if _, err := os.Stat("/SHOULD_NOT_EXIST"); err == nil || !os.IsNotExist(err) { - c.Fatalf("SECURITY: --cgroup-parent with ../../ relative paths cause files to be created in the host (this is bad) !!") + t.Fatalf("SECURITY: --cgroup-parent with ../../ relative paths cause files to be created in the host (this is bad) !!") } cgroupPaths := ParseCgroupPaths(out) if len(cgroupPaths) == 0 { - c.Fatalf("unexpected output - %q", out) + t.Fatalf("unexpected output - %q", out) } - id := getIDByName(c, name) + id := getIDByName(t, name) expectedCgroup := path.Join(cleanCgroupParent, id) found := false for _, p := range cgroupPaths { @@ -3257,7 +3257,7 @@ func testRunInvalidCgroupParent(c *testing.T, cgroupParent, cleanCgroupParent, n } } if !found { - c.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) + t.Fatalf("unexpected cgroup paths. Expected at least one cgroup path to have suffix %q. Cgroup Paths: %v", expectedCgroup, cgroupPaths) } } diff --git a/integration-cli/docker_cli_save_load_test.go b/integration-cli/docker_cli_save_load_test.go index 5ed281fc11..c0341be490 100644 --- a/integration-cli/docker_cli_save_load_test.go +++ b/integration-cli/docker_cli_save_load_test.go @@ -24,12 +24,12 @@ type DockerCLISaveLoadSuite struct { ds *DockerSuite } -func (s *DockerCLISaveLoadSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLISaveLoadSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLISaveLoadSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLISaveLoadSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // save a repo using gz compression and try to load it using stdout diff --git a/integration-cli/docker_cli_search_test.go b/integration-cli/docker_cli_search_test.go index 2a0691bbf4..36fb32d5a7 100644 --- a/integration-cli/docker_cli_search_test.go +++ b/integration-cli/docker_cli_search_test.go @@ -15,12 +15,12 @@ type DockerCLISearchSuite struct { ds *DockerSuite } -func (s *DockerCLISearchSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLISearchSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLISearchSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLISearchSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // search for repos named "registry" on the central registry diff --git a/integration-cli/docker_cli_service_create_test.go b/integration-cli/docker_cli_service_create_test.go index 2c12796127..927127857a 100644 --- a/integration-cli/docker_cli_service_create_test.go +++ b/integration-cli/docker_cli_service_create_test.go @@ -27,15 +27,15 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, id) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, id) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { - task = d.GetTask(ctx, c, task.ID) + task = d.GetTask(ctx, t, task.ID) } return task.NodeID != "" && task.Status.ContainerStatus != nil, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -143,15 +143,15 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *testi assert.Equal(c, len(refs), len(testPaths)) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, serviceName) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, serviceName) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { - task = d.GetTask(ctx, c, task.ID) + task = d.GetTask(ctx, t, task.ID) } return task.NodeID != "" && task.Status.ContainerStatus != nil, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -194,15 +194,15 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *testing assert.Equal(c, len(refs), 2) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, serviceName) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, serviceName) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { - task = d.GetTask(ctx, c, task.ID) + task = d.GetTask(ctx, t, task.ID) } return task.NodeID != "" && task.Status.ContainerStatus != nil, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -293,15 +293,15 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *testi assert.Equal(c, len(refs), len(testPaths)) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, serviceName) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, serviceName) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { - task = d.GetTask(ctx, c, task.ID) + task = d.GetTask(ctx, t, task.ID) } return task.NodeID != "" && task.Status.ContainerStatus != nil, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -344,15 +344,15 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *testing assert.Equal(c, len(refs), 2) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, serviceName) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, serviceName) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { - task = d.GetTask(ctx, c, task.ID) + task = d.GetTask(ctx, t, task.ID) } return task.NodeID != "" && task.Status.ContainerStatus != nil, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -377,15 +377,15 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, id) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, id) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { - task = d.GetTask(ctx, c, task.ID) + task = d.GetTask(ctx, t, task.ID) } return task.NodeID != "" && task.Status.ContainerStatus != nil, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -434,15 +434,15 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, id) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, id) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { - task = d.GetTask(ctx, c, task.ID) + task = d.GetTask(ctx, t, task.ID) } return task.NodeID != "" && task.Status.ContainerStatus != nil, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) diff --git a/integration-cli/docker_cli_service_health_test.go b/integration-cli/docker_cli_service_health_test.go index dfb6ed9397..6b5025de4a 100644 --- a/integration-cli/docker_cli_service_health_test.go +++ b/integration-cli/docker_cli_service_health_test.go @@ -42,23 +42,23 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, id) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, id) return tasks, "" }, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] // wait for task to start - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - task = d.GetTask(ctx, c, task.ID) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + task = d.GetTask(ctx, t, task.ID) return task.Status.State, "" }, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout)) containerID := task.Status.ContainerStatus.ContainerID // wait for container to be healthy - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID) return strings.TrimSpace(out), "" }, checker.Equals("healthy")), poll.WithTimeout(defaultReconciliationTimeout)) @@ -66,14 +66,14 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) { // make it fail d.Cmd("exec", containerID, "rm", "/status") // wait for container to be unhealthy - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID) return strings.TrimSpace(out), "" }, checker.Equals("unhealthy")), poll.WithTimeout(defaultReconciliationTimeout)) // Task should be terminated - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - task = d.GetTask(ctx, c, task.ID) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + task = d.GetTask(ctx, t, task.ID) return task.Status.State, "" }, checker.Equals(swarm.TaskStateFailed)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -105,23 +105,23 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - tasks = d.GetServiceTasks(ctx, c, id) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + tasks = d.GetServiceTasks(ctx, t, id) return tasks, "" }, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] // wait for task to start - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - task = d.GetTask(ctx, c, task.ID) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + task = d.GetTask(ctx, t, task.ID) return task.Status.State, "" }, checker.Equals(swarm.TaskStateStarting)), poll.WithTimeout(defaultReconciliationTimeout)) containerID := task.Status.ContainerStatus.ContainerID // wait for health check to work - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { out, _ := d.Cmd("inspect", "--format={{.State.Health.FailingStreak}}", containerID) failingStreak, _ := strconv.Atoi(strings.TrimSpace(out)) return failingStreak, "" @@ -135,8 +135,8 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) { d.Cmd("exec", containerID, "touch", "/status") // Task should be at running status - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { - task = d.GetTask(ctx, c, task.ID) + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + task = d.GetTask(ctx, t, task.ID) return task.Status.State, "" }, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout)) } diff --git a/integration-cli/docker_cli_service_logs_test.go b/integration-cli/docker_cli_service_logs_test.go index 71cc0a1802..3cc6ebd20f 100644 --- a/integration-cli/docker_cli_service_logs_test.go +++ b/integration-cli/docker_cli_service_logs_test.go @@ -57,9 +57,9 @@ func (s *DockerSwarmSuite) TestServiceLogs(c *testing.T) { // verify that a minimum number of expected container log messages have been // output. func countLogLines(d *daemon.Daemon, name string) func(*testing.T) (interface{}, string) { - return func(c *testing.T) (interface{}, string) { + return func(t *testing.T) (interface{}, string) { result := icmd.RunCmd(d.Command("service", "logs", "-t", "--raw", name)) - result.Assert(c, icmd.Expected{}) + result.Assert(t, icmd.Expected{}) // if this returns an emptystring, trying to split it later will return // an array containing emptystring. a valid log line will NEVER be // emptystring because we ask for the timestamp. diff --git a/integration-cli/docker_cli_sni_test.go b/integration-cli/docker_cli_sni_test.go index e72b83d961..e588f4a719 100644 --- a/integration-cli/docker_cli_sni_test.go +++ b/integration-cli/docker_cli_sni_test.go @@ -19,12 +19,12 @@ type DockerCLISNISuite struct { ds *DockerSuite } -func (s *DockerCLISNISuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLISNISuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLISNISuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLISNISuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLISNISuite) TestClientSetsTLSServerName(c *testing.T) { diff --git a/integration-cli/docker_cli_start_test.go b/integration-cli/docker_cli_start_test.go index 319efde9a4..e28539daaa 100644 --- a/integration-cli/docker_cli_start_test.go +++ b/integration-cli/docker_cli_start_test.go @@ -17,12 +17,12 @@ type DockerCLIStartSuite struct { ds *DockerSuite } -func (s *DockerCLIStartSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIStartSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIStartSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIStartSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } // Regression test for https://github.com/docker/docker/issues/7843 diff --git a/integration-cli/docker_cli_stats_test.go b/integration-cli/docker_cli_stats_test.go index e6994834e4..5db8d0448e 100644 --- a/integration-cli/docker_cli_stats_test.go +++ b/integration-cli/docker_cli_stats_test.go @@ -18,12 +18,12 @@ type DockerCLIStatsSuite struct { ds *DockerSuite } -func (s *DockerCLIStatsSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIStatsSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIStatsSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIStatsSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIStatsSuite) TestStatsNoStream(c *testing.T) { diff --git a/integration-cli/docker_cli_swarm_test.go b/integration-cli/docker_cli_swarm_test.go index 07363c2d3c..ec360786aa 100644 --- a/integration-cli/docker_cli_swarm_test.go +++ b/integration-cli/docker_cli_swarm_test.go @@ -1051,14 +1051,14 @@ func (s *DockerSwarmSuite) TestDNSConfigUpdate(c *testing.T) { assert.Equal(c, strings.TrimSpace(out), "{[1.2.3.4] [example.com] [timeout:3]}") } -func getNodeStatus(c *testing.T, d *daemon.Daemon) swarm.LocalNodeState { - ctx := testutil.GetContext(c) - info := d.SwarmInfo(ctx, c) +func getNodeStatus(t *testing.T, d *daemon.Daemon) swarm.LocalNodeState { + ctx := testutil.GetContext(t) + info := d.SwarmInfo(ctx, t) return info.LocalNodeState } func checkKeyIsEncrypted(d *daemon.Daemon) func(*testing.T) (interface{}, string) { - return func(c *testing.T) (interface{}, string) { + return func(t *testing.T) (interface{}, string) { keyBytes, err := os.ReadFile(filepath.Join(d.Folder, "root", "swarm", "certificates", "swarm-node.key")) if err != nil { return fmt.Errorf("error reading key: %v", err), "" @@ -1073,20 +1073,20 @@ func checkKeyIsEncrypted(d *daemon.Daemon) func(*testing.T) (interface{}, string } } -func checkSwarmLockedToUnlocked(ctx context.Context, c *testing.T, d *daemon.Daemon) { +func checkSwarmLockedToUnlocked(ctx context.Context, t *testing.T, d *daemon.Daemon) { // Wait for the PEM file to become unencrypted - poll.WaitOn(c, pollCheck(c, checkKeyIsEncrypted(d), checker.Equals(false)), poll.WithTimeout(defaultReconciliationTimeout)) + poll.WaitOn(t, pollCheck(t, checkKeyIsEncrypted(d), checker.Equals(false)), poll.WithTimeout(defaultReconciliationTimeout)) - d.RestartNode(c) - poll.WaitOn(c, pollCheck(c, d.CheckLocalNodeState(ctx), checker.Equals(swarm.LocalNodeStateActive)), poll.WithTimeout(time.Second)) + d.RestartNode(t) + poll.WaitOn(t, pollCheck(t, d.CheckLocalNodeState(ctx), checker.Equals(swarm.LocalNodeStateActive)), poll.WithTimeout(time.Second)) } -func checkSwarmUnlockedToLocked(ctx context.Context, c *testing.T, d *daemon.Daemon) { +func checkSwarmUnlockedToLocked(ctx context.Context, t *testing.T, d *daemon.Daemon) { // Wait for the PEM file to become encrypted - poll.WaitOn(c, pollCheck(c, checkKeyIsEncrypted(d), checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) + poll.WaitOn(t, pollCheck(t, checkKeyIsEncrypted(d), checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) - d.RestartNode(c) - poll.WaitOn(c, pollCheck(c, d.CheckLocalNodeState(ctx), checker.Equals(swarm.LocalNodeStateLocked)), poll.WithTimeout(time.Second)) + d.RestartNode(t) + poll.WaitOn(t, pollCheck(t, d.CheckLocalNodeState(ctx), checker.Equals(swarm.LocalNodeStateLocked)), poll.WithTimeout(time.Second)) } func (s *DockerSwarmSuite) TestUnlockEngineAndUnlockedSwarm(c *testing.T) { @@ -1293,7 +1293,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) { // (because we never want a manager TLS key to be on disk unencrypted if the cluster // is set to autolock) poll.WaitOn(c, pollCheck(c, d3.CheckControlAvailable(ctx), checker.False()), poll.WithTimeout(defaultReconciliationTimeout)) - poll.WaitOn(c, pollCheck(c, func(c *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { certBytes, err := os.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt")) if err != nil { return "", fmt.Sprintf("error: %v", err) @@ -1801,21 +1801,21 @@ func (s *DockerSwarmSuite) TestSwarmJoinLeave(c *testing.T) { const defaultRetryCount = 10 -func waitForEvent(c *testing.T, d *daemon.Daemon, since string, filter string, event string, retry int) string { +func waitForEvent(t *testing.T, d *daemon.Daemon, since string, filter string, event string, retry int) string { if retry < 1 { - c.Fatalf("retry count %d is invalid. It should be no less than 1", retry) + t.Fatalf("retry count %d is invalid. It should be no less than 1", retry) return "" } var out string for i := 0; i < retry; i++ { - until := daemonUnixTime(c) + until := daemonUnixTime(t) var err error if len(filter) > 0 { out, err = d.Cmd("events", "--since", since, "--until", until, filter) } else { out, err = d.Cmd("events", "--since", since, "--until", until) } - assert.NilError(c, err, out) + assert.NilError(t, err, out) if strings.Contains(out, event) { return strings.TrimSpace(out) } @@ -1824,7 +1824,7 @@ func waitForEvent(c *testing.T, d *daemon.Daemon, since string, filter string, e time.Sleep(200 * time.Millisecond) } } - c.Fatalf("docker events output '%s' doesn't contain event '%s'", out, event) + t.Fatalf("docker events output '%s' doesn't contain event '%s'", out, event) return "" } @@ -2023,14 +2023,14 @@ func (s *DockerSwarmSuite) TestSwarmClusterEventsConfig(c *testing.T) { waitForEvent(c, d, t1, "-f type=config", "config remove "+id, defaultRetryCount) } -func getUnlockKey(d *daemon.Daemon, c *testing.T, autolockOutput string) string { +func getUnlockKey(d *daemon.Daemon, t *testing.T, autolockOutput string) string { unlockKey, err := d.Cmd("swarm", "unlock-key", "-q") - assert.Assert(c, err == nil, unlockKey) + assert.Assert(t, err == nil, 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 - assert.Assert(c, strings.Contains(autolockOutput, "docker swarm unlock"), autolockOutput) - assert.Assert(c, strings.Contains(autolockOutput, unlockKey), autolockOutput) + assert.Assert(t, strings.Contains(autolockOutput, "docker swarm unlock"), autolockOutput) + assert.Assert(t, strings.Contains(autolockOutput, unlockKey), autolockOutput) return unlockKey } diff --git a/integration-cli/docker_cli_top_test.go b/integration-cli/docker_cli_top_test.go index fc24381a33..bd9b5ddaca 100644 --- a/integration-cli/docker_cli_top_test.go +++ b/integration-cli/docker_cli_top_test.go @@ -14,12 +14,12 @@ type DockerCLITopSuite struct { ds *DockerSuite } -func (s *DockerCLITopSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLITopSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLITopSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLITopSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLITopSuite) TestTopMultipleArgs(c *testing.T) { diff --git a/integration-cli/docker_cli_update_unix_test.go b/integration-cli/docker_cli_update_unix_test.go index 7bdb1f8b67..06e019784d 100644 --- a/integration-cli/docker_cli_update_unix_test.go +++ b/integration-cli/docker_cli_update_unix_test.go @@ -22,12 +22,12 @@ import ( "gotest.tools/v3/skip" ) -func (s *DockerCLIUpdateSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIUpdateSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIUpdateSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIUpdateSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIUpdateSuite) TestUpdateRunningContainer(c *testing.T) { diff --git a/integration-cli/docker_cli_userns_test.go b/integration-cli/docker_cli_userns_test.go index 327eb79bd1..33876406af 100644 --- a/integration-cli/docker_cli_userns_test.go +++ b/integration-cli/docker_cli_userns_test.go @@ -95,13 +95,13 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) { } // findUser finds the uid or name of the user of the first process that runs in a container -func (s *DockerDaemonSuite) findUser(c *testing.T, container string) string { +func (s *DockerDaemonSuite) findUser(t *testing.T, container string) string { out, err := s.d.Cmd("top", container) - assert.Assert(c, err == nil, "Output: %s", out) + assert.Assert(t, err == nil, "Output: %s", out) rows := strings.Split(out, "\n") if len(rows) < 2 { // No process rows founds - c.FailNow() + t.FailNow() } return strings.Fields(rows[1])[0] } diff --git a/integration-cli/docker_cli_volume_test.go b/integration-cli/docker_cli_volume_test.go index 23ea0f06ee..487af4abfb 100644 --- a/integration-cli/docker_cli_volume_test.go +++ b/integration-cli/docker_cli_volume_test.go @@ -25,12 +25,12 @@ type DockerCLIVolumeSuite struct { ds *DockerSuite } -func (s *DockerCLIVolumeSuite) TearDownTest(ctx context.Context, c *testing.T) { - s.ds.TearDownTest(ctx, c) +func (s *DockerCLIVolumeSuite) TearDownTest(ctx context.Context, t *testing.T) { + s.ds.TearDownTest(ctx, t) } -func (s *DockerCLIVolumeSuite) OnTimeout(c *testing.T) { - s.ds.OnTimeout(c) +func (s *DockerCLIVolumeSuite) OnTimeout(t *testing.T) { + s.ds.OnTimeout(t) } func (s *DockerCLIVolumeSuite) TestVolumeCLICreate(c *testing.T) { @@ -119,7 +119,7 @@ func (s *DockerCLIVolumeSuite) TestVolumeLsFormatDefaultFormat(c *testing.T) { assertVolumesInList(c, out, []string{"aaa default", "soo default", "test default"}) } -func assertVolumesInList(c *testing.T, out string, expected []string) { +func assertVolumesInList(t *testing.T, out string, expected []string) { lines := strings.Split(strings.TrimSpace(out), "\n") for _, expect := range expected { found := false @@ -129,7 +129,7 @@ func assertVolumesInList(c *testing.T, out string, expected []string) { break } } - assert.Assert(c, found, "Expected volume not found: %v, got: %v", expect, lines) + assert.Assert(t, found, "Expected volume not found: %v, got: %v", expect, lines) } } diff --git a/integration-cli/docker_hub_pull_suite_test.go b/integration-cli/docker_hub_pull_suite_test.go index dc043d85a7..daab17421d 100644 --- a/integration-cli/docker_hub_pull_suite_test.go +++ b/integration-cli/docker_hub_pull_suite_test.go @@ -31,38 +31,38 @@ func newDockerHubPullSuite() *DockerHubPullSuite { } // SetUpSuite starts the suite daemon. -func (s *DockerHubPullSuite) SetUpSuite(ctx context.Context, c *testing.T) { - testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) - s.d = daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) - s.d.Start(c) +func (s *DockerHubPullSuite) SetUpSuite(ctx context.Context, t *testing.T) { + testRequires(t, DaemonIsLinux, testEnv.IsLocalDaemon) + s.d = daemon.New(t, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution)) + s.d.Start(t) } // TearDownSuite stops the suite daemon. -func (s *DockerHubPullSuite) TearDownSuite(ctx context.Context, c *testing.T) { +func (s *DockerHubPullSuite) TearDownSuite(ctx context.Context, t *testing.T) { if s.d != nil { - s.d.Stop(c) + s.d.Stop(t) } } // SetUpTest declares that all tests of this suite require network. -func (s *DockerHubPullSuite) SetUpTest(ctx context.Context, c *testing.T) { - testRequires(c, Network) +func (s *DockerHubPullSuite) SetUpTest(ctx context.Context, t *testing.T) { + testRequires(t, Network) } // TearDownTest removes all images from the suite daemon. -func (s *DockerHubPullSuite) TearDownTest(ctx context.Context, c *testing.T) { - out := s.Cmd(c, "images", "-aq") +func (s *DockerHubPullSuite) TearDownTest(ctx context.Context, t *testing.T) { + out := s.Cmd(t, "images", "-aq") images := strings.Split(out, "\n") images = append([]string{"rmi", "-f"}, images...) s.d.Cmd(images...) - s.ds.TearDownTest(ctx, c) + s.ds.TearDownTest(ctx, t) } // Cmd executes a command against the suite daemon and returns the combined // output. The function fails the test when the command returns an error. -func (s *DockerHubPullSuite) Cmd(c *testing.T, name string, arg ...string) string { +func (s *DockerHubPullSuite) Cmd(t *testing.T, name string, arg ...string) string { out, err := s.CmdWithError(name, arg...) - assert.Assert(c, err == nil, "%q failed with errors: %s, %v", strings.Join(arg, " "), out, err) + assert.Assert(t, err == nil, "%q failed with errors: %s, %v", strings.Join(arg, " "), out, err) return out } diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index b1b15b9a4e..d1aba99c9e 100644 --- a/integration-cli/docker_utils_test.go +++ b/integration-cli/docker_utils_test.go @@ -47,18 +47,18 @@ func dockerCmdWithResult(args ...string) *icmd.Result { return cli.Docker(cli.Args(args...)) } -func findContainerIP(c *testing.T, id string, network string) string { - c.Helper() - out := cli.DockerCmd(c, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id).Stdout() +func findContainerIP(t *testing.T, id string, network string) string { + t.Helper() + out := cli.DockerCmd(t, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id).Stdout() return strings.Trim(out, " \r\n'") } -func getContainerCount(c *testing.T) int { - c.Helper() +func getContainerCount(t *testing.T) int { + t.Helper() const containers = "Containers:" result := icmd.RunCommand(dockerBinary, "info") - result.Assert(c, icmd.Success) + result.Assert(t, icmd.Success) lines := strings.Split(result.Combined(), "\n") for _, line := range lines { @@ -67,18 +67,18 @@ func getContainerCount(c *testing.T) int { output = strings.TrimPrefix(output, containers) output = strings.Trim(output, " ") containerCount, err := strconv.Atoi(output) - assert.NilError(c, err) + assert.NilError(t, err) return containerCount } } return 0 } -func inspectFieldAndUnmarshall(c *testing.T, name, field string, output interface{}) { - c.Helper() - str := inspectFieldJSON(c, name, field) +func inspectFieldAndUnmarshall(t *testing.T, name, field string, output interface{}) { + t.Helper() + str := inspectFieldJSON(t, name, field) err := json.Unmarshal([]byte(str), output) - assert.Assert(c, err == nil, "failed to unmarshal: %v", err) + assert.Assert(t, err == nil, "failed to unmarshal: %v", err) } // Deprecated: use cli.Docker @@ -97,26 +97,26 @@ func inspectFieldWithError(name, field string) (string, error) { } // Deprecated: use cli.Docker -func inspectField(c *testing.T, name, field string) string { - c.Helper() +func inspectField(t *testing.T, name, field string) string { + t.Helper() out, err := inspectFilter(name, "."+field) - assert.NilError(c, err) + assert.NilError(t, err) return out } // Deprecated: use cli.Docker -func inspectFieldJSON(c *testing.T, name, field string) string { - c.Helper() +func inspectFieldJSON(t *testing.T, name, field string) string { + t.Helper() out, err := inspectFilter(name, "json ."+field) - assert.NilError(c, err) + assert.NilError(t, err) return out } // Deprecated: use cli.Docker -func inspectFieldMap(c *testing.T, name, path, field string) string { - c.Helper() +func inspectFieldMap(t *testing.T, name, path, field string) string { + t.Helper() out, err := inspectFilter(name, fmt.Sprintf("index .%s %q", path, field)) - assert.NilError(c, err) + assert.NilError(t, err) return out } @@ -152,17 +152,17 @@ func inspectMountPoint(name, destination string) (container.MountPoint, error) { return container.MountPoint{}, errMountNotFound } -func getIDByName(c *testing.T, name string) string { - c.Helper() +func getIDByName(t *testing.T, name string) string { + t.Helper() id, err := inspectFieldWithError(name, "Id") - assert.NilError(c, err) + assert.NilError(t, err) return id } // Deprecated: use cli.Docker -func buildImageSuccessfully(c *testing.T, name string, cmdOperators ...cli.CmdOperator) { - c.Helper() - buildImage(name, cmdOperators...).Assert(c, icmd.Success) +func buildImageSuccessfully(t *testing.T, name string, cmdOperators ...cli.CmdOperator) { + t.Helper() + buildImage(name, cmdOperators...).Assert(t, icmd.Success) } // Deprecated: use cli.Docker @@ -174,24 +174,24 @@ func buildImage(name string, cmdOperators ...cli.CmdOperator) *icmd.Result { // as well as any missing directories. // The file is truncated if it already exists. // Fail the test when error occurs. -func writeFile(dst, content string, c *testing.T) { - c.Helper() +func writeFile(dst, content string, t *testing.T) { + t.Helper() // Create subdirectories if necessary - assert.NilError(c, os.MkdirAll(path.Dir(dst), 0o700)) + assert.NilError(t, 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) + assert.NilError(t, err) defer f.Close() // Write content (truncate if it exists) _, err = io.Copy(f, strings.NewReader(content)) - assert.NilError(c, err) + assert.NilError(t, err) } // Return the contents of file at path `src`. // Fail the test when error occurs. -func readFile(src string, c *testing.T) (content string) { - c.Helper() +func readFile(src string, t *testing.T) (content string) { + t.Helper() data, err := os.ReadFile(src) - assert.NilError(c, err) + assert.NilError(t, err) return string(data) } @@ -201,56 +201,56 @@ func containerStorageFile(containerID, basename string) string { } // docker commands that use this function must be run with the '-d' switch. -func runCommandAndReadContainerFile(c *testing.T, filename string, command string, args ...string) []byte { - c.Helper() +func runCommandAndReadContainerFile(t *testing.T, filename string, command string, args ...string) []byte { + t.Helper() result := icmd.RunCommand(command, args...) - result.Assert(c, icmd.Success) + result.Assert(t, icmd.Success) contID := strings.TrimSpace(result.Combined()) - cli.WaitRun(c, contID) - return readContainerFile(c, contID, filename) + cli.WaitRun(t, contID) + return readContainerFile(t, contID, filename) } -func readContainerFile(c *testing.T, containerID, filename string) []byte { - c.Helper() +func readContainerFile(t *testing.T, containerID, filename string) []byte { + t.Helper() f, err := os.Open(containerStorageFile(containerID, filename)) - assert.NilError(c, err) + assert.NilError(t, err) defer f.Close() content, err := io.ReadAll(f) - assert.NilError(c, err) + assert.NilError(t, err) return content } -func readContainerFileWithExec(c *testing.T, containerID, filename string) []byte { - c.Helper() +func readContainerFileWithExec(t *testing.T, containerID, filename string) []byte { + t.Helper() result := icmd.RunCommand(dockerBinary, "exec", containerID, "cat", filename) - result.Assert(c, icmd.Success) + result.Assert(t, icmd.Success) return []byte(result.Combined()) } // daemonTime provides the current time on the daemon host -func daemonTime(c *testing.T) time.Time { - c.Helper() +func daemonTime(t *testing.T) time.Time { + t.Helper() if testEnv.IsLocalDaemon() { return time.Now() } apiClient, err := client.NewClientWithOpts(client.FromEnv) - assert.NilError(c, err) + assert.NilError(t, err) defer apiClient.Close() - info, err := apiClient.Info(testutil.GetContext(c)) - assert.NilError(c, err) + info, err := apiClient.Info(testutil.GetContext(t)) + assert.NilError(t, err) dt, err := time.Parse(time.RFC3339Nano, info.SystemTime) - assert.Assert(c, err == nil, "invalid time format in GET /info response") + assert.Assert(t, err == nil, "invalid time format in GET /info response") return dt } // daemonUnixTime returns the current time on the daemon host with nanoseconds precision. // It return the time formatted how the client sends timestamps to the server. -func daemonUnixTime(c *testing.T) string { - c.Helper() - return parseEventTime(daemonTime(c)) +func daemonUnixTime(t *testing.T) string { + t.Helper() + return parseEventTime(daemonTime(t)) } func parseEventTime(t time.Time) string { @@ -284,15 +284,15 @@ func appendBaseEnv(isTLS bool, env ...string) []string { return env } -func createTmpFile(c *testing.T, content string) string { - c.Helper() +func createTmpFile(t *testing.T, content string) string { + t.Helper() f, err := os.CreateTemp("", "testfile") - assert.NilError(c, err) + assert.NilError(t, err) filename := f.Name() err = os.WriteFile(filename, []byte(content), 0o644) - assert.NilError(c, err) + assert.NilError(t, err) return filename } @@ -305,32 +305,32 @@ func waitInspect(name, expr, expected string, timeout time.Duration) error { return daemon.WaitInspectWithArgs(dockerBinary, name, expr, expected, timeout) } -func getInspectBody(c *testing.T, version, id string) []byte { - c.Helper() +func getInspectBody(t *testing.T, version, id string) []byte { + t.Helper() apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(version)) - assert.NilError(c, err) + assert.NilError(t, err) defer apiClient.Close() - _, body, err := apiClient.ContainerInspectWithRaw(testutil.GetContext(c), id, false) - assert.NilError(c, err) + _, body, err := apiClient.ContainerInspectWithRaw(testutil.GetContext(t), id, false) + assert.NilError(t, err) return body } // Run a long running idle task in a background container using the // system-specific default image and command. -func runSleepingContainer(c *testing.T, extraArgs ...string) string { - c.Helper() - return runSleepingContainerInImage(c, "busybox", extraArgs...) +func runSleepingContainer(t *testing.T, extraArgs ...string) string { + t.Helper() + return runSleepingContainerInImage(t, "busybox", extraArgs...) } // Run a long running idle task in a background container using the specified // image and the system-specific command. -func runSleepingContainerInImage(c *testing.T, image string, extraArgs ...string) string { - c.Helper() +func runSleepingContainerInImage(t *testing.T, image string, extraArgs ...string) string { + t.Helper() args := []string{"run", "-d"} args = append(args, extraArgs...) args = append(args, image) args = append(args, sleepCommandForDaemonPlatform()...) - return strings.TrimSpace(cli.DockerCmd(c, args...).Combined()) + return strings.TrimSpace(cli.DockerCmd(t, args...).Combined()) } // minimalBaseImage returns the name of the minimal base image for the current @@ -405,10 +405,10 @@ func waitForGoroutines(ctx context.Context, t poll.TestingT, apiClient client.AP } // getErrorMessage returns the error message from an error API response -func getErrorMessage(c *testing.T, body []byte) string { - c.Helper() +func getErrorMessage(t *testing.T, body []byte) string { + t.Helper() var resp types.ErrorResponse - assert.NilError(c, json.Unmarshal(body, &resp)) + assert.NilError(t, json.Unmarshal(body, &resp)) return strings.TrimSpace(resp.Message) } @@ -439,12 +439,12 @@ func pollCheck(t *testing.T, f checkF, compare func(x interface{}) assert.BoolOr } func reducedCheck(r reducer, funcs ...checkF) checkF { - return func(c *testing.T) (interface{}, string) { - c.Helper() + return func(t *testing.T) (interface{}, string) { + t.Helper() var values []interface{} var comments []string for _, f := range funcs { - v, comment := f(c) + v, comment := f(t) values = append(values, v) if len(comment) > 0 { comments = append(comments, comment) @@ -462,31 +462,31 @@ func sumAsIntegers(vals ...interface{}) interface{} { return s } -func loadSpecialImage(c *testing.T, imageFunc specialimage.SpecialImageFunc) string { - tmpDir := c.TempDir() +func loadSpecialImage(t *testing.T, imageFunc specialimage.SpecialImageFunc) string { + tmpDir := t.TempDir() imgDir := filepath.Join(tmpDir, "image") - assert.NilError(c, os.Mkdir(imgDir, 0o755)) + assert.NilError(t, os.Mkdir(imgDir, 0o755)) _, err := imageFunc(imgDir) - assert.NilError(c, err) + assert.NilError(t, err) rc, err := archive.TarWithOptions(imgDir, &archive.TarOptions{}) - assert.NilError(c, err) + assert.NilError(t, err) defer rc.Close() imgTar := filepath.Join(tmpDir, "image.tar") tarFile, err := os.OpenFile(imgTar, os.O_CREATE|os.O_WRONLY, 0o644) - assert.NilError(c, err) + assert.NilError(t, err) defer tarFile.Close() _, err = io.Copy(tarFile, rc) - assert.NilError(c, err) + assert.NilError(t, err) tarFile.Close() - out := cli.DockerCmd(c, "load", "-i", imgTar).Stdout() + out := cli.DockerCmd(t, "load", "-i", imgTar).Stdout() for _, line := range strings.Split(out, "\n") { line = strings.TrimSpace(line) @@ -499,6 +499,6 @@ func loadSpecialImage(c *testing.T, imageFunc specialimage.SpecialImageFunc) str } } - c.Fatalf("failed to extract image ref from %q", out) + t.Fatalf("failed to extract image ref from %q", out) return "" } diff --git a/integration-cli/events_utils_test.go b/integration-cli/events_utils_test.go index 2e63645460..453e2988a5 100644 --- a/integration-cli/events_utils_test.go +++ b/integration-cli/events_utils_test.go @@ -37,13 +37,13 @@ type eventObserver struct { // newEventObserver creates the observer and initializes the command // without running it. Users must call `eventObserver.Start` to start the command. -func newEventObserver(c *testing.T, args ...string) (*eventObserver, error) { - since := daemonTime(c).Unix() - return newEventObserverWithBacklog(c, since, args...) +func newEventObserver(t *testing.T, args ...string) (*eventObserver, error) { + since := daemonTime(t).Unix() + return newEventObserverWithBacklog(t, since, args...) } // newEventObserverWithBacklog creates a new observer changing the start time of the backlog to return. -func newEventObserverWithBacklog(c *testing.T, since int64, args ...string) (*eventObserver, error) { +func newEventObserverWithBacklog(t *testing.T, since int64, args ...string) (*eventObserver, error) { startTime := strconv.FormatInt(since, 10) cmdArgs := []string{"events", "--since", startTime} if len(args) > 0 { @@ -95,13 +95,13 @@ func (e *eventObserver) Match(match eventMatcher, process eventMatchProcessor) { e.disconnectionError = err } -func (e *eventObserver) CheckEventError(c *testing.T, id, event string, match eventMatcher) { +func (e *eventObserver) CheckEventError(t *testing.T, id, event string, match eventMatcher) { var foundEvent bool scannerOut := e.buffer.String() if e.disconnectionError != nil { - until := daemonUnixTime(c) - out := cli.DockerCmd(c, "events", "--since", e.startTime, "--until", until).Stdout() + until := daemonUnixTime(t) + out := cli.DockerCmd(t, "events", "--since", e.startTime, "--until", until).Stdout() events := strings.Split(strings.TrimSpace(out), "\n") for _, e := range events { if _, ok := match(e); ok { @@ -112,7 +112,7 @@ func (e *eventObserver) CheckEventError(c *testing.T, id, event string, match ev scannerOut = out } if !foundEvent { - c.Fatalf("failed to observe event `%s` for %s. Disconnection error: %v\nout:\n%v", event, id, e.disconnectionError, scannerOut) + t.Fatalf("failed to observe event `%s` for %s. Disconnection error: %v\nout:\n%v", event, id, e.disconnectionError, scannerOut) } } @@ -146,18 +146,18 @@ func processEventMatch(actions map[string]chan bool) eventMatchProcessor { // parseEventAction parses an event text and returns the action. // It fails if the text is not in the event format. -func parseEventAction(c *testing.T, text string) string { +func parseEventAction(t *testing.T, text string) string { matches := eventstestutils.ScanMap(text) return matches["action"] } // eventActionsByIDAndType returns the actions for a given id and type. // It fails if the text is not in the event format. -func eventActionsByIDAndType(c *testing.T, events []string, id, eventType string) []string { +func eventActionsByIDAndType(t *testing.T, events []string, id, eventType string) []string { var filtered []string for _, event := range events { matches := eventstestutils.ScanMap(event) - assert.Assert(c, matches != nil) + assert.Assert(t, matches != nil) if matchIDAndEventType(matches, id, eventType) { filtered = append(filtered, matches["action"]) } @@ -185,12 +185,12 @@ func matchEventID(matches map[string]string, id string) bool { return matchID } -func parseEvents(c *testing.T, out, match string) { +func parseEvents(t *testing.T, out, match string) { events := strings.Split(strings.TrimSpace(out), "\n") for _, event := range events { matches := eventstestutils.ScanMap(event) matched, err := regexp.MatchString(match, matches["action"]) - assert.NilError(c, err) - assert.Assert(c, matched, "Matcher: %s did not match %s", match, matches["action"]) + assert.NilError(t, err) + assert.Assert(t, matched, "Matcher: %s did not match %s", match, matches["action"]) } } diff --git a/integration-cli/fixtures_linux_daemon_test.go b/integration-cli/fixtures_linux_daemon_test.go index 7bd5728334..f36986ae08 100644 --- a/integration-cli/fixtures_linux_daemon_test.go +++ b/integration-cli/fixtures_linux_daemon_test.go @@ -15,37 +15,37 @@ import ( "gotest.tools/v3/assert" ) -func ensureSyscallTest(ctx context.Context, c *testing.T) { - defer testEnv.ProtectImage(c, "syscall-test:latest") +func ensureSyscallTest(ctx context.Context, t *testing.T) { + defer testEnv.ProtectImage(t, "syscall-test:latest") // If the image already exists, there's nothing left to do. - if testEnv.HasExistingImage(c, "syscall-test:latest") { + if testEnv.HasExistingImage(t, "syscall-test:latest") { return } // if no match, must build in docker, which is significantly slower // (slower mostly because of the vfs graphdriver) if testEnv.DaemonInfo.OSType != runtime.GOOS { - ensureSyscallTestBuild(ctx, c) + ensureSyscallTestBuild(ctx, t) return } tmp, err := os.MkdirTemp("", "syscall-test-build") - assert.NilError(c, err, "couldn't create temp dir") + assert.NilError(t, err, "couldn't create temp dir") defer os.RemoveAll(tmp) gcc, err := exec.LookPath("gcc") - assert.NilError(c, err, "could not find gcc") + assert.NilError(t, err, "could not find gcc") tests := []string{"userns", "ns", "acct", "setuid", "setgid", "socket", "raw"} for _, test := range tests { out, err := exec.Command(gcc, "-g", "-Wall", "-static", fmt.Sprintf("../contrib/syscall-test/%s.c", test), "-o", fmt.Sprintf("%s/%s-test", tmp, test)).CombinedOutput() - assert.NilError(c, err, string(out)) + assert.NilError(t, err, string(out)) } if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" { out, err := exec.Command(gcc, "-s", "-m32", "-nostdlib", "-static", "../contrib/syscall-test/exit32.s", "-o", tmp+"/"+"exit32-test").CombinedOutput() - assert.NilError(c, err, string(out)) + assert.NilError(t, err, string(out)) } dockerFile := filepath.Join(tmp, "Dockerfile") @@ -54,7 +54,7 @@ func ensureSyscallTest(ctx context.Context, c *testing.T) { COPY . /usr/bin/ `) err = os.WriteFile(dockerFile, content, 0o600) - assert.NilError(c, err) + assert.NilError(t, err) var buildArgs []string if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { @@ -62,12 +62,12 @@ func ensureSyscallTest(ctx context.Context, c *testing.T) { } buildArgs = append(buildArgs, []string{"-q", "-t", "syscall-test", tmp}...) buildArgs = append([]string{"build"}, buildArgs...) - cli.DockerCmd(c, buildArgs...) + cli.DockerCmd(t, buildArgs...) } -func ensureSyscallTestBuild(ctx context.Context, c *testing.T) { +func ensureSyscallTestBuild(ctx context.Context, t *testing.T) { err := load.FrozenImagesLinux(ctx, testEnv.APIClient(), "debian:bookworm-slim") - assert.NilError(c, err) + assert.NilError(t, err) var buildArgs []string if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { @@ -75,32 +75,32 @@ func ensureSyscallTestBuild(ctx context.Context, c *testing.T) { } buildArgs = append(buildArgs, []string{"-q", "-t", "syscall-test", "../contrib/syscall-test"}...) buildArgs = append([]string{"build"}, buildArgs...) - cli.DockerCmd(c, buildArgs...) + cli.DockerCmd(t, buildArgs...) } -func ensureNNPTest(ctx context.Context, c *testing.T) { - defer testEnv.ProtectImage(c, "nnp-test:latest") +func ensureNNPTest(ctx context.Context, t *testing.T) { + defer testEnv.ProtectImage(t, "nnp-test:latest") // If the image already exists, there's nothing left to do. - if testEnv.HasExistingImage(c, "nnp-test:latest") { + if testEnv.HasExistingImage(t, "nnp-test:latest") { return } // if no match, must build in docker, which is significantly slower // (slower mostly because of the vfs graphdriver) if testEnv.DaemonInfo.OSType != runtime.GOOS { - ensureNNPTestBuild(ctx, c) + ensureNNPTestBuild(ctx, t) return } tmp, err := os.MkdirTemp("", "docker-nnp-test") - assert.NilError(c, err) + assert.NilError(t, err) gcc, err := exec.LookPath("gcc") - assert.NilError(c, err, "could not find gcc") + assert.NilError(t, err, "could not find gcc") out, err := exec.Command(gcc, "-g", "-Wall", "-static", "../contrib/nnp-test/nnp-test.c", "-o", filepath.Join(tmp, "nnp-test")).CombinedOutput() - assert.NilError(c, err, string(out)) + assert.NilError(t, err, string(out)) dockerfile := filepath.Join(tmp, "Dockerfile") content := ` @@ -109,7 +109,7 @@ func ensureNNPTest(ctx context.Context, c *testing.T) { RUN chmod +s /usr/bin/nnp-test ` err = os.WriteFile(dockerfile, []byte(content), 0o600) - assert.NilError(c, err, "could not write Dockerfile for nnp-test image") + assert.NilError(t, err, "could not write Dockerfile for nnp-test image") var buildArgs []string if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { @@ -117,12 +117,12 @@ func ensureNNPTest(ctx context.Context, c *testing.T) { } buildArgs = append(buildArgs, []string{"-q", "-t", "nnp-test", tmp}...) buildArgs = append([]string{"build"}, buildArgs...) - cli.DockerCmd(c, buildArgs...) + cli.DockerCmd(t, buildArgs...) } -func ensureNNPTestBuild(ctx context.Context, c *testing.T) { +func ensureNNPTestBuild(ctx context.Context, t *testing.T) { err := load.FrozenImagesLinux(ctx, testEnv.APIClient(), "debian:bookworm-slim") - assert.NilError(c, err) + assert.NilError(t, err) var buildArgs []string if arg := os.Getenv("DOCKER_BUILD_ARGS"); strings.TrimSpace(arg) != "" { @@ -130,5 +130,5 @@ func ensureNNPTestBuild(ctx context.Context, c *testing.T) { } buildArgs = append(buildArgs, []string{"-q", "-t", "npp-test", "../contrib/nnp-test"}...) buildArgs = append([]string{"build"}, buildArgs...) - cli.DockerCmd(c, buildArgs...) + cli.DockerCmd(t, buildArgs...) } diff --git a/integration-cli/utils_test.go b/integration-cli/utils_test.go index 1d86e0355b..4bf135a12b 100644 --- a/integration-cli/utils_test.go +++ b/integration-cli/utils_test.go @@ -115,7 +115,7 @@ type elementListOptions struct { element, format string } -func existingElements(c *testing.T, opts elementListOptions) []string { +func existingElements(t *testing.T, opts elementListOptions) []string { var args []string switch opts.element { case "container": @@ -132,7 +132,7 @@ func existingElements(c *testing.T, opts elementListOptions) []string { if opts.format != "" { args = append(args, "--format", opts.format) } - out := cli.DockerCmd(c, args...).Combined() + out := cli.DockerCmd(t, args...).Combined() var lines []string for _, l := range strings.Split(out, "\n") { if l != "" { @@ -143,13 +143,13 @@ func existingElements(c *testing.T, opts elementListOptions) []string { } // ExistingContainerIDs returns a list of currently existing container IDs. -func ExistingContainerIDs(c *testing.T) []string { - return existingElements(c, elementListOptions{element: "container", format: "{{.ID}}"}) +func ExistingContainerIDs(t *testing.T) []string { + return existingElements(t, elementListOptions{element: "container", format: "{{.ID}}"}) } // ExistingContainerNames returns a list of existing container names. -func ExistingContainerNames(c *testing.T) []string { - return existingElements(c, elementListOptions{element: "container", format: "{{.Names}}"}) +func ExistingContainerNames(t *testing.T) []string { + return existingElements(t, elementListOptions{element: "container", format: "{{.Names}}"}) } // RemoveLinesForExistingElements removes existing elements from the output of a