Skip to content

Commit

Permalink
Remove pg.SkipDB(), add DbUrlOrInMemory()
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Dec 11, 2024
1 parent 3d9ffe3 commit bad96f9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
13 changes: 10 additions & 3 deletions pkg/pg/pg.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package pg

import (
"os"
"testing"

"github.com/google/uuid"
"github.com/jmoiron/sqlx"
"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())
Expand All @@ -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)
}
8 changes: 1 addition & 7 deletions pkg/pg/txdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pg
import (
"context"
"database/sql"
"os"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions pkg/utils/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit bad96f9

Please sign in to comment.