(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func 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, |
nothing calls this directly
no test coverage detected
searching dependent graphs…