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

Function TestPreStart_SuccessTwoHooksInOrder

pkg/compose/pre_start_test.go:70–106  ·  pkg/compose/pre_start_test.go::TestPreStart_SuccessTwoHooksInOrder
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func 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
108func TestPreStart_FirstHookFailsStopsExecution(t *testing.T) {
109 tested, apiClient := 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