(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestStackServicesErrors(t *testing.T) { |
| 20 | testCases := []struct { |
| 21 | args []string |
| 22 | flags map[string]string |
| 23 | serviceListFunc func(options client.ServiceListOptions) (client.ServiceListResult, error) |
| 24 | expectedError string |
| 25 | }{ |
| 26 | { |
| 27 | args: []string{"foo"}, |
| 28 | serviceListFunc: func(options client.ServiceListOptions) (client.ServiceListResult, error) { |
| 29 | return client.ServiceListResult{}, errors.New("error getting services") |
| 30 | }, |
| 31 | expectedError: "error getting services", |
| 32 | }, |
| 33 | { |
| 34 | args: []string{"foo"}, |
| 35 | flags: map[string]string{ |
| 36 | "format": "{{invalid format}}", |
| 37 | }, |
| 38 | serviceListFunc: func(options client.ServiceListOptions) (client.ServiceListResult, error) { |
| 39 | return client.ServiceListResult{ |
| 40 | Items: []swarm.Service{*builders.Service()}, |
| 41 | }, nil |
| 42 | }, |
| 43 | expectedError: "template parsing error", |
| 44 | }, |
| 45 | } |
| 46 | |
| 47 | for _, tc := range testCases { |
| 48 | t.Run(tc.expectedError, func(t *testing.T) { |
| 49 | cli := test.NewFakeCli(&fakeClient{ |
| 50 | serviceListFunc: tc.serviceListFunc, |
| 51 | }) |
| 52 | cmd := newServicesCommand(cli) |
| 53 | cmd.SetArgs(tc.args) |
| 54 | for key, value := range tc.flags { |
| 55 | assert.Check(t, cmd.Flags().Set(key, value)) |
| 56 | } |
| 57 | cmd.SetOut(io.Discard) |
| 58 | cmd.SetErr(io.Discard) |
| 59 | assert.ErrorContains(t, cmd.Execute(), tc.expectedError) |
| 60 | }) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestRunServicesWithEmptyName(t *testing.T) { |
| 65 | cmd := newServicesCommand(test.NewFakeCli(&fakeClient{})) |
nothing calls this directly
no test coverage detected
searching dependent graphs…