From 0e867e98c85acaed05e19cad80c62201bfeea631 Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:20:33 -0800 Subject: [PATCH] Remove pg.SkipDB(), add DbUrlOrInMemory() --- pkg/pg/pg.go | 13 ++++++++++--- pkg/pg/txdb_test.go | 8 +------- pkg/utils/tests/tests.go | 5 ----- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pkg/pg/pg.go b/pkg/pg/pg.go index e4233212f..fea17e632 100644 --- a/pkg/pg/pg.go +++ b/pkg/pg/pg.go @@ -1,6 +1,7 @@ package pg import ( + "os" "testing" "github.com/google/uuid" @@ -8,12 +9,9 @@ import ( "github.com/scylladb/go-reflectx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" ) func NewSqlxDB(t testing.TB, dbURL string) *sqlx.DB { - tests.SkipShortDB(t) err := RegisterTxDb(dbURL) if err != nil { t.Fatalf("failed to register txdb dialect: %s", err.Error()) @@ -26,3 +24,12 @@ func NewSqlxDB(t testing.TB, dbURL string) *sqlx.DB { return db } + +func DbUrlOrInMemory(t testing.TB) string { + dbURL, ok := os.LookupEnv("CL_DATABASE_URL") + if ok { + return dbURL + } + t.Log("CL_DATABASE_URL not set--falling back to testing txdb backed by an in-memory db") + return string(InMemoryPostgres) +} diff --git a/pkg/pg/txdb_test.go b/pkg/pg/txdb_test.go index 31f30a8d7..32254119f 100644 --- a/pkg/pg/txdb_test.go +++ b/pkg/pg/txdb_test.go @@ -3,7 +3,6 @@ package pg import ( "context" "database/sql" - "os" "sync" "testing" "time" @@ -35,12 +34,7 @@ func TestTxDBDriver(t *testing.T) { assert.Contains(t, drivers, "txdb") }) - dbURL, ok := os.LookupEnv("CL_VATABASE_URL") - if !ok { - t.Log("CL_DATABASE_URL not set--falling back to testing txdb backed by an in-memory db") - dbURL = string(InMemoryPostgres) - } - db := NewSqlxDB(t, dbURL) + db := NewSqlxDB(t, DbUrlOrInMemory(t)) dropTable := func() error { _, err := db.Exec(`DROP TABLE IF EXISTS txdb_test`) return err diff --git a/pkg/utils/tests/tests.go b/pkg/utils/tests/tests.go index 80a47f613..374ef23fb 100644 --- a/pkg/utils/tests/tests.go +++ b/pkg/utils/tests/tests.go @@ -76,11 +76,6 @@ func SkipShort(tb testing.TB, why string) { } } -// SkipShortDB skips tb during -short runs, and notes the DB dependency. -func SkipShortDB(tb testing.TB) { - SkipShort(tb, "DB dependency") -} - func SkipFlakey(t *testing.T, ticketURL string) { t.Skip("Flakey", ticketURL) }