Skip to content

Commit

Permalink
test: skip SQL tests on dockerless CI
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Nov 2, 2023
1 parent c8fb8b8 commit a845795
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ import (
)

func Test_SQL_Connect(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

db, _ := ConnectTestDB(t)
a.NotNil(db)
}

func Test_SQL_Prepare(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

db, _ := ConnectTestDB(t)
Expand Down Expand Up @@ -72,6 +76,8 @@ func Test_SQL_Prepare(t *testing.T) {
}

func Test_SQL_Exec(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

db, _ := ConnectTestDB(t)
Expand Down Expand Up @@ -99,6 +105,8 @@ func Test_SQL_Exec(t *testing.T) {
}

func Test_SQL_Query(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

db, _ := ConnectTestDB(t)
Expand Down Expand Up @@ -126,6 +134,8 @@ func Test_SQL_Query(t *testing.T) {
}

func Test_SQL_Query_Tx(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

db, _ := ConnectTestDB(t)
Expand Down Expand Up @@ -155,6 +165,8 @@ func Test_SQL_Query_Tx(t *testing.T) {
}

func Test_SQL_Query_Tx_Row(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

db, logBuilder := ConnectTestDB(t)
Expand Down Expand Up @@ -191,6 +203,8 @@ func Test_SQL_Query_Tx_Row(t *testing.T) {
}

func Test_SQL_Query_Tx_RowCtx(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

db, _ := ConnectTestDB(t)
Expand All @@ -214,6 +228,8 @@ func Test_SQL_Query_Tx_RowCtx(t *testing.T) {
}

func Test_SQL_Create(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

db, err := sql.ObserveDB(&gosql.DB{}, log.NewNopLogger(), "test1")
Expand All @@ -222,12 +238,16 @@ func Test_SQL_Create(t *testing.T) {
}

func Test_SQL_Monitor(t *testing.T) {
skipIfDisabled(t)

a := assert.New(t)

a.NoError(sql.MeasureStats(&gosql.DB{}, "test1"))
}

func Test_SQL_Monitor_Query(t *testing.T) {
skipIfDisabled(t)

done := sql.MeasureQuery(LazyNopLogger, time.Minute.Milliseconds(), "1", "tx", "select * from test", 0)
done()

Expand Down Expand Up @@ -269,6 +289,8 @@ func LazyNopLogger() log.Logger {

func ConnectTestDB(t *testing.T) (*sql.DB, *log.BufferedLogger) {
t.Helper()
skipIfDisabled(t)

open := func() (*gosql.DB, error) {
db, err := gosql.Open("mysql", "moov:moov@tcp(localhost:3306)/")
if err != nil {
Expand Down Expand Up @@ -324,6 +346,8 @@ func ConnectTestDB(t *testing.T) (*sql.DB, *log.BufferedLogger) {

func AddRecord(t *testing.T, db *sql.DB) string {
t.Helper()
skipIfDisabled(t)

// Add a record
id := uuid.NewString()
sql := "INSERT INTO moov.test(id, value) VALUES (?, ?)"
Expand All @@ -346,3 +370,11 @@ func Test_CleanQuery(t *testing.T) {

assert.Equal(t, `SELECT * FROM sometable WHERE sometable.field = ?`, cleaned)
}

func skipIfDisabled(t *testing.T) {
t.Helper()

if testing.Short() {
t.Skip("-short flag provided")
}
}

0 comments on commit a845795

Please sign in to comment.