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

Function TestCreateFromContext

cli/command/context/create_test.go:164–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestCreateFromContext(t *testing.T) {
165 cases := []struct {
166 name string
167 description string
168 expectedDescription string
169 docker map[string]string
170 }{
171 {
172 name: "no-override",
173 expectedDescription: "original description",
174 },
175 {
176 name: "override-description",
177 description: "new description",
178 expectedDescription: "new description",
179 },
180 }
181
182 cli := makeFakeCli(t)
183 cli.ResetOutputBuffers()
184 assert.NilError(t, runCreate(cli, "original", createOptions{
185 description: "original description",
186 endpoint: map[string]string{
187 keyHost: "tcp://42.42.42.42:2375",
188 },
189 }))
190 assertContextCreateLogging(t, cli, "original")
191
192 cli.ResetOutputBuffers()
193 assert.NilError(t, runCreate(cli, "dummy", createOptions{
194 description: "dummy description",
195 endpoint: map[string]string{
196 keyHost: "tcp://24.24.24.24:2375",
197 },
198 }))
199 assertContextCreateLogging(t, cli, "dummy")
200
201 cli.SetCurrentContext("dummy")
202
203 for _, tc := range cases {
204 t.Run(tc.name, func(t *testing.T) {
205 cli.ResetOutputBuffers()
206 err := runCreate(cli, tc.name, createOptions{
207 from: "original",
208 description: tc.description,
209 endpoint: tc.docker,
210 })
211 assert.NilError(t, err)
212 assertContextCreateLogging(t, cli, tc.name)
213 newContext, err := cli.ContextStore().GetMetadata(tc.name)
214 assert.NilError(t, err)
215 newContextTyped, err := command.GetDockerContext(newContext)
216 assert.NilError(t, err)
217 dockerEndpoint, err := docker.EndpointFromContext(newContext)
218 assert.NilError(t, err)
219 assert.Equal(t, newContextTyped.Description, tc.expectedDescription)
220 assert.Equal(t, dockerEndpoint.Host, "tcp://42.42.42.42:2375")
221 })

Callers

nothing calls this directly

Calls 7

makeFakeCliFunction · 0.85
SetCurrentContextMethod · 0.80
runCreateFunction · 0.70
GetMetadataMethod · 0.65
ContextStoreMethod · 0.65
ResetOutputBuffersMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…