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

Function TestInitializeFromClient

cli/command/cli_test.go:158–206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestInitializeFromClient(t *testing.T) {
159 const defaultVersion = "v1.55"
160
161 testcases := []struct {
162 doc string
163 pingFunc func() (client.PingResult, error)
164 expectedServer ServerInfo
165 negotiated bool
166 }{
167 {
168 doc: "successful ping",
169 pingFunc: func() (client.PingResult, error) {
170 return client.PingResult{Experimental: true, OSType: "linux", APIVersion: "v1.44"}, nil
171 },
172 expectedServer: ServerInfo{HasExperimental: true, OSType: "linux"},
173 negotiated: true,
174 },
175 {
176 doc: "failed ping, no API version",
177 pingFunc: func() (client.PingResult, error) {
178 return client.PingResult{}, errors.New("failed")
179 },
180 expectedServer: ServerInfo{HasExperimental: true},
181 },
182 {
183 doc: "failed ping, with API version",
184 pingFunc: func() (client.PingResult, error) {
185 return client.PingResult{APIVersion: "v1.44"}, errors.New("failed")
186 },
187 expectedServer: ServerInfo{HasExperimental: true},
188 negotiated: true,
189 },
190 }
191
192 for _, tc := range testcases {
193 t.Run(tc.doc, func(t *testing.T) {
194 apiClient := &fakeClient{
195 pingFunc: tc.pingFunc,
196 version: defaultVersion,
197 }
198
199 cli := &DockerCli{client: apiClient}
200 err := cli.Initialize(flags.NewClientOptions())
201 assert.NilError(t, err)
202 assert.DeepEqual(t, cli.ServerInfo(), tc.expectedServer)
203 assert.Equal(t, apiClient.negotiated, tc.negotiated)
204 })
205 }
206}
207
208// Makes sure we don't hang forever on the initial connection.
209// https://github.com/docker/cli/issues/3652

Callers

nothing calls this directly

Calls 2

InitializeMethod · 0.95
ServerInfoMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…