MCPcopy Create free account
hub / github.com/docker/cli / TestSwarmUnlockErrors

Function TestSwarmUnlockErrors

cli/command/swarm/unlock_test.go:17–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestSwarmUnlockErrors(t *testing.T) {
18 testCases := []struct {
19 name string
20 args []string
21 swarmUnlockFunc func(client.SwarmUnlockOptions) (client.SwarmUnlockResult, error)
22 infoFunc func() (system.Info, error)
23 expectedError string
24 }{
25 {
26 name: "too-many-args",
27 args: []string{"foo"},
28 expectedError: "accepts no arguments",
29 },
30 {
31 name: "is-not-part-of-a-swarm",
32 infoFunc: func() (system.Info, error) {
33 return system.Info{
34 Swarm: swarm.Info{
35 LocalNodeState: swarm.LocalNodeStateInactive,
36 },
37 }, nil
38 },
39 expectedError: "this node is not part of a swarm",
40 },
41 {
42 name: "is-not-locked",
43 infoFunc: func() (system.Info, error) {
44 return system.Info{
45 Swarm: swarm.Info{
46 LocalNodeState: swarm.LocalNodeStateActive,
47 },
48 }, nil
49 },
50 expectedError: "error: swarm is not locked",
51 },
52 {
53 name: "unlockrequest-failed",
54 infoFunc: func() (system.Info, error) {
55 return system.Info{
56 Swarm: swarm.Info{
57 LocalNodeState: swarm.LocalNodeStateLocked,
58 },
59 }, nil
60 },
61 swarmUnlockFunc: func(client.SwarmUnlockOptions) (client.SwarmUnlockResult, error) {
62 return client.SwarmUnlockResult{}, errors.New("error unlocking the swarm")
63 },
64 expectedError: "error unlocking the swarm",
65 },
66 }
67 for _, tc := range testCases {
68 t.Run(tc.name, func(t *testing.T) {
69 cmd := newUnlockCommand(
70 test.NewFakeCli(&fakeClient{
71 infoFunc: tc.infoFunc,
72 swarmUnlockFunc: tc.swarmUnlockFunc,
73 }))
74 if tc.args == nil {

Callers

nothing calls this directly

Calls 4

newUnlockCommandFunction · 0.85
SetArgsMethod · 0.80
SetOutMethod · 0.45
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…