cli/command/swarm: 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:
parent
8b09ee1e12
commit
694d248001
@ -1,6 +1,7 @@
|
||||
package swarm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
@ -8,7 +9,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"
|
||||
"gotest.tools/v3/golden"
|
||||
)
|
||||
@ -26,28 +26,28 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
|
||||
{
|
||||
name: "init-failed",
|
||||
swarmInitFunc: func() (string, error) {
|
||||
return "", errors.Errorf("error initializing the swarm")
|
||||
return "", errors.New("error initializing the swarm")
|
||||
},
|
||||
expectedError: "error initializing the swarm",
|
||||
},
|
||||
{
|
||||
name: "init-failed-with-ip-choice",
|
||||
swarmInitFunc: func() (string, error) {
|
||||
return "", errors.Errorf("could not choose an IP address to advertise")
|
||||
return "", errors.New("could not choose an IP address to advertise")
|
||||
},
|
||||
expectedError: "could not choose an IP address to advertise - specify one with --advertise-addr",
|
||||
},
|
||||
{
|
||||
name: "swarm-inspect-after-init-failed",
|
||||
swarmInspectFunc: func() (swarm.Swarm, error) {
|
||||
return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
|
||||
return swarm.Swarm{}, errors.New("error inspecting the swarm")
|
||||
},
|
||||
expectedError: "error inspecting the swarm",
|
||||
},
|
||||
{
|
||||
name: "node-inspect-after-init-failed",
|
||||
nodeInspectFunc: func() (swarm.Node, []byte, error) {
|
||||
return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
|
||||
return swarm.Node{}, []byte{}, errors.New("error inspecting the node")
|
||||
},
|
||||
expectedError: "error inspecting the node",
|
||||
},
|
||||
@ -57,7 +57,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
|
||||
flagAutolock: "true",
|
||||
},
|
||||
swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
|
||||
return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting swarm unlock key")
|
||||
return types.SwarmUnlockKeyResponse{}, errors.New("error getting swarm unlock key")
|
||||
},
|
||||
expectedError: "could not fetch unlock key: error getting swarm unlock key",
|
||||
},
|
||||
|
@ -1,6 +1,7 @@
|
||||
package swarm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -8,7 +9,6 @@ import (
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/system"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
@ -34,7 +34,7 @@ func TestSwarmJoinErrors(t *testing.T) {
|
||||
name: "join-failed",
|
||||
args: []string{"remote"},
|
||||
swarmJoinFunc: func() error {
|
||||
return errors.Errorf("error joining the swarm")
|
||||
return errors.New("error joining the swarm")
|
||||
},
|
||||
expectedError: "error joining the swarm",
|
||||
},
|
||||
@ -42,7 +42,7 @@ func TestSwarmJoinErrors(t *testing.T) {
|
||||
name: "join-failed-on-init",
|
||||
args: []string{"remote"},
|
||||
infoFunc: func() (system.Info, error) {
|
||||
return system.Info{}, errors.Errorf("error asking for node info")
|
||||
return system.Info{}, errors.New("error asking for node info")
|
||||
},
|
||||
expectedError: "error asking for node info",
|
||||
},
|
||||
|
@ -1,6 +1,7 @@
|
||||
package swarm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
@ -9,7 +10,6 @@ import (
|
||||
"github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/system"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/golden"
|
||||
)
|
||||
@ -43,7 +43,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
|
||||
name: "swarm-inspect-failed",
|
||||
args: []string{"worker"},
|
||||
swarmInspectFunc: func() (swarm.Swarm, error) {
|
||||
return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
|
||||
return swarm.Swarm{}, errors.New("error inspecting the swarm")
|
||||
},
|
||||
expectedError: "error inspecting the swarm",
|
||||
},
|
||||
@ -54,7 +54,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
|
||||
flagRotate: "true",
|
||||
},
|
||||
swarmInspectFunc: func() (swarm.Swarm, error) {
|
||||
return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
|
||||
return swarm.Swarm{}, errors.New("error inspecting the swarm")
|
||||
},
|
||||
expectedError: "error inspecting the swarm",
|
||||
},
|
||||
@ -65,7 +65,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
|
||||
flagRotate: "true",
|
||||
},
|
||||
swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
|
||||
return errors.Errorf("error updating the swarm")
|
||||
return errors.New("error updating the swarm")
|
||||
},
|
||||
expectedError: "error updating the swarm",
|
||||
},
|
||||
@ -73,7 +73,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
|
||||
name: "node-inspect-failed",
|
||||
args: []string{"worker"},
|
||||
nodeInspectFunc: func() (swarm.Node, []byte, error) {
|
||||
return swarm.Node{}, []byte{}, errors.Errorf("error inspecting node")
|
||||
return swarm.Node{}, []byte{}, errors.New("error inspecting node")
|
||||
},
|
||||
expectedError: "error inspecting node",
|
||||
},
|
||||
@ -81,7 +81,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
|
||||
name: "info-failed",
|
||||
args: []string{"worker"},
|
||||
infoFunc: func() (system.Info, error) {
|
||||
return system.Info{}, errors.Errorf("error asking for node info")
|
||||
return system.Info{}, errors.New("error asking for node info")
|
||||
},
|
||||
expectedError: "error asking for node info",
|
||||
},
|
||||
|
@ -1,12 +1,12 @@
|
||||
package swarm
|
||||
|
||||
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"
|
||||
)
|
||||
@ -26,7 +26,7 @@ func TestSwarmLeaveErrors(t *testing.T) {
|
||||
{
|
||||
name: "leave-failed",
|
||||
swarmLeaveFunc: func() error {
|
||||
return errors.Errorf("error leaving the swarm")
|
||||
return errors.New("error leaving the swarm")
|
||||
},
|
||||
expectedError: "error leaving the swarm",
|
||||
},
|
||||
|
@ -1,6 +1,7 @@
|
||||
package swarm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
@ -9,7 +10,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"
|
||||
"gotest.tools/v3/golden"
|
||||
)
|
||||
@ -35,7 +35,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) {
|
||||
flagRotate: "true",
|
||||
},
|
||||
swarmInspectFunc: func() (swarm.Swarm, error) {
|
||||
return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
|
||||
return swarm.Swarm{}, errors.New("error inspecting the swarm")
|
||||
},
|
||||
expectedError: "error inspecting the swarm",
|
||||
},
|
||||
@ -58,14 +58,14 @@ func TestSwarmUnlockKeyErrors(t *testing.T) {
|
||||
return *builders.Swarm(builders.Autolock()), nil
|
||||
},
|
||||
swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
|
||||
return errors.Errorf("error updating the swarm")
|
||||
return errors.New("error updating the swarm")
|
||||
},
|
||||
expectedError: "error updating the swarm",
|
||||
},
|
||||
{
|
||||
name: "swarm-get-unlock-key-failed",
|
||||
swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
|
||||
return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key")
|
||||
return types.SwarmUnlockKeyResponse{}, errors.New("error getting unlock key")
|
||||
},
|
||||
expectedError: "error getting unlock key",
|
||||
},
|
||||
@ -88,8 +88,8 @@ func TestSwarmUnlockKeyErrors(t *testing.T) {
|
||||
swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc,
|
||||
}))
|
||||
cmd.SetArgs(tc.args)
|
||||
for key, value := range tc.flags {
|
||||
assert.Check(t, cmd.Flags().Set(key, value))
|
||||
for k, v := range tc.flags {
|
||||
assert.Check(t, cmd.Flags().Set(k, v))
|
||||
}
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetErr(io.Discard)
|
||||
@ -165,8 +165,8 @@ func TestSwarmUnlockKey(t *testing.T) {
|
||||
})
|
||||
cmd := newUnlockKeyCommand(cli)
|
||||
cmd.SetArgs(tc.args)
|
||||
for key, value := range tc.flags {
|
||||
assert.Check(t, cmd.Flags().Set(key, value))
|
||||
for k, v := range tc.flags {
|
||||
assert.Check(t, cmd.Flags().Set(k, v))
|
||||
}
|
||||
assert.NilError(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("unlockkeys-%s.golden", tc.name))
|
||||
|
@ -1,6 +1,7 @@
|
||||
package swarm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -9,7 +10,6 @@ import (
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/system"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
@ -58,7 +58,7 @@ func TestSwarmUnlockErrors(t *testing.T) {
|
||||
}, nil
|
||||
},
|
||||
swarmUnlockFunc: func(req swarm.UnlockRequest) error {
|
||||
return errors.Errorf("error unlocking the swarm")
|
||||
return errors.New("error unlocking the swarm")
|
||||
},
|
||||
expectedError: "error unlocking the swarm",
|
||||
},
|
||||
@ -90,7 +90,7 @@ func TestSwarmUnlock(t *testing.T) {
|
||||
},
|
||||
swarmUnlockFunc: func(req swarm.UnlockRequest) error {
|
||||
if req.UnlockKey != input {
|
||||
return errors.Errorf("Invalid unlock key")
|
||||
return errors.New("invalid unlock key")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
@ -1,6 +1,7 @@
|
||||
package swarm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
@ -10,7 +11,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"
|
||||
"gotest.tools/v3/golden"
|
||||
)
|
||||
@ -36,7 +36,7 @@ func TestSwarmUpdateErrors(t *testing.T) {
|
||||
flagTaskHistoryLimit: "10",
|
||||
},
|
||||
swarmInspectFunc: func() (swarm.Swarm, error) {
|
||||
return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
|
||||
return swarm.Swarm{}, errors.New("error inspecting the swarm")
|
||||
},
|
||||
expectedError: "error inspecting the swarm",
|
||||
},
|
||||
@ -46,7 +46,7 @@ func TestSwarmUpdateErrors(t *testing.T) {
|
||||
flagTaskHistoryLimit: "10",
|
||||
},
|
||||
swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
|
||||
return errors.Errorf("error updating the swarm")
|
||||
return errors.New("error updating the swarm")
|
||||
},
|
||||
expectedError: "error updating the swarm",
|
||||
},
|
||||
@ -59,7 +59,7 @@ func TestSwarmUpdateErrors(t *testing.T) {
|
||||
return *builders.Swarm(), nil
|
||||
},
|
||||
swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
|
||||
return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key")
|
||||
return types.SwarmUnlockKeyResponse{}, errors.New("error getting unlock key")
|
||||
},
|
||||
expectedError: "error getting unlock key",
|
||||
},
|
||||
@ -114,33 +114,33 @@ func TestSwarmUpdate(t *testing.T) {
|
||||
},
|
||||
swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
|
||||
if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 {
|
||||
return errors.Errorf("historyLimit not correctly set")
|
||||
return errors.New("historyLimit not correctly set")
|
||||
}
|
||||
heartbeatDuration, err := time.ParseDuration("10s")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if swarm.Dispatcher.HeartbeatPeriod != heartbeatDuration {
|
||||
return errors.Errorf("heartbeatPeriodLimit not correctly set")
|
||||
return errors.New("heartbeatPeriodLimit not correctly set")
|
||||
}
|
||||
certExpiryDuration, err := time.ParseDuration("20s")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if swarm.CAConfig.NodeCertExpiry != certExpiryDuration {
|
||||
return errors.Errorf("certExpiry not correctly set")
|
||||
return errors.New("certExpiry not correctly set")
|
||||
}
|
||||
if len(swarm.CAConfig.ExternalCAs) != 1 || swarm.CAConfig.ExternalCAs[0].CACert != "trustroot" {
|
||||
return errors.Errorf("externalCA not correctly set")
|
||||
return errors.New("externalCA not correctly set")
|
||||
}
|
||||
if *swarm.Raft.KeepOldSnapshots != 10 {
|
||||
return errors.Errorf("keepOldSnapshots not correctly set")
|
||||
return errors.New("keepOldSnapshots not correctly set")
|
||||
}
|
||||
if swarm.Raft.SnapshotInterval != 100 {
|
||||
return errors.Errorf("snapshotInterval not correctly set")
|
||||
return errors.New("snapshotInterval not correctly set")
|
||||
}
|
||||
if !swarm.EncryptionConfig.AutoLockManagers {
|
||||
return errors.Errorf("autolock not correctly set")
|
||||
return errors.New("autolock not correctly set")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
@ -153,7 +153,7 @@ func TestSwarmUpdate(t *testing.T) {
|
||||
},
|
||||
swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
|
||||
if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 {
|
||||
return errors.Errorf("historyLimit not correctly set")
|
||||
return errors.New("historyLimit not correctly set")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user