Skip to content

Commit 3c5cdf7

Browse files
Prometheus2677FPiety0521
authored and
FPiety0521
committed
POSTGRES_PASSWORD is now required when using postgres via docker
See: docker-library/postgres#681
1 parent 00b0479 commit 3c5cdf7

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

database/postgres/postgres_test.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ import (
2323
_ "github.com/golang-migrate/migrate/v4/source/file"
2424
)
2525

26+
const (
27+
pgPassword = "postgres"
28+
)
29+
2630
var (
27-
opts = dktest.Options{PortRequired: true, ReadyFunc: isReady}
31+
opts = dktest.Options{
32+
Env: map[string]string{"POSTGRES_PASSWORD": pgPassword},
33+
PortRequired: true, ReadyFunc: isReady}
2834
// Supported versions: https://www.postgresql.org/support/versioning/
2935
specs = []dktesting.ContainerSpec{
3036
{ImageName: "postgres:9.5", Options: opts},
@@ -36,7 +42,7 @@ var (
3642
)
3743

3844
func pgConnectionString(host, port string) string {
39-
return fmt.Sprintf("postgres://postgres@%s:%s/postgres?sslmode=disable", host, port)
45+
return fmt.Sprintf("postgres://postgres:%s@%s:%s/postgres?sslmode=disable", pgPassword, host, port)
4046
}
4147

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

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

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

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

308-
dbar, err := p.Open(fmt.Sprintf("postgres://postgres@%v:%v/postgres?sslmode=disable&search_path=bar", ip, port))
317+
dbar, err := p.Open(fmt.Sprintf("postgres://postgres:%s@%v:%v/postgres?sslmode=disable&search_path=bar",
318+
pgPassword, ip, port))
309319
if err != nil {
310320
t.Fatal(err)
311321
}

0 commit comments

Comments
 (0)