Skip to content

Commit

Permalink
Add password environment variable for customizing running tests (#1996)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DarrylWong authored Jan 23, 2024
1 parent dd30470 commit 20f9a47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 2 additions & 5 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -34,8 +33,6 @@ func TestGinkgo(t *testing.T) {

func pgOptions() *pg.Options {
return &pg.Options{
User: "postgres",
Password: "postgres",
TLSConfig: getTLSConfig(),

MaxRetries: 1,
Expand Down
4 changes: 4 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 20f9a47

Please sign in to comment.