Skip to content

Commit

Permalink
Add configurable test environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Molina committed Jan 24, 2017
1 parent 427fbe3 commit ac516ae
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/common_test.go
Expand Up @@ -3,17 +3,19 @@ package tests
import (
"database/sql"
"fmt"
"os"
"testing"

"github.com/stretchr/testify/suite"
)

const (
host = "0.0.0.0:5432"
database = "testing"
user = "testing"
password = "testing"
)
func envOrDefault(key string, def string) string {
v := os.Getenv(key)
if v == "" {
v = def
}
return v
}

func TestHijackSuite(t *testing.T) {
suite.Run(t, new(CommonSuite))
Expand All @@ -25,10 +27,12 @@ type CommonSuite struct {
}

func (s *CommonSuite) SetupSuite() {
db, err := sql.Open(
"postgres",
fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=disable", user, password, host, database),
)
db, err := sql.Open("postgres", fmt.Sprintf(
"postgres://%s:%s@0.0.0.0:5432/%s?sslmode=disable",
envOrDefault("DBUSER", "testing"),
envOrDefault("DBPASS", "testing"),
envOrDefault("DBNAME", "testing"),
))
s.Nil(err)
s.NotNil(db)
s.db = db
Expand Down

0 comments on commit ac516ae

Please sign in to comment.