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

Function TestPreStart_ExplicitHookImageUsed

pkg/compose/pre_start_test.go:185–214  ·  pkg/compose/pre_start_test.go::TestPreStart_ExplicitHookImageUsed
(t *testing.T)

Source from the content-addressed store, hash-verified

183}
184
185func TestPreStart_ExplicitHookImageUsed(t *testing.T) {
186 tested, apiClient := newPreStartTestService(t)
187
188 project := &types.Project{Name: "demo"}
189 service := types.ServiceConfig{
190 Name: "web",
191 Image: "service-image:latest",
192 PreStart: []types.ServiceHook{
193 {Image: "custom-hook-image:1.2.3", Command: types.ShellCommand{"echo"}},
194 },
195 }
196 ctr := container.Summary{ID: "service-ctr-id"}
197
198 var gotImage string
199 apiClient.EXPECT().ContainerCreate(gomock.Any(), gomock.Any()).
200 DoAndReturn(func(_ any, opts client.ContainerCreateOptions) (client.ContainerCreateResult, error) {
201 gotImage = opts.Config.Image
202 return client.ContainerCreateResult{ID: "hook-1"}, nil
203 })
204 apiClient.EXPECT().ContainerStart(gomock.Any(), "hook-1", gomock.Any()).
205 Return(client.ContainerStartResult{}, nil)
206 apiClient.EXPECT().ContainerLogs(gomock.Any(), "hook-1", gomock.Any()).
207 Return(emptyLogs(), nil)
208 apiClient.EXPECT().ContainerWait(gomock.Any(), "hook-1", gomock.Any()).
209 Return(waitResultExit(0))
210
211 err := tested.runPreStart(t.Context(), project, service, ctr, func(api.ContainerEvent) {})
212 assert.NilError(t, err)
213 assert.Equal(t, gotImage, "custom-hook-image:1.2.3")
214}
215
216func TestPreStart_VolumesFromServiceContainer(t *testing.T) {
217 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