Skip to content

Commit

Permalink
Adding GetEndpointFromPort to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhuie19 committed Sep 6, 2024
1 parent 5e0b15b commit c7e6160
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/docker/test_env/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ func GetHost(ctx context.Context, container tc.Container) (string, error) {
return host, nil
}

// GetEndpointFromPort returns the endpoint of a container associated with a port,
// if localhost then force ipv4 localhost
// to avoid ipv6 docker bugs https://github.com/moby/moby/issues/42442 https://github.com/moby/moby/issues/42375
func GetEndpointFromPort(ctx context.Context, container tc.Container, endpointType string, portStr string) (string, error) {
port, err := nat.NewPort("tcp", portStr)
if err != nil {
return "", err
}
endpoint, err := container.PortEndpoint(ctx, port, endpointType)
if err != nil {
return "", err
}
return strings.Replace(endpoint, "localhost", "127.0.0.1", 1), nil
}

// GetEndpoint returns the endpoint of a container, if localhost then force ipv4 localhost
// to avoid ipv6 docker bugs https://github.com/moby/moby/issues/42442 https://github.com/moby/moby/issues/42375
func GetEndpoint(ctx context.Context, container tc.Container, endpointType string) (string, error) {
Expand Down

0 comments on commit c7e6160

Please sign in to comment.