(t *testing.T)
| 162 | } |
| 163 | |
| 164 | func 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 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…