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

Function TestNodeDemoteErrors

cli/command/node/demote_test.go:15–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestNodeDemoteErrors(t *testing.T) {
16 testCases := []struct {
17 args []string
18 nodeInspectFunc func() (client.NodeInspectResult, error)
19 nodeUpdateFunc func(nodeID string, options client.NodeUpdateOptions) (client.NodeUpdateResult, error)
20 expectedError string
21 }{
22 {
23 expectedError: "requires at least 1 argument",
24 },
25 {
26 args: []string{"nodeID"},
27 nodeInspectFunc: func() (client.NodeInspectResult, error) {
28 return client.NodeInspectResult{}, errors.New("error inspecting the node")
29 },
30 expectedError: "error inspecting the node",
31 },
32 {
33 args: []string{"nodeID"},
34 nodeUpdateFunc: func(nodeID string, options client.NodeUpdateOptions) (client.NodeUpdateResult, error) {
35 return client.NodeUpdateResult{}, errors.New("error updating the node")
36 },
37 expectedError: "error updating the node",
38 },
39 }
40 for _, tc := range testCases {
41 cmd := newDemoteCommand(
42 test.NewFakeCli(&fakeClient{
43 nodeInspectFunc: tc.nodeInspectFunc,
44 nodeUpdateFunc: tc.nodeUpdateFunc,
45 }))
46 cmd.SetArgs(tc.args)
47 cmd.SetOut(io.Discard)
48 cmd.SetErr(io.Discard)
49 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
50 }
51}
52
53func TestNodeDemoteNoChange(t *testing.T) {
54 cmd := newDemoteCommand(

Callers

nothing calls this directly

Calls 4

newDemoteCommandFunction · 0.85
SetArgsMethod · 0.80
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…