aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2020-06-22 08:55:53 -0400
committerJonathan Amsterdam <jba@google.com>2020-06-22 14:34:26 +0000
commitccd36309fc414fa6d64130ab861503cf3171bca8 (patch)
treec1c185bccf574e67141f789c904e0f79079436da
parent43a5edf9d37cf8db18da028a55b505c3ad9344ea (diff)
downloadgo-x-pkgsite-ccd36309fc414fa6d64130ab861503cf3171bca8.tar.xz
all.bash,internal: force DB testing in CI
If the environment variable GO_DISCOVERY_TESTDB is "true" wherever we would skip DB tests, fail instead. Set it to "true" in all.bash. Fixes golang/go#39713. Change-Id: I80fe27578a05610e29cc3ad9f6d477c9768fd51a Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/239257 Reviewed-by: Julie Qiu <julie@golang.org>
-rwxr-xr-xall.bash4
-rw-r--r--internal/database/database.go1
-rw-r--r--internal/database/database_test.go2
-rw-r--r--internal/postgres/test_helper.go2
4 files changed, 4 insertions, 5 deletions
diff --git a/all.bash b/all.bash
index 0da7b306..f828f33d 100755
--- a/all.bash
+++ b/all.bash
@@ -157,7 +157,7 @@ main() {
"")
standard_linters
runcmd go mod tidy
- runcmd go test ./...
+ runcmd env GO_DISCOVERY_TESTDB=true go test ./...
# To test internal/secrets, set GO_DISCOVERY_SECRETS_BUCKET and GO_DISCOVERY_KMS_KEY_NAME
# to appropriate test values.
runcmd go test ./internal/secrets
@@ -166,7 +166,7 @@ main() {
# Similar to the no-arg mode, but omit actions that require GCP
# permissions or that don't test the code.
standard_linters
- runcmd go test -race -count=1 ./...
+ runcmd env GO_DISCOVERY_TESTDB=true go test -race -count=1 ./...
;;
lint) standard_linters ;;
headers) check_headers ;;
diff --git a/internal/database/database.go b/internal/database/database.go
index d13973dd..4c8aff18 100644
--- a/internal/database/database.go
+++ b/internal/database/database.go
@@ -138,7 +138,6 @@ func processRows(rows *sql.Rows, f func(*sql.Rows) error) error {
//
// If the isolation level requires it, Transact will retry the transaction upon
// serialization failure, so txFunc may be called more than once.
-
func (db *DB) Transact(ctx context.Context, iso sql.IsolationLevel, txFunc func(*DB) error) (err error) {
defer derrors.Wrap(&err, "Transact(%s)", iso)
// For the levels which require retry, see
diff --git a/internal/database/database_test.go b/internal/database/database_test.go
index 3e11f6e3..68a9090b 100644
--- a/internal/database/database_test.go
+++ b/internal/database/database_test.go
@@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
const dbName = "discovery_postgres_test"
if err := dbtest.CreateDBIfNotExists(dbName); err != nil {
- if errors.Is(err, derrors.NotFound) {
+ if errors.Is(err, derrors.NotFound) && os.Getenv("GO_DISCOVERY_TESTDB") != "true" {
log.Printf("SKIPPING: could not connect to DB (see doc/postgres.md to set up): %v", err)
return
}
diff --git a/internal/postgres/test_helper.go b/internal/postgres/test_helper.go
index 5b3b0cd1..0e8c4215 100644
--- a/internal/postgres/test_helper.go
+++ b/internal/postgres/test_helper.go
@@ -132,7 +132,7 @@ func RunDBTests(dbName string, m *testing.M, testDB **DB) {
database.QueryLoggingDisabled = true
db, err := SetupTestDB(dbName)
if err != nil {
- if errors.Is(err, derrors.NotFound) {
+ if errors.Is(err, derrors.NotFound) && os.Getenv("GO_DISCOVERY_TESTDB") != "true" {
log.Printf("SKIPPING: could not connect to DB (see doc/postgres.md to set up): %v", err)
return
}