From 694d2480010aa2d6aabd63c2c9896d20d30f7cd1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 1 Feb 2025 14:51:41 +0100 Subject: [PATCH] cli/command/swarm: remove uses of pkg/errors in tests While there may be reasons to keep pkg/errors in production code, we don't need them for these tests. Signed-off-by: Sebastiaan van Stijn --- cli/command/swarm/init_test.go | 12 ++++++------ cli/command/swarm/join_test.go | 6 +++--- cli/command/swarm/join_token_test.go | 12 ++++++------ cli/command/swarm/leave_test.go | 4 ++-- cli/command/swarm/unlock_key_test.go | 16 ++++++++-------- cli/command/swarm/unlock_test.go | 6 +++--- cli/command/swarm/update_test.go | 24 ++++++++++++------------ 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/cli/command/swarm/init_test.go b/cli/command/swarm/init_test.go index 8a3d981b66..cd8fafac1a 100644 --- a/cli/command/swarm/init_test.go +++ b/cli/command/swarm/init_test.go @@ -1,6 +1,7 @@ package swarm import ( + "errors" "fmt" "io" "testing" @@ -8,7 +9,6 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -26,28 +26,28 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) { { name: "init-failed", swarmInitFunc: func() (string, error) { - return "", errors.Errorf("error initializing the swarm") + return "", errors.New("error initializing the swarm") }, expectedError: "error initializing the swarm", }, { name: "init-failed-with-ip-choice", swarmInitFunc: func() (string, error) { - return "", errors.Errorf("could not choose an IP address to advertise") + return "", errors.New("could not choose an IP address to advertise") }, expectedError: "could not choose an IP address to advertise - specify one with --advertise-addr", }, { name: "swarm-inspect-after-init-failed", swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, errors.New("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, { name: "node-inspect-after-init-failed", nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node") + return swarm.Node{}, []byte{}, errors.New("error inspecting the node") }, expectedError: "error inspecting the node", }, @@ -57,7 +57,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) { flagAutolock: "true", }, swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { - return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting swarm unlock key") + return types.SwarmUnlockKeyResponse{}, errors.New("error getting swarm unlock key") }, expectedError: "could not fetch unlock key: error getting swarm unlock key", }, diff --git a/cli/command/swarm/join_test.go b/cli/command/swarm/join_test.go index 53c0c08627..02ff901ac3 100644 --- a/cli/command/swarm/join_test.go +++ b/cli/command/swarm/join_test.go @@ -1,6 +1,7 @@ package swarm import ( + "errors" "io" "strings" "testing" @@ -8,7 +9,6 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -34,7 +34,7 @@ func TestSwarmJoinErrors(t *testing.T) { name: "join-failed", args: []string{"remote"}, swarmJoinFunc: func() error { - return errors.Errorf("error joining the swarm") + return errors.New("error joining the swarm") }, expectedError: "error joining the swarm", }, @@ -42,7 +42,7 @@ func TestSwarmJoinErrors(t *testing.T) { name: "join-failed-on-init", args: []string{"remote"}, infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, errors.New("error asking for node info") }, expectedError: "error asking for node info", }, diff --git a/cli/command/swarm/join_token_test.go b/cli/command/swarm/join_token_test.go index 0942b2b7c7..76db830b64 100644 --- a/cli/command/swarm/join_token_test.go +++ b/cli/command/swarm/join_token_test.go @@ -1,6 +1,7 @@ package swarm import ( + "errors" "fmt" "io" "testing" @@ -9,7 +10,6 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -43,7 +43,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { name: "swarm-inspect-failed", args: []string{"worker"}, swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, errors.New("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, @@ -54,7 +54,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { flagRotate: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, errors.New("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, @@ -65,7 +65,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { flagRotate: "true", }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { - return errors.Errorf("error updating the swarm") + return errors.New("error updating the swarm") }, expectedError: "error updating the swarm", }, @@ -73,7 +73,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { name: "node-inspect-failed", args: []string{"worker"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting node") + return swarm.Node{}, []byte{}, errors.New("error inspecting node") }, expectedError: "error inspecting node", }, @@ -81,7 +81,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { name: "info-failed", args: []string{"worker"}, infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, errors.New("error asking for node info") }, expectedError: "error asking for node info", }, diff --git a/cli/command/swarm/leave_test.go b/cli/command/swarm/leave_test.go index b3a868b25c..19dd1dc1f6 100644 --- a/cli/command/swarm/leave_test.go +++ b/cli/command/swarm/leave_test.go @@ -1,12 +1,12 @@ package swarm import ( + "errors" "io" "strings" "testing" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -26,7 +26,7 @@ func TestSwarmLeaveErrors(t *testing.T) { { name: "leave-failed", swarmLeaveFunc: func() error { - return errors.Errorf("error leaving the swarm") + return errors.New("error leaving the swarm") }, expectedError: "error leaving the swarm", }, diff --git a/cli/command/swarm/unlock_key_test.go b/cli/command/swarm/unlock_key_test.go index 8cb403dc7f..e55567b50e 100644 --- a/cli/command/swarm/unlock_key_test.go +++ b/cli/command/swarm/unlock_key_test.go @@ -1,6 +1,7 @@ package swarm import ( + "errors" "fmt" "io" "testing" @@ -9,7 +10,6 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -35,7 +35,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { flagRotate: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, errors.New("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, @@ -58,14 +58,14 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { return *builders.Swarm(builders.Autolock()), nil }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { - return errors.Errorf("error updating the swarm") + return errors.New("error updating the swarm") }, expectedError: "error updating the swarm", }, { name: "swarm-get-unlock-key-failed", swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { - return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key") + return types.SwarmUnlockKeyResponse{}, errors.New("error getting unlock key") }, expectedError: "error getting unlock key", }, @@ -88,8 +88,8 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc, })) cmd.SetArgs(tc.args) - for key, value := range tc.flags { - assert.Check(t, cmd.Flags().Set(key, value)) + for k, v := range tc.flags { + assert.Check(t, cmd.Flags().Set(k, v)) } cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) @@ -165,8 +165,8 @@ func TestSwarmUnlockKey(t *testing.T) { }) cmd := newUnlockKeyCommand(cli) cmd.SetArgs(tc.args) - for key, value := range tc.flags { - assert.Check(t, cmd.Flags().Set(key, value)) + for k, v := range tc.flags { + assert.Check(t, cmd.Flags().Set(k, v)) } assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("unlockkeys-%s.golden", tc.name)) diff --git a/cli/command/swarm/unlock_test.go b/cli/command/swarm/unlock_test.go index 07c3cf1d6e..f0cdfdfa8e 100644 --- a/cli/command/swarm/unlock_test.go +++ b/cli/command/swarm/unlock_test.go @@ -1,6 +1,7 @@ package swarm import ( + "errors" "io" "strings" "testing" @@ -9,7 +10,6 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" "gotest.tools/v3/assert" ) @@ -58,7 +58,7 @@ func TestSwarmUnlockErrors(t *testing.T) { }, nil }, swarmUnlockFunc: func(req swarm.UnlockRequest) error { - return errors.Errorf("error unlocking the swarm") + return errors.New("error unlocking the swarm") }, expectedError: "error unlocking the swarm", }, @@ -90,7 +90,7 @@ func TestSwarmUnlock(t *testing.T) { }, swarmUnlockFunc: func(req swarm.UnlockRequest) error { if req.UnlockKey != input { - return errors.Errorf("Invalid unlock key") + return errors.New("invalid unlock key") } return nil }, diff --git a/cli/command/swarm/update_test.go b/cli/command/swarm/update_test.go index 3f147f3f90..98dd0b7abe 100644 --- a/cli/command/swarm/update_test.go +++ b/cli/command/swarm/update_test.go @@ -1,6 +1,7 @@ package swarm import ( + "errors" "fmt" "io" "testing" @@ -10,7 +11,6 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -36,7 +36,7 @@ func TestSwarmUpdateErrors(t *testing.T) { flagTaskHistoryLimit: "10", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, errors.New("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, @@ -46,7 +46,7 @@ func TestSwarmUpdateErrors(t *testing.T) { flagTaskHistoryLimit: "10", }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { - return errors.Errorf("error updating the swarm") + return errors.New("error updating the swarm") }, expectedError: "error updating the swarm", }, @@ -59,7 +59,7 @@ func TestSwarmUpdateErrors(t *testing.T) { return *builders.Swarm(), nil }, swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { - return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key") + return types.SwarmUnlockKeyResponse{}, errors.New("error getting unlock key") }, expectedError: "error getting unlock key", }, @@ -114,33 +114,33 @@ func TestSwarmUpdate(t *testing.T) { }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 { - return errors.Errorf("historyLimit not correctly set") + return errors.New("historyLimit not correctly set") } heartbeatDuration, err := time.ParseDuration("10s") if err != nil { return err } if swarm.Dispatcher.HeartbeatPeriod != heartbeatDuration { - return errors.Errorf("heartbeatPeriodLimit not correctly set") + return errors.New("heartbeatPeriodLimit not correctly set") } certExpiryDuration, err := time.ParseDuration("20s") if err != nil { return err } if swarm.CAConfig.NodeCertExpiry != certExpiryDuration { - return errors.Errorf("certExpiry not correctly set") + return errors.New("certExpiry not correctly set") } if len(swarm.CAConfig.ExternalCAs) != 1 || swarm.CAConfig.ExternalCAs[0].CACert != "trustroot" { - return errors.Errorf("externalCA not correctly set") + return errors.New("externalCA not correctly set") } if *swarm.Raft.KeepOldSnapshots != 10 { - return errors.Errorf("keepOldSnapshots not correctly set") + return errors.New("keepOldSnapshots not correctly set") } if swarm.Raft.SnapshotInterval != 100 { - return errors.Errorf("snapshotInterval not correctly set") + return errors.New("snapshotInterval not correctly set") } if !swarm.EncryptionConfig.AutoLockManagers { - return errors.Errorf("autolock not correctly set") + return errors.New("autolock not correctly set") } return nil }, @@ -153,7 +153,7 @@ func TestSwarmUpdate(t *testing.T) { }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 { - return errors.Errorf("historyLimit not correctly set") + return errors.New("historyLimit not correctly set") } return nil },