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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-02-01 14:39:04 +01:00
parent 957be84a3c
commit 0d913efe8a
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
4 changed files with 16 additions and 15 deletions

View File

@ -2,6 +2,8 @@ package config
import ( import (
"context" "context"
"errors"
"fmt"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
@ -12,7 +14,6 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden" "gotest.tools/v3/golden"
@ -37,7 +38,7 @@ func TestConfigCreateErrors(t *testing.T) {
{ {
args: []string{"name", filepath.Join("testdata", configDataFile)}, args: []string{"name", filepath.Join("testdata", configDataFile)},
configCreateFunc: func(_ context.Context, configSpec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { 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", expectedError: "error creating config",
}, },
@ -63,7 +64,7 @@ func TestConfigCreateWithName(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
if spec.Name != name { 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 actual = spec.Data
@ -102,7 +103,7 @@ func TestConfigCreateWithLabels(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
if !reflect.DeepEqual(spec, expected) { 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{ return types.ConfigCreateResponse{
@ -128,11 +129,11 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) {
if spec.Name != name { 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 { 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{ return types.ConfigCreateResponse{

View File

@ -2,6 +2,7 @@ package config
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"testing" "testing"
@ -10,7 +11,6 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders" "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
"gotest.tools/v3/golden" "gotest.tools/v3/golden"
) )
@ -28,7 +28,7 @@ func TestConfigInspectErrors(t *testing.T) {
{ {
args: []string{"foo"}, args: []string{"foo"},
configInspectFunc: func(_ context.Context, configID string) (swarm.Config, []byte, error) { 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", expectedError: "error while inspecting the config",
}, },
@ -45,7 +45,7 @@ func TestConfigInspectErrors(t *testing.T) {
if configID == "foo" { if configID == "foo" {
return *builders.Config(builders.ConfigName("foo")), nil, nil 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", expectedError: "error while inspecting the config",
}, },
@ -77,7 +77,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) {
args: []string{"foo"}, args: []string{"foo"},
configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) { configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) {
if name != "foo" { 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 return *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), nil, nil
}, },

View File

@ -2,6 +2,7 @@ package config
import ( import (
"context" "context"
"errors"
"io" "io"
"testing" "testing"
"time" "time"
@ -11,7 +12,6 @@ import (
"github.com/docker/cli/internal/test/builders" "github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden" "gotest.tools/v3/golden"
@ -29,7 +29,7 @@ func TestConfigListErrors(t *testing.T) {
}, },
{ {
configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { 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", expectedError: "error listing configs",
}, },

View File

@ -1,12 +1,12 @@
package config package config
import ( import (
"errors"
"io" "io"
"strings" "strings"
"testing" "testing"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/pkg/errors"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
) )
@ -24,7 +24,7 @@ func TestConfigRemoveErrors(t *testing.T) {
{ {
args: []string{"foo"}, args: []string{"foo"},
configRemoveFunc: func(name string) error { configRemoveFunc: func(name string) error {
return errors.Errorf("error removing config") return errors.New("error removing config")
}, },
expectedError: "error removing config", expectedError: "error removing config",
}, },
@ -66,7 +66,7 @@ func TestConfigRemoveContinueAfterError(t *testing.T) {
configRemoveFunc: func(name string) error { configRemoveFunc: func(name string) error {
removedConfigs = append(removedConfigs, name) removedConfigs = append(removedConfigs, name)
if name == "foo" { if name == "foo" {
return errors.Errorf("error removing config: %s", name) return errors.New("error removing config: " + name)
} }
return nil return nil
}, },