From 20f9a47cd3d5ba5f3883f88de16e33ad133d66de Mon Sep 17 00:00:00 2001 From: DarrylWong <56486370+DarrylWong@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:51:45 -0500 Subject: [PATCH] Add password environment variable for customizing running tests (#1996) In #1429, environment variables were added to read in postgres connection details for customizing tests. This change does the same but with a password variable. It also removes the explicit user and password values from pgOptions, as Options init() will set it as postgres anyway if not specified. This also enables env variables to be used instead for those values. --- db_test.go | 7 ++----- options.go | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/db_test.go b/db_test.go index 679340c4..04908c47 100644 --- a/db_test.go +++ b/db_test.go @@ -14,12 +14,11 @@ import ( "testing" "time" + "github.com/go-pg/pg/v10" + "github.com/go-pg/pg/v10/orm" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/stretchr/testify/require" - - "github.com/go-pg/pg/v10" - "github.com/go-pg/pg/v10/orm" ) func init() { @@ -34,8 +33,6 @@ func TestGinkgo(t *testing.T) { func pgOptions() *pg.Options { return &pg.Options{ - User: "postgres", - Password: "postgres", TLSConfig: getTLSConfig(), MaxRetries: 1, diff --git a/options.go b/options.go index df05ebcd..60b1daa8 100644 --- a/options.go +++ b/options.go @@ -125,6 +125,10 @@ func (opt *Options) init() { opt.User = env("PGUSER", "postgres") } + if opt.Password == "" { + opt.Password = env("PGPASSWORD", "postgres") + } + if opt.Database == "" { opt.Database = env("PGDATABASE", "postgres") }