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

Function TestSwarmUpdateErrors

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

Source from the content-addressed store, hash-verified

15)
16
17func TestSwarmUpdateErrors(t *testing.T) {
18 testCases := []struct {
19 name string
20 args []string
21 flags map[string]string
22 swarmInspectFunc func() (client.SwarmInspectResult, error)
23 swarmUpdateFunc func(client.SwarmUpdateOptions) (client.SwarmUpdateResult, error)
24 swarmGetUnlockKeyFunc func() (client.SwarmGetUnlockKeyResult, error)
25 expectedError string
26 }{
27 {
28 name: "too-many-args",
29 args: []string{"foo"},
30 expectedError: "accepts no arguments",
31 },
32 {
33 name: "swarm-inspect-error",
34 flags: map[string]string{
35 flagTaskHistoryLimit: "10",
36 },
37 swarmInspectFunc: func() (client.SwarmInspectResult, error) {
38 return client.SwarmInspectResult{}, errors.New("error inspecting the swarm")
39 },
40 expectedError: "error inspecting the swarm",
41 },
42 {
43 name: "swarm-update-error",
44 flags: map[string]string{
45 flagTaskHistoryLimit: "10",
46 },
47 swarmUpdateFunc: func(client.SwarmUpdateOptions) (client.SwarmUpdateResult, error) {
48 return client.SwarmUpdateResult{}, errors.New("error updating the swarm")
49 },
50 expectedError: "error updating the swarm",
51 },
52 {
53 name: "swarm-unlock-key-error",
54 flags: map[string]string{
55 flagAutolock: "true",
56 },
57 swarmInspectFunc: func() (client.SwarmInspectResult, error) {
58 return client.SwarmInspectResult{
59 Swarm: *builders.Swarm(),
60 }, nil
61 },
62 swarmGetUnlockKeyFunc: func() (client.SwarmGetUnlockKeyResult, error) {
63 return client.SwarmGetUnlockKeyResult{}, errors.New("error getting unlock key")
64 },
65 expectedError: "error getting unlock key",
66 },
67 }
68 for _, tc := range testCases {
69 t.Run(tc.name, func(t *testing.T) {
70 cmd := newUpdateCommand(
71 test.NewFakeCli(&fakeClient{
72 swarmInspectFunc: tc.swarmInspectFunc,
73 swarmUpdateFunc: tc.swarmUpdateFunc,
74 swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc,

Callers

nothing calls this directly

Calls 5

SetArgsMethod · 0.80
newUpdateCommandFunction · 0.70
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…