From 0d913efe8a3a699352cee4b5c3fe3957335258b7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 1 Feb 2025 14:39:04 +0100 Subject: [PATCH] cli/command/config: 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/config/create_test.go | 13 +++++++------ cli/command/config/inspect_test.go | 8 ++++---- cli/command/config/ls_test.go | 4 ++-- cli/command/config/remove_test.go | 6 +++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cli/command/config/create_test.go b/cli/command/config/create_test.go index 855fab3fdf..9c919f8800 100644 --- a/cli/command/config/create_test.go +++ b/cli/command/config/create_test.go @@ -2,6 +2,8 @@ package config import ( "context" + "errors" + "fmt" "io" "os" "path/filepath" @@ -12,7 +14,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" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -37,7 +38,7 @@ func TestConfigCreateErrors(t *testing.T) { { args: []string{"name", filepath.Join("testdata", configDataFile)}, configCreateFunc: func(_ context.Context, configSpec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { - return types.ConfigCreateResponse{}, errors.Errorf("error creating config") + return types.ConfigCreateResponse{}, errors.New("error creating config") }, expectedError: "error creating config", }, @@ -63,7 +64,7 @@ func TestConfigCreateWithName(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if spec.Name != name { - return types.ConfigCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) + return types.ConfigCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name) } actual = spec.Data @@ -102,7 +103,7 @@ func TestConfigCreateWithLabels(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if !reflect.DeepEqual(spec, expected) { - return types.ConfigCreateResponse{}, errors.Errorf("expected %+v, got %+v", expected, spec) + return types.ConfigCreateResponse{}, fmt.Errorf("expected %+v, got %+v", expected, spec) } return types.ConfigCreateResponse{ @@ -128,11 +129,11 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if spec.Name != name { - return types.ConfigCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) + return types.ConfigCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name) } if spec.Templating.Name != expectedDriver.Name { - return types.ConfigCreateResponse{}, errors.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) + return types.ConfigCreateResponse{}, fmt.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) } return types.ConfigCreateResponse{ diff --git a/cli/command/config/inspect_test.go b/cli/command/config/inspect_test.go index fc22516fbb..a2a8e648ba 100644 --- a/cli/command/config/inspect_test.go +++ b/cli/command/config/inspect_test.go @@ -2,6 +2,7 @@ package config import ( "context" + "errors" "fmt" "io" "testing" @@ -10,7 +11,6 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -28,7 +28,7 @@ func TestConfigInspectErrors(t *testing.T) { { args: []string{"foo"}, configInspectFunc: func(_ context.Context, configID string) (swarm.Config, []byte, error) { - return swarm.Config{}, nil, errors.Errorf("error while inspecting the config") + return swarm.Config{}, nil, errors.New("error while inspecting the config") }, expectedError: "error while inspecting the config", }, @@ -45,7 +45,7 @@ func TestConfigInspectErrors(t *testing.T) { if configID == "foo" { return *builders.Config(builders.ConfigName("foo")), nil, nil } - return swarm.Config{}, nil, errors.Errorf("error while inspecting the config") + return swarm.Config{}, nil, errors.New("error while inspecting the config") }, expectedError: "error while inspecting the config", }, @@ -77,7 +77,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) { args: []string{"foo"}, configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) { if name != "foo" { - return swarm.Config{}, nil, errors.Errorf("Invalid name, expected %s, got %s", "foo", name) + return swarm.Config{}, nil, fmt.Errorf("invalid name, expected %s, got %s", "foo", name) } return *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), nil, nil }, diff --git a/cli/command/config/ls_test.go b/cli/command/config/ls_test.go index 15658ee330..d740ef9278 100644 --- a/cli/command/config/ls_test.go +++ b/cli/command/config/ls_test.go @@ -2,6 +2,7 @@ package config import ( "context" + "errors" "io" "testing" "time" @@ -11,7 +12,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" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -29,7 +29,7 @@ func TestConfigListErrors(t *testing.T) { }, { configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { - return []swarm.Config{}, errors.Errorf("error listing configs") + return []swarm.Config{}, errors.New("error listing configs") }, expectedError: "error listing configs", }, diff --git a/cli/command/config/remove_test.go b/cli/command/config/remove_test.go index d1c5a71f9f..9213fcc11f 100644 --- a/cli/command/config/remove_test.go +++ b/cli/command/config/remove_test.go @@ -1,12 +1,12 @@ package config 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" ) @@ -24,7 +24,7 @@ func TestConfigRemoveErrors(t *testing.T) { { args: []string{"foo"}, configRemoveFunc: func(name string) error { - return errors.Errorf("error removing config") + return errors.New("error removing config") }, expectedError: "error removing config", }, @@ -66,7 +66,7 @@ func TestConfigRemoveContinueAfterError(t *testing.T) { configRemoveFunc: func(name string) error { removedConfigs = append(removedConfigs, name) if name == "foo" { - return errors.Errorf("error removing config: %s", name) + return errors.New("error removing config: " + name) } return nil },