MCPcopy
hub / github.com/docker/compose / TestPreStart_VolumesFromServiceContainer

Function TestPreStart_VolumesFromServiceContainer

pkg/compose/pre_start_test.go:216–248  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

214}
215
216func TestPreStart_VolumesFromServiceContainer(t *testing.T) {
217 tested, apiClient := newPreStartTestService(t)
218
219 project := &types.Project{Name: "demo"}
220 service := types.ServiceConfig{
221 Name: "web",
222 Image: "alpine",
223 PreStart: []types.ServiceHook{
224 {Image: "alpine", Command: types.ShellCommand{"true"}},
225 },
226 }
227 ctr := container.Summary{ID: "service-ctr-id"}
228
229 var gotVolumesFrom []string
230 var gotAutoRemove bool
231 apiClient.EXPECT().ContainerCreate(gomock.Any(), gomock.Any()).
232 DoAndReturn(func(_ any, opts client.ContainerCreateOptions) (client.ContainerCreateResult, error) {
233 gotVolumesFrom = opts.HostConfig.VolumesFrom
234 gotAutoRemove = opts.HostConfig.AutoRemove
235 return client.ContainerCreateResult{ID: "hook-1"}, nil
236 })
237 apiClient.EXPECT().ContainerStart(gomock.Any(), "hook-1", gomock.Any()).
238 Return(client.ContainerStartResult{}, nil)
239 apiClient.EXPECT().ContainerLogs(gomock.Any(), "hook-1", gomock.Any()).
240 Return(emptyLogs(), nil)
241 apiClient.EXPECT().ContainerWait(gomock.Any(), "hook-1", gomock.Any()).
242 Return(waitResultExit(0))
243
244 err := tested.runPreStart(t.Context(), project, service, ctr, func(api.ContainerEvent) {})
245 assert.NilError(t, err)
246 assert.DeepEqual(t, gotVolumesFrom, []string{"service-ctr-id"})
247 assert.Assert(t, gotAutoRemove)
248}
249
250func TestPreStart_ContainerCreateFailurePropagates(t *testing.T) {
251 tested, apiClient := newPreStartTestService(t)

Callers

nothing calls this directly

Calls 9

newPreStartTestServiceFunction · 0.85
emptyLogsFunction · 0.85
waitResultExitFunction · 0.85
runPreStartMethod · 0.80
ContainerCreateMethod · 0.45
EXPECTMethod · 0.45
ContainerStartMethod · 0.45
ContainerLogsMethod · 0.45
ContainerWaitMethod · 0.45

Tested by

no test coverage detected