| 17 | ) |
| 18 | |
| 19 | func TestNodePsErrors(t *testing.T) { |
| 20 | testCases := []struct { |
| 21 | args []string |
| 22 | flags map[string]string |
| 23 | infoFunc func() (client.SystemInfoResult, error) |
| 24 | nodeInspectFunc func() (client.NodeInspectResult, error) |
| 25 | taskListFunc func(options client.TaskListOptions) (client.TaskListResult, error) |
| 26 | expectedError string |
| 27 | }{ |
| 28 | { |
| 29 | infoFunc: func() (client.SystemInfoResult, error) { |
| 30 | return client.SystemInfoResult{}, errors.New("error asking for node info") |
| 31 | }, |
| 32 | expectedError: "error asking for node info", |
| 33 | }, |
| 34 | { |
| 35 | args: []string{"nodeID"}, |
| 36 | nodeInspectFunc: func() (client.NodeInspectResult, error) { |
| 37 | return client.NodeInspectResult{}, errors.New("error inspecting the node") |
| 38 | }, |
| 39 | expectedError: "error inspecting the node", |
| 40 | }, |
| 41 | { |
| 42 | args: []string{"nodeID"}, |
| 43 | taskListFunc: func(options client.TaskListOptions) (client.TaskListResult, error) { |
| 44 | return client.TaskListResult{}, errors.New("error returning the task list") |
| 45 | }, |
| 46 | expectedError: "error returning the task list", |
| 47 | }, |
| 48 | } |
| 49 | for _, tc := range testCases { |
| 50 | cli := test.NewFakeCli(&fakeClient{ |
| 51 | infoFunc: tc.infoFunc, |
| 52 | nodeInspectFunc: tc.nodeInspectFunc, |
| 53 | taskListFunc: tc.taskListFunc, |
| 54 | }) |
| 55 | cmd := newPsCommand(cli) |
| 56 | cmd.SetArgs(tc.args) |
| 57 | for key, value := range tc.flags { |
| 58 | assert.Check(t, cmd.Flags().Set(key, value)) |
| 59 | } |
| 60 | cmd.SetOut(io.Discard) |
| 61 | cmd.SetErr(io.Discard) |
| 62 | assert.Error(t, cmd.Execute(), tc.expectedError) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func TestNodePs(t *testing.T) { |
| 67 | testCases := []struct { |