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

Function TestSwarmInitWithExternalCA

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

Source from the content-addressed store, hash-verified

131}
132
133func TestSwarmInitWithExternalCA(t *testing.T) {
134 cli := test.NewFakeCli(&fakeClient{
135 swarmInitFunc: func(options client.SwarmInitOptions) (client.SwarmInitResult, error) {
136 if assert.Check(t, is.Len(options.Spec.CAConfig.ExternalCAs, 1)) {
137 assert.Equal(t, options.Spec.CAConfig.ExternalCAs[0].CACert, cert)
138 assert.Equal(t, options.Spec.CAConfig.ExternalCAs[0].Protocol, swarm.ExternalCAProtocolCFSSL)
139 assert.Equal(t, options.Spec.CAConfig.ExternalCAs[0].URL, "https://example.com")
140 }
141 return client.SwarmInitResult{NodeID: "nodeID"}, nil
142 },
143 })
144
145 tempDir := t.TempDir()
146 certFile := filepath.Join(tempDir, "cert.pem")
147 err := os.WriteFile(certFile, []byte(cert), 0o644)
148 assert.NilError(t, err)
149
150 cmd := newInitCommand(cli)
151 cmd.SetArgs([]string{})
152 cmd.SetOut(io.Discard)
153 cmd.SetErr(io.Discard)
154 assert.NilError(t, cmd.Flags().Set(flagExternalCA, "protocol=cfssl,url=https://example.com,cacert="+certFile))
155 assert.NilError(t, cmd.Execute())
156}

Callers

nothing calls this directly

Calls 6

newInitCommandFunction · 0.85
SetArgsMethod · 0.80
LenMethod · 0.45
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…