(t *testing.T)
| 68 | } |
| 69 | |
| 70 | func TestPreStart_SuccessTwoHooksInOrder(t *testing.T) { |
| 71 | tested, apiClient := newPreStartTestService(t) |
| 72 | |
| 73 | project := &types.Project{Name: "demo"} |
| 74 | service := types.ServiceConfig{ |
| 75 | Name: "web", |
| 76 | Image: "alpine", |
| 77 | PreStart: []types.ServiceHook{ |
| 78 | {Image: "alpine", Command: types.ShellCommand{"echo", "first"}}, |
| 79 | {Image: "alpine", Command: types.ShellCommand{"echo", "second"}}, |
| 80 | }, |
| 81 | } |
| 82 | ctr := container.Summary{ID: "service-ctr-id"} |
| 83 | |
| 84 | // Hook 1: create → wait (subscribe) → logs (subscribe) → start. |
| 85 | create1 := apiClient.EXPECT().ContainerCreate(gomock.Any(), gomock.Any()). |
| 86 | Return(client.ContainerCreateResult{ID: "hook-1"}, nil) |
| 87 | wait1 := apiClient.EXPECT().ContainerWait(gomock.Any(), "hook-1", gomock.Any()). |
| 88 | Return(waitResultExit(0)).After(create1) |
| 89 | logs1 := apiClient.EXPECT().ContainerLogs(gomock.Any(), "hook-1", gomock.Any()). |
| 90 | Return(emptyLogs(), nil).After(wait1) |
| 91 | start1 := apiClient.EXPECT().ContainerStart(gomock.Any(), "hook-1", gomock.Any()). |
| 92 | Return(client.ContainerStartResult{}, nil).After(logs1) |
| 93 | |
| 94 | // Hook 2 is only created after hook 1 has been started (and waited on). |
| 95 | create2 := apiClient.EXPECT().ContainerCreate(gomock.Any(), gomock.Any()). |
| 96 | Return(client.ContainerCreateResult{ID: "hook-2"}, nil).After(start1) |
| 97 | wait2 := apiClient.EXPECT().ContainerWait(gomock.Any(), "hook-2", gomock.Any()). |
| 98 | Return(waitResultExit(0)).After(create2) |
| 99 | logs2 := apiClient.EXPECT().ContainerLogs(gomock.Any(), "hook-2", gomock.Any()). |
| 100 | Return(emptyLogs(), nil).After(wait2) |
| 101 | apiClient.EXPECT().ContainerStart(gomock.Any(), "hook-2", gomock.Any()). |
| 102 | Return(client.ContainerStartResult{}, nil).After(logs2) |
| 103 | |
| 104 | err := tested.runPreStart(t.Context(), project, service, ctr, func(api.ContainerEvent) {}) |
| 105 | assert.NilError(t, err) |
| 106 | } |
| 107 | |
| 108 | func TestPreStart_FirstHookFailsStopsExecution(t *testing.T) { |
| 109 | tested, apiClient := newPreStartTestService(t) |
nothing calls this directly
no test coverage detected