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 (
"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{

View File

@ -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
},

View File

@ -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",
},

View File

@ -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
},