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

Function TestSwarmInit

cli/command/swarm/init_test.go:88–131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func 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
133func TestSwarmInitWithExternalCA(t *testing.T) {
134 cli := test.NewFakeCli(&fakeClient{

Callers

nothing calls this directly

Calls 7

OutBufferMethod · 0.95
newInitCommandFunction · 0.85
SetArgsMethod · 0.80
StringMethod · 0.65
SetOutMethod · 0.45
SetErrMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…