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

Function TestSwarmJoinErrors

cli/command/swarm/join_test.go:17–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestSwarmJoinErrors(t *testing.T) {
18 testCases := []struct {
19 name string
20 args []string
21 swarmJoinFunc func() (client.SwarmJoinResult, error)
22 infoFunc func() (system.Info, error)
23 expectedError string
24 }{
25 {
26 name: "not-enough-args",
27 args: []string{},
28 expectedError: "requires 1 argument",
29 },
30 {
31 name: "too-many-args",
32 args: []string{"remote1", "remote2"},
33 expectedError: "requires 1 argument",
34 },
35 {
36 name: "join-failed",
37 args: []string{"remote"},
38 swarmJoinFunc: func() (client.SwarmJoinResult, error) {
39 return client.SwarmJoinResult{}, errors.New("error joining the swarm")
40 },
41 expectedError: "error joining the swarm",
42 },
43 {
44 name: "join-failed-on-init",
45 args: []string{"remote"},
46 infoFunc: func() (system.Info, error) {
47 return system.Info{}, errors.New("error asking for node info")
48 },
49 expectedError: "error asking for node info",
50 },
51 }
52 for _, tc := range testCases {
53 t.Run(tc.name, func(t *testing.T) {
54 cmd := newJoinCommand(
55 test.NewFakeCli(&fakeClient{
56 swarmJoinFunc: tc.swarmJoinFunc,
57 infoFunc: tc.infoFunc,
58 }))
59 cmd.SetArgs(tc.args)
60 cmd.SetOut(io.Discard)
61 cmd.SetErr(io.Discard)
62 assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
63 })
64 }
65}
66
67func TestSwarmJoin(t *testing.T) {
68 testCases := []struct {

Callers

nothing calls this directly

Calls 4

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