(t *testing.T)
| 214 | } |
| 215 | |
| 216 | func 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 | |
| 250 | func TestPreStart_ContainerCreateFailurePropagates(t *testing.T) { |
| 251 | tested, apiClient := newPreStartTestService(t) |
nothing calls this directly
no test coverage detected