support a testing postgres URL (#935)

This commit is contained in:
Jim authored and GitHub committed 2021-02-16 20:39:09 -05:00
1 parent bc565922fb
commit 958dba6d7f
1 file changed
+12 -4
+12 -4
View File
@@ -5,6 +5,7 @@ package docker
import (
"database/sql"
"fmt"
"os"
"strings"
"github.com/ory/dockertest/v3"
@@ -27,11 +28,18 @@ func startDbInDockerSupported(dialect string) (cleanup func() error, retURL, con
var url string
switch dialect {
case "postgres":
resource, err = pool.Run("postgres", "11", []string{"POSTGRES_PASSWORD=password", "POSTGRES_DB=boundary"})
url = "postgres://postgres:password@localhost:%s?sslmode=disable"
if err == nil {
url = fmt.Sprintf("postgres://postgres:password@%s/boundary?sslmode=disable", resource.GetHostPort("5432/tcp"))
switch {
case os.Getenv("BOUNDARY_TESTING_PG_URL") != "":
url = os.Getenv("BOUNDARY_TESTING_PG_URL")
return func() error { return nil }, url, "", nil
default:
resource, err = pool.Run("postgres", "11", []string{"POSTGRES_PASSWORD=password", "POSTGRES_DB=boundary"})
url = "postgres://postgres:password@localhost:%s?sslmode=disable"
if err == nil {
url = fmt.Sprintf("postgres://postgres:password@%s/boundary?sslmode=disable", resource.GetHostPort("5432/tcp"))
}
}
default:
panic(fmt.Sprintf("unknown dialect %q", dialect))
}