Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Make sure db is accepting connections in container for itests #71

Merged
merged 1 commit into from
May 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pkg/internal/testhelpers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/docker/go-connections/nat"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
_ "github.com/jackc/pgx/v4/stdlib"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"os"
"path/filepath"
"testing"
)

const (
Expand Down Expand Up @@ -104,7 +105,9 @@ func StartPGContainer(ctx context.Context, withExtension bool, testDataDir strin
req := testcontainers.ContainerRequest{
Image: image,
ExposedPorts: []string{string(containerPort)},
WaitingFor: wait.NewHostPortStrategy(containerPort),
WaitingFor: wait.ForSQL(containerPort, "pgx", func(port nat.Port) string {
return "dbname=postgres password=password user=postgres host=127.0.0.1 port=" + port.Port()
}),
Env: map[string]string{
"POSTGRES_PASSWORD": "password",
},
Expand Down Expand Up @@ -154,7 +157,7 @@ func StartPromContainer(storagePath string, ctx context.Context) (testcontainers
req := testcontainers.ContainerRequest{
Image: "prom/prometheus",
ExposedPorts: []string{string(prometheusPort)},
WaitingFor: wait.NewHostPortStrategy(prometheusPort),
WaitingFor: wait.ForListeningPort(prometheusPort),
BindMounts: map[string]string{
storagePath: "/prometheus",
},
Expand Down