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

Function TestStackServicesErrors

cli/command/stack/services_test.go:19–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func 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
64func TestRunServicesWithEmptyName(t *testing.T) {
65 cmd := newServicesCommand(test.NewFakeCli(&fakeClient{}))

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…