Skip to content

Commit

Permalink
test: use DBHOST while running tests (#272)
Browse files Browse the repository at this point in the history
This allows us to run tests against a PostgreSQL instance on a different host or a non-default port.

Signed-off-by: Santiago M. Mola <[email protected]>
  • Loading branch information
smola authored and Roberto Santalla committed Jun 18, 2018
1 parent d770e29 commit 0ff8479
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func envOrDefault(key string, def string) string {

func dbURL() string {
return fmt.Sprintf(
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
"postgres://%s:%s@%s/%s?sslmode=disable",
envOrDefault("DBUSER", "testing"),
envOrDefault("DBPASS", "testing"),
envOrDefault("DBHOST", "0.0.0.0:5432"),
envOrDefault("DBNAME", "testing"),
)
}
Expand Down
3 changes: 2 additions & 1 deletion common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ func envOrDefault(key string, def string) string {

func openTestDB() (*sql.DB, error) {
return sql.Open("postgres", fmt.Sprintf(
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
"postgres://%s:%s@%s/%s?sslmode=disable",
envOrDefault("DBUSER", "testing"),
envOrDefault("DBPASS", "testing"),
envOrDefault("DBHOST", "0.0.0.0:5432"),
envOrDefault("DBNAME", "testing"),
))
}
Expand Down
3 changes: 2 additions & 1 deletion types/slices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ func envOrDefault(key string, def string) string {

func openTestDB() (*sql.DB, error) {
return sql.Open("postgres", fmt.Sprintf(
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
"postgres://%s:%s@%s/%s?sslmode=disable",
envOrDefault("DBUSER", "testing"),
envOrDefault("DBPASS", "testing"),
envOrDefault("DBHOST", "0.0.0.0:5432"),
envOrDefault("DBNAME", "testing"),
))
}

0 comments on commit 0ff8479

Please sign in to comment.