MCPcopy Index your code
hub / github.com/docker/cli / TestSwarmUnlockKeyErrors

Function TestSwarmUnlockKeyErrors

cli/command/swarm/unlock_key_test.go:16–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestSwarmUnlockKeyErrors(t *testing.T) {
17 testCases := []struct {
18 name string
19 args []string
20 flags map[string]string
21 swarmInspectFunc func() (client.SwarmInspectResult, error)
22 swarmUpdateFunc func(client.SwarmUpdateOptions) (client.SwarmUpdateResult, error)
23 swarmGetUnlockKeyFunc func() (client.SwarmGetUnlockKeyResult, error)
24 expectedError string
25 }{
26 {
27 name: "too-many-args",
28 args: []string{"foo"},
29 expectedError: "accepts no arguments",
30 },
31 {
32 name: "swarm-inspect-rotate-failed",
33 flags: map[string]string{
34 flagRotate: "true",
35 },
36 swarmInspectFunc: func() (client.SwarmInspectResult, error) {
37 return client.SwarmInspectResult{}, errors.New("error inspecting the swarm")
38 },
39 expectedError: "error inspecting the swarm",
40 },
41 {
42 name: "swarm-rotate-no-autolock-failed",
43 flags: map[string]string{
44 flagRotate: "true",
45 },
46 swarmInspectFunc: func() (client.SwarmInspectResult, error) {
47 return client.SwarmInspectResult{
48 Swarm: *builders.Swarm(),
49 }, nil
50 },
51 expectedError: "cannot rotate because autolock is not turned on",
52 },
53 {
54 name: "swarm-update-failed",
55 flags: map[string]string{
56 flagRotate: "true",
57 },
58 swarmInspectFunc: func() (client.SwarmInspectResult, error) {
59 return client.SwarmInspectResult{
60 Swarm: *builders.Swarm(builders.Autolock()),
61 }, nil
62 },
63 swarmUpdateFunc: func(client.SwarmUpdateOptions) (client.SwarmUpdateResult, error) {
64 return client.SwarmUpdateResult{}, errors.New("error updating the swarm")
65 },
66 expectedError: "error updating the swarm",
67 },
68 {
69 name: "swarm-get-unlock-key-failed",
70 swarmGetUnlockKeyFunc: func() (client.SwarmGetUnlockKeyResult, error) {
71 return client.SwarmGetUnlockKeyResult{}, errors.New("error getting unlock key")
72 },
73 expectedError: "error getting unlock key",

Callers

nothing calls this directly

Calls 5

newUnlockKeyCommandFunction · 0.85
SetArgsMethod · 0.80
SetOutMethod · 0.45
SetErrMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…