Skip to content

Commit

Permalink
Use docker/types for health status, but also check for the zero value.
Browse files Browse the repository at this point in the history
  • Loading branch information
emetsger committed May 7, 2024
1 parent 4fe80cd commit 1b85b7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 0 additions & 5 deletions docker.go
Expand Up @@ -49,11 +49,6 @@ const (
packagePath = "github.com/testcontainers/testcontainers-go"

logStoppedForOutOfSyncMessage = "Stopping log consumer: Headers out of sync"

healthStatusNone = "" // default status for a container with no healthcheck
healthStatusHealthy = "healthy" // healthy container
healthStatusStarting = "starting" // starting container
healthStatusUnhealthy = "unhealthy" // unhealthy container
)

var createContainerFailDueToNameConflictRegex = regexp.MustCompile("Conflict. The container name .* is already in use by container .*")
Expand Down
8 changes: 6 additions & 2 deletions reaper.go
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"fmt"
"github.com/docker/docker/api/types"
"math/rand"
"net"
"strings"
Expand Down Expand Up @@ -117,8 +118,11 @@ func lookUpReaperContainer(ctx context.Context, sessionID string) (*DockerContai
return err
}

if r.healthStatus != healthStatusHealthy && r.healthStatus != healthStatusNone {
return fmt.Errorf("container %s is not healthy, wanted status=%s, got status=%s", resp[0].ID[:8], healthStatusHealthy, r.healthStatus)
// if a health status is present on the container, and the container is not healthy, error
if r.healthStatus != "" {
if r.healthStatus != types.Healthy && r.healthStatus != types.NoHealthcheck {
return fmt.Errorf("container %s is not healthy, wanted status=%s, got status=%s", resp[0].ID[:8], types.Healthy, r.healthStatus)
}
}

reaperContainer = r
Expand Down

0 comments on commit 1b85b7c

Please sign in to comment.