Skip to content

Commit

Permalink
fix(ryul): test by overriding reaper endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
romainlaurent committed Oct 3, 2024
1 parent 937f3b5 commit 61e3e59
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/rand"
"net"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -197,7 +198,7 @@ func reuseOrCreateReaper(ctx context.Context, sessionID string, provider ReaperP
// reuseReaperContainer constructs a Reaper from an already running reaper
// DockerContainer.
func reuseReaperContainer(ctx context.Context, sessionID string, provider ReaperProvider, reaperContainer *DockerContainer) (*Reaper, error) {
endpoint, err := reaperContainer.PortEndpoint(ctx, "8080", "")
endpoint, err := reaperEndpoint(ctx, reaperContainer)
if err != nil {
return nil, err
}
Expand All @@ -218,6 +219,14 @@ func reuseReaperContainer(ctx context.Context, sessionID string, provider Reaper
}, nil
}

func reaperEndpoint(ctx context.Context, c Container) (string, error) {
if _, exists := os.LookupEnv("TESTCONTAINERS_RYUK_ENDPOINT_OVERRIDE_BY_NAME"); exists {
return net.JoinHostPort(reaperContainerNameFromSessionID(c.SessionID()), "8080"), nil
}

return c.PortEndpoint(ctx, "8080", "")
}

// newReaper creates a Reaper with a sessionID to identify containers and a
// provider to use. Do not call this directly, use reuseOrCreateReaper instead.
func newReaper(ctx context.Context, sessionID string, provider ReaperProvider) (*Reaper, error) {
Expand Down Expand Up @@ -313,7 +322,7 @@ func newReaper(ctx context.Context, sessionID string, provider ReaperProvider) (
}
reaper.container = c

endpoint, err := c.PortEndpoint(ctx, "8080", "")
endpoint, err := reaperEndpoint(ctx, c)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 61e3e59

Please sign in to comment.