From d9d6d85ecd05c9f024b4cca2e219e9068b75039a Mon Sep 17 00:00:00 2001 From: Dale Hui Date: Sun, 16 Feb 2020 00:42:37 -0800 Subject: [PATCH] POSTGRES_PASSWORD is now required when using postgres via docker See: https://github.com/docker-library/postgres/issues/681 --- database/postgres/postgres_test.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/database/postgres/postgres_test.go b/database/postgres/postgres_test.go index 6046375ec..b4645d06f 100644 --- a/database/postgres/postgres_test.go +++ b/database/postgres/postgres_test.go @@ -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}, @@ -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 { @@ -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 { @@ -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) } @@ -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) } @@ -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) }