cli/command/stack: 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:50:31 +01:00
parent ec5ae0c2d0
commit 8b09ee1e12
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
4 changed files with 13 additions and 13 deletions

View File

@ -1,6 +1,7 @@
package stack package stack
import ( import (
"errors"
"io" "io"
"testing" "testing"
@ -8,7 +9,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"
"gotest.tools/v3/golden" "gotest.tools/v3/golden"
) )
@ -34,7 +34,7 @@ func TestListErrors(t *testing.T) {
{ {
args: []string{}, args: []string{},
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
return []swarm.Service{}, errors.Errorf("error getting services") return []swarm.Service{}, errors.New("error getting services")
}, },
expectedError: "error getting services", expectedError: "error getting services",
}, },

View File

@ -1,6 +1,7 @@
package stack package stack
import ( import (
"errors"
"io" "io"
"testing" "testing"
"time" "time"
@ -10,7 +11,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"
@ -33,7 +33,7 @@ func TestStackPsErrors(t *testing.T) {
{ {
args: []string{"foo"}, args: []string{"foo"},
taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) {
return nil, errors.Errorf("error getting tasks") return nil, errors.New("error getting tasks")
}, },
expectedError: "error getting tasks", expectedError: "error getting tasks",
}, },

View File

@ -1,6 +1,7 @@
package stack package stack
import ( import (
"errors"
"io" "io"
"testing" "testing"
@ -9,7 +10,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"
@ -27,7 +27,7 @@ func TestStackServicesErrors(t *testing.T) {
{ {
args: []string{"foo"}, args: []string{"foo"},
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
return nil, errors.Errorf("error getting services") return nil, errors.New("error getting services")
}, },
expectedError: "error getting services", expectedError: "error getting services",
}, },
@ -37,7 +37,7 @@ func TestStackServicesErrors(t *testing.T) {
return []swarm.Service{*builders.Service(builders.GlobalService())}, nil return []swarm.Service{*builders.Service(builders.GlobalService())}, nil
}, },
nodeListFunc: func(options types.NodeListOptions) ([]swarm.Node, error) { nodeListFunc: func(options types.NodeListOptions) ([]swarm.Node, error) {
return nil, errors.Errorf("error getting nodes") return nil, errors.New("error getting nodes")
}, },
taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) {
return []swarm.Task{*builders.Task()}, nil return []swarm.Task{*builders.Task()}, nil
@ -50,7 +50,7 @@ func TestStackServicesErrors(t *testing.T) {
return []swarm.Service{*builders.Service(builders.GlobalService())}, nil return []swarm.Service{*builders.Service(builders.GlobalService())}, nil
}, },
taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) {
return nil, errors.Errorf("error getting tasks") return nil, errors.New("error getting tasks")
}, },
expectedError: "error getting tasks", expectedError: "error getting tasks",
}, },

View File

@ -2,11 +2,11 @@ package swarm
import ( import (
"context" "context"
"errors"
"testing" "testing"
"github.com/docker/cli/internal/test/network" "github.com/docker/cli/internal/test/network"
networktypes "github.com/docker/docker/api/types/network" networktypes "github.com/docker/docker/api/types/network"
"github.com/pkg/errors"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
@ -28,8 +28,8 @@ func TestValidateExternalNetworks(t *testing.T) {
expectedMsg: "could not be found. You need to create a swarm-scoped network", expectedMsg: "could not be found. You need to create a swarm-scoped network",
}, },
{ {
inspectError: errors.New("Unexpected"), inspectError: errors.New("unexpected"),
expectedMsg: "Unexpected", expectedMsg: "unexpected",
}, },
// FIXME(vdemeester) that doesn't work under windows, the check needs to be smarter // FIXME(vdemeester) that doesn't work under windows, the check needs to be smarter
/* /*
@ -49,13 +49,13 @@ func TestValidateExternalNetworks(t *testing.T) {
} }
for _, testcase := range testcases { for _, testcase := range testcases {
fakeClient := &network.FakeClient{ client := &network.FakeClient{
NetworkInspectFunc: func(_ context.Context, _ string, _ networktypes.InspectOptions) (networktypes.Inspect, error) { NetworkInspectFunc: func(_ context.Context, _ string, _ networktypes.InspectOptions) (networktypes.Inspect, error) {
return testcase.inspectResponse, testcase.inspectError return testcase.inspectResponse, testcase.inspectError
}, },
} }
networks := []string{testcase.network} networks := []string{testcase.network}
err := validateExternalNetworks(context.Background(), fakeClient, networks) err := validateExternalNetworks(context.Background(), client, networks)
if testcase.expectedMsg == "" { if testcase.expectedMsg == "" {
assert.NilError(t, err) assert.NilError(t, err)
} else { } else {