Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit495222c

Browse files
committed
test: provide an ergonomic way to access the test database for debugging
1 parentd7bdb3c commit495222c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

‎coderd/database/dbtestutil/postgres.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func (p ConnectionParams) DSN() string {
4040
returnfmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable",p.Username,p.Password,p.Host,p.Port,p.DBName)
4141
}
4242

43+
funcWillLogDSN()bool {
44+
returnos.Getenv("CODER_TEST_LOG_PG_DSN")!=""
45+
}
46+
4347
// These variables are global because all tests share them.
4448
var (
4549
connectionParamsInitOnce sync.Once
@@ -227,6 +231,12 @@ func Open(t TBSubset, opts ...OpenOption) (string, error) {
227231
Port:port,
228232
DBName:dbName,
229233
}.DSN()
234+
235+
// Optionally log the DSN to help connect to the test database.
236+
ifWillLogDSN() {
237+
t.Logf("Postgres test DSN: %s",dsn)
238+
_,_=fmt.Fprintln(os.Stderr,"Postgres test DSN:",dsn)
239+
}
230240
returndsn,nil
231241
}
232242

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp