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

Function TestPreStart_FirstHookFailsStopsExecution

pkg/compose/pre_start_test.go:108–134  ·  pkg/compose/pre_start_test.go::TestPreStart_FirstHookFailsStopsExecution
(t *testing.T)

Source from the content-addressed store, hash-verified

106}
107
108func 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
136func TestPreStart_PerReplicaRejected(t *testing.T) {
137 tested, _ := newPreStartTestService(t)

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected