MCPcopy Create free account
hub / github.com/docker/cli / TestRollbackWithErrors

Function TestRollbackWithErrors

cli/command/service/rollback_test.go:56–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestRollbackWithErrors(t *testing.T) {
57 testCases := []struct {
58 name string
59 args []string
60 serviceInspectFunc func(ctx context.Context, serviceID string, options client.ServiceInspectOptions) (client.ServiceInspectResult, error)
61 serviceUpdateFunc func(ctx context.Context, serviceID string, options client.ServiceUpdateOptions) (client.ServiceUpdateResult, error)
62 expectedError string
63 }{
64 {
65 name: "not-enough-args",
66 expectedError: "requires 1 argument",
67 },
68 {
69 name: "too-many-args",
70 args: []string{"service-id-1", "service-id-2"},
71 expectedError: "requires 1 argument",
72 },
73 {
74 name: "service-does-not-exists",
75 args: []string{"service-id"},
76 serviceInspectFunc: func(ctx context.Context, serviceID string, options client.ServiceInspectOptions) (client.ServiceInspectResult, error) {
77 return client.ServiceInspectResult{}, fmt.Errorf("no such services: %s", serviceID)
78 },
79 expectedError: "no such services: service-id",
80 },
81 {
82 name: "service-update-failed",
83 args: []string{"service-id"},
84 serviceUpdateFunc: func(ctx context.Context, serviceID string, options client.ServiceUpdateOptions) (client.ServiceUpdateResult, error) {
85 return client.ServiceUpdateResult{}, fmt.Errorf("no such services: %s", serviceID)
86 },
87 expectedError: "no such services: service-id",
88 },
89 }
90
91 for _, tc := range testCases {
92 t.Run(tc.name, func(t *testing.T) {
93 cmd := newRollbackCommand(
94 test.NewFakeCli(&fakeClient{
95 serviceInspectFunc: tc.serviceInspectFunc,
96 serviceUpdateFunc: tc.serviceUpdateFunc,
97 }))
98 cmd.SetArgs(tc.args)
99 assert.NilError(t, cmd.Flags().Set("quiet", "true"))
100 cmd.SetOut(io.Discard)
101 cmd.SetErr(io.Discard)
102 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
103 })
104 }
105}

Callers

nothing calls this directly

Calls 5

newRollbackCommandFunction · 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…