(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func 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 | |
| 67 | func TestSwarmJoin(t *testing.T) { |
| 68 | testCases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…