(t *testing.T)
| 106 | } |
| 107 | |
| 108 | func TestPreStart_FirstHookFailsStopsExecution(t *testing.T) { |
| 109 | tested, apiClient := newPreStartTestService(t) |
| 110 | |
| 111 | project := &types.Project{Name: "demo"} |
| 112 | service := types.ServiceConfig{ |
| 113 | Name: "web", |
| 114 | Image: "alpine", |
| 115 | PreStart: []types.ServiceHook{ |
| 116 | {Image: "alpine", Command: types.ShellCommand{"false"}}, |
| 117 | {Image: "alpine", Command: types.ShellCommand{"echo", "never"}}, |
| 118 | }, |
| 119 | } |
| 120 | ctr := container.Summary{ID: "service-ctr-id"} |
| 121 | |
| 122 | create1 := apiClient.EXPECT().ContainerCreate(gomock.Any(), gomock.Any()). |
| 123 | Return(client.ContainerCreateResult{ID: "hook-1"}, nil) |
| 124 | wait1 := apiClient.EXPECT().ContainerWait(gomock.Any(), "hook-1", gomock.Any()). |
| 125 | Return(waitResultExit(42)).After(create1) |
| 126 | logs1 := apiClient.EXPECT().ContainerLogs(gomock.Any(), "hook-1", gomock.Any()). |
| 127 | Return(emptyLogs(), nil).After(wait1) |
| 128 | apiClient.EXPECT().ContainerStart(gomock.Any(), "hook-1", gomock.Any()). |
| 129 | Return(client.ContainerStartResult{}, nil).After(logs1) |
| 130 | |
| 131 | err := tested.runPreStart(t.Context(), project, service, ctr, func(api.ContainerEvent) {}) |
| 132 | assert.ErrorContains(t, err, `service "web" pre_start[0]`) |
| 133 | assert.ErrorContains(t, err, "42") |
| 134 | } |
| 135 | |
| 136 | func TestPreStart_PerReplicaRejected(t *testing.T) { |
| 137 | tested, _ := newPreStartTestService(t) |
nothing calls this directly
no test coverage detected