(t *testing.T)
| 258 | } |
| 259 | |
| 260 | func 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) |
nothing calls this directly
no test coverage detected