(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestSwarmInit(t *testing.T) { |
| 89 | testCases := []struct { |
| 90 | name string |
| 91 | flags map[string]string |
| 92 | swarmInitFunc func(client.SwarmInitOptions) (client.SwarmInitResult, error) |
| 93 | swarmGetUnlockKeyFunc func() (client.SwarmGetUnlockKeyResult, error) |
| 94 | }{ |
| 95 | { |
| 96 | name: "init", |
| 97 | swarmInitFunc: func(client.SwarmInitOptions) (client.SwarmInitResult, error) { |
| 98 | return client.SwarmInitResult{NodeID: "nodeID"}, nil |
| 99 | }, |
| 100 | }, |
| 101 | { |
| 102 | name: "init-auto-lock", |
| 103 | flags: map[string]string{ |
| 104 | flagAutolock: "true", |
| 105 | }, |
| 106 | swarmInitFunc: func(client.SwarmInitOptions) (client.SwarmInitResult, error) { |
| 107 | return client.SwarmInitResult{NodeID: "nodeID"}, nil |
| 108 | }, |
| 109 | swarmGetUnlockKeyFunc: func() (client.SwarmGetUnlockKeyResult, error) { |
| 110 | return client.SwarmGetUnlockKeyResult{Key: "unlock-key"}, nil |
| 111 | }, |
| 112 | }, |
| 113 | } |
| 114 | for _, tc := range testCases { |
| 115 | t.Run(tc.name, func(t *testing.T) { |
| 116 | cli := test.NewFakeCli(&fakeClient{ |
| 117 | swarmInitFunc: tc.swarmInitFunc, |
| 118 | swarmGetUnlockKeyFunc: tc.swarmGetUnlockKeyFunc, |
| 119 | }) |
| 120 | cmd := newInitCommand(cli) |
| 121 | cmd.SetArgs([]string{}) |
| 122 | cmd.SetOut(io.Discard) |
| 123 | cmd.SetErr(io.Discard) |
| 124 | for k, v := range tc.flags { |
| 125 | assert.Check(t, cmd.Flags().Set(k, v)) |
| 126 | } |
| 127 | assert.NilError(t, cmd.Execute()) |
| 128 | golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("init-%s.golden", tc.name)) |
| 129 | }) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | func TestSwarmInitWithExternalCA(t *testing.T) { |
| 134 | cli := test.NewFakeCli(&fakeClient{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…