Skip to content

Commit

Permalink
Merge pull request #5781 from thaJeztah/less_pkg_errors
Browse files Browse the repository at this point in the history
remove uses of pkg/errors in tests
  • Loading branch information
thaJeztah authored Feb 3, 2025
2 parents bdd70c1 + 2e26ce1 commit 4d7fe01
Show file tree
Hide file tree
Showing 71 changed files with 219 additions and 217 deletions.
4 changes: 2 additions & 2 deletions cli/command/checkpoint/create_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package checkpoint

import (
"errors"
"io"
"strings"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand All @@ -29,7 +29,7 @@ func TestCheckpointCreateErrors(t *testing.T) {
{
args: []string{"foo", "bar"},
checkpointCreateFunc: func(container string, options checkpoint.CreateOptions) error {
return errors.Errorf("error creating checkpoint for container foo")
return errors.New("error creating checkpoint for container foo")
},
expectedError: "error creating checkpoint for container foo",
},
Expand Down
4 changes: 2 additions & 2 deletions cli/command/checkpoint/list_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package checkpoint

import (
"errors"
"io"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
Expand All @@ -29,7 +29,7 @@ func TestCheckpointListErrors(t *testing.T) {
{
args: []string{"foo"},
checkpointListFunc: func(container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) {
return []checkpoint.Summary{}, errors.Errorf("error getting checkpoints for container foo")
return []checkpoint.Summary{}, errors.New("error getting checkpoints for container foo")
},
expectedError: "error getting checkpoints for container foo",
},
Expand Down
4 changes: 2 additions & 2 deletions cli/command/checkpoint/remove_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package checkpoint

import (
"errors"
"io"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand All @@ -28,7 +28,7 @@ func TestCheckpointRemoveErrors(t *testing.T) {
{
args: []string{"foo", "bar"},
checkpointDeleteFunc: func(container string, options checkpoint.DeleteOptions) error {
return errors.Errorf("error deleting checkpoint")
return errors.New("error deleting checkpoint")
},
expectedError: "error deleting checkpoint",
},
Expand Down
2 changes: 1 addition & 1 deletion cli/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package command
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
"gotest.tools/v3/fs"
)
Expand Down
13 changes: 7 additions & 6 deletions cli/command/config/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package config

import (
"context"
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand All @@ -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"
Expand All @@ -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",
},
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions cli/command/config/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"errors"
"fmt"
"io"
"testing"
Expand All @@ -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"
)
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand Down Expand Up @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions cli/command/config/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"errors"
"io"
"testing"
"time"
Expand All @@ -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"
Expand All @@ -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",
},
Expand Down
6 changes: 3 additions & 3 deletions cli/command/config/remove_test.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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",
},
Expand Down Expand Up @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/attach_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package container

import (
"errors"
"io"
"testing"

"github.com/docker/cli/cli"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
)

Expand All @@ -23,7 +23,7 @@ func TestNewAttachCommandErrors(t *testing.T) {
args: []string{"5cb5bb5e4a3b"},
expectedError: "something went wrong",
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return container.InspectResponse{}, errors.Errorf("something went wrong")
return container.InspectResponse{}, errors.New("something went wrong")
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package container

import (
"context"
"errors"
"io"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package container

import (
"context"
"errors"
"io"
"strings"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"errors"
"io"
"os"
"testing"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/fs"
Expand Down Expand Up @@ -259,7 +259,7 @@ func TestNewExecCommandErrors(t *testing.T) {
args: []string{"5cb5bb5e4a3b", "-t", "-i", "bash"},
expectedError: "something went wrong",
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
return container.InspectResponse{}, errors.Errorf("something went wrong")
return container.InspectResponse{}, errors.New("something went wrong")
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/opts_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package container

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"
"github.com/spf13/pflag"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
Expand Down Expand Up @@ -340,7 +340,7 @@ func compareRandomizedStrings(a, b, c, d string) error {
if a == d && b == c {
return nil
}
return errors.Errorf("strings don't match")
return errors.New("strings don't match")
}

// Simple parse with MacAddress validation
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package container

import (
"context"
"errors"
"io"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/pkg/errors"
)

func TestContainerPrunePromptTermination(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package container

import (
"context"
"errors"
"io"
"testing"

"github.com/docker/cli/internal/test"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"errors"
"io"
"sort"
"sync"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down
Loading

0 comments on commit 4d7fe01

Please sign in to comment.