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

Function TestIsServiceHealthy

pkg/compose/convergence_test.go:260–400  ·  pkg/compose/convergence_test.go::TestIsServiceHealthy
(t *testing.T)

Source from the content-addressed store, hash-verified

258}
259
260func TestIsServiceHealthy(t *testing.T) {
261 mockCtrl := gomock.NewController(t)
262 defer mockCtrl.Finish()
263
264 apiClient := mocks.NewMockAPIClient(mockCtrl)
265 cli := mocks.NewMockCli(mockCtrl)
266 tested, err := NewComposeService(cli)
267 assert.NilError(t, err)
268 cli.EXPECT().Client().Return(apiClient).AnyTimes()
269
270 ctx := t.Context()
271
272 t.Run("disabled healthcheck with fallback to running", func(t *testing.T) {
273 containerID := "test-container-id"
274 containers := Containers{
275 {ID: containerID},
276 }
277
278 // Container with disabled healthcheck (Test: ["NONE"])
279 apiClient.EXPECT().ContainerInspect(ctx, containerID, gomock.Any()).Return(client.ContainerInspectResult{
280 Container: container.InspectResponse{
281 ID: containerID,
282 Name: "test-container",
283 State: &container.State{Status: "running"},
284 Config: &container.Config{
285 Healthcheck: &container.HealthConfig{
286 Test: []string{"NONE"},
287 },
288 },
289 },
290 }, nil)
291
292 isHealthy, err := tested.(*composeService).isServiceHealthy(ctx, containers, true)
293 assert.NilError(t, err)
294 assert.Equal(t, true, isHealthy, "Container with disabled healthcheck should be considered healthy when running with fallbackRunning=true")
295 })
296
297 t.Run("disabled healthcheck without fallback", func(t *testing.T) {
298 containerID := "test-container-id"
299 containers := Containers{
300 {ID: containerID},
301 }
302
303 // Container with disabled healthcheck (Test: ["NONE"]) but fallbackRunning=false
304 apiClient.EXPECT().ContainerInspect(ctx, containerID, gomock.Any()).Return(client.ContainerInspectResult{
305 Container: container.InspectResponse{
306 ID: containerID,
307 Name: "test-container",
308 State: &container.State{Status: "running"},
309 Config: &container.Config{
310 Healthcheck: &container.HealthConfig{
311 Test: []string{"NONE"},
312 },
313 },
314 },
315 }, nil)
316
317 _, err := tested.(*composeService).isServiceHealthy(ctx, containers, false)

Callers

nothing calls this directly

Calls 8

EXPECTMethod · 0.95
EXPECTMethod · 0.95
NewMockAPIClientFunction · 0.92
NewMockCliFunction · 0.92
NewComposeServiceFunction · 0.85
isServiceHealthyMethod · 0.80
ClientMethod · 0.45
ContainerInspectMethod · 0.45

Tested by

no test coverage detected