Skip to content

Commit

Permalink
POSTGRES_PASSWORD is now required when using postgres via docker
Browse files Browse the repository at this point in the history
  • Loading branch information
dhui committed Feb 16, 2020
1 parent 9dcc6f0 commit d9d6d85
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions database/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ import (
_ "github.com/golang-migrate/migrate/v4/source/file"
)

const (
pgPassword = "postgres"
)

var (
opts = dktest.Options{PortRequired: true, ReadyFunc: isReady}
opts = dktest.Options{
Env: map[string]string{"POSTGRES_PASSWORD": pgPassword},
PortRequired: true, ReadyFunc: isReady}
// Supported versions: https://www.postgresql.org/support/versioning/
specs = []dktesting.ContainerSpec{
{ImageName: "postgres:9.5", Options: opts},
Expand All @@ -36,7 +42,7 @@ var (
)

func pgConnectionString(host, port string) string {
return fmt.Sprintf("postgres://postgres@%s:%s/postgres?sslmode=disable", host, port)
return fmt.Sprintf("postgres://postgres:%s@%s:%s/postgres?sslmode=disable", pgPassword, host, port)
}

func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
Expand Down Expand Up @@ -184,7 +190,8 @@ func TestFilterCustomQuery(t *testing.T) {
t.Fatal(err)
}

addr := fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable&x-custom=foobar", ip, port)
addr := fmt.Sprintf("postgres://postgres:%s@%v:%v/postgres?sslmode=disable&x-custom=foobar",
pgPassword, ip, port)
p := &Postgres{}
d, err := p.Open(addr)
if err != nil {
Expand Down Expand Up @@ -226,7 +233,8 @@ func TestWithSchema(t *testing.T) {
}

// re-connect using that schema
d2, err := p.Open(fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable&search_path=foobar", ip, port))
d2, err := p.Open(fmt.Sprintf("postgres://postgres:%s@%v:%v/postgres?sslmode=disable&search_path=foobar",
pgPassword, ip, port))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -295,7 +303,8 @@ func TestParallelSchema(t *testing.T) {
}

// re-connect using that schemas
dfoo, err := p.Open(fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable&search_path=foo", ip, port))
dfoo, err := p.Open(fmt.Sprintf("postgres://postgres:%s@%v:%v/postgres?sslmode=disable&search_path=foo",
pgPassword, ip, port))
if err != nil {
t.Fatal(err)
}
Expand All @@ -305,7 +314,8 @@ func TestParallelSchema(t *testing.T) {
}
}()

dbar, err := p.Open(fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable&search_path=bar", ip, port))
dbar, err := p.Open(fmt.Sprintf("postgres://postgres:%s@%v:%v/postgres?sslmode=disable&search_path=bar",
pgPassword, ip, port))
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit d9d6d85

Please sign in to comment.