Repository: moby/moby
File: integration/container/list_test.go (Go)

Code before:
	if assert.Check(t, ctr.ImageManifestDescriptor != nil && ctr.ImageManifestDescriptor.Platform != nil) {
		// Check that at least OS and Architecture have a value. Other values
		// depend on the platform on which we're running the test.
		assert.Equal(t, ctr.ImageManifestDescriptor.Platform.OS, testEnv.DaemonInfo.OSType)
		assert.Check(t, ctr.ImageManifestDescriptor.Platform.Architecture != "")
	}
}

func pollForHealthStatusSummary(ctx context.Context, client client.APIClient, containerID string, healthStatus containertypes.HealthStatus) func(log poll.LogT) poll.Result {
	return func(log poll.LogT) poll.Result {
		containers, err := client.ContainerList(ctx, containertypes.ListOptions{
			All:     true,
			Filters: filters.NewArgs(filters.Arg("id", containerID)),
		})
		if err != nil {
			return poll.Error(err)
		}
		total := 0
		version := client.ClientVersion()
		if err != nil {
			return poll.Error(err)
		}
		for _, container := range containers {
			if (container.Health == nil && versions.LessThan(version, "1.51")) {
				total++
			} else if container.Health != nil && container.Health.Status == healthStatus && versions.GreaterThanOrEqualTo(version, "1.51"){
				total++
			}
		}

		if total == len(containers) {
			return poll.Success()
		}

		return poll.Continue("waiting for container to become %s", healthStatus)
	}
}

func TestContainerList_HealthSummary(t *testing.T) {
	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
	ctx := setupTest(t)
	testcases := []struct {
		apiVersion string
	}{
		{apiVersion: "1.50"},
		{apiVersion: "1.51"},
	}

	for _, tc := range testcases {
		t.Run(fmt.Sprintf("run with version v%s", tc.apiVersion), func(t *testing.T) {
			apiClient := request.NewAPIClient(t, client.WithVersion(tc.apiVersion))

Review comment (bug):
Linter failure (https://github.com/moby/moby/actions/runs/16223267852/job/45939842246?pr=50281#step:6:71)

```
integration/container/list_test.go:166:1: File is not properly formatted (gofmt)
			if (container.Health == nil && versions.LessThan(version, "1.51")) {
^
integration/container/list_test.go:162:10: nilness: impossible condition: nil != nil (govet)
		if err != nil {
		       ^
```

Code after:
	if assert.Check(t, ctr.ImageManifestDescriptor != nil && ctr.ImageManifestDescriptor.Platform != nil) {
		// Check that at least OS and Architecture have a value. Other values
		// depend on the platform on which we're running the test.
		assert.Equal(t, ctr.ImageManifestDescriptor.Platform.OS, testEnv.DaemonInfo.OSType)
		assert.Check(t, ctr.ImageManifestDescriptor.Platform.Architecture != "")
	}
}

func pollForHealthStatusSummary(ctx context.Context, client client.APIClient, containerID string, healthStatus containertypes.HealthStatus) func(log poll.LogT) poll.Result {
	return func(log poll.LogT) poll.Result {
		containers, err := client.ContainerList(ctx, containertypes.ListOptions{
			All:     true,
			Filters: filters.NewArgs(filters.Arg("id", containerID)),
		})
		if err != nil {
			return poll.Error(err)
		}
		total := 0
		version := client.ClientVersion()
		for _, ctr := range containers {
			if ctr.Health == nil && versions.LessThan(version, "1.52") {
				total++
			} else if ctr.Health != nil && ctr.Health.Status == healthStatus && versions.GreaterThanOrEqualTo(version, "1.52") {
				total++
			}
		}

		if total == len(containers) {
			return poll.Success()
		}

		return poll.Continue("waiting for container to become %s", healthStatus)
	}
}

func TestContainerList_HealthSummary(t *testing.T) {
	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
	ctx := setupTest(t)
	testcases := []struct {
		apiVersion string
	}{
		{apiVersion: "1.51"},
		{apiVersion: "1.52"},
	}

	for _, tc := range testcases {
		t.Run(fmt.Sprintf("run with version v%s", tc.apiVersion), func(t *testing.T) {
			apiClient := request.NewAPIClient(t, client.WithVersion(tc.apiVersion))

			cID := container.Run(ctx, t, apiClient, container.WithTty(true), container.WithWorkingDir("/foo"), func(c *container.TestContainerConfig) {
				c.Config.Healthcheck = &containertypes.HealthConfig{