Skip to content

Commit

Permalink
mark fail, mustExec and mustQuery as test helpers (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 authored Oct 10, 2023
1 parent 9c633df commit 278a0b9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) {
}

func (dbt *DBTest) fail(method, query string, err error) {
dbt.Helper()
if len(query) > 300 {
query = "[query too large to print]"
}
dbt.Fatalf("error on %s %s: %s", method, query, err.Error())
}

func (dbt *DBTest) mustExec(query string, args ...interface{}) (res sql.Result) {
dbt.Helper()
res, err := dbt.db.Exec(query, args...)
if err != nil {
dbt.fail("exec", query, err)
Expand All @@ -180,6 +182,7 @@ func (dbt *DBTest) mustExec(query string, args ...interface{}) (res sql.Result)
}

func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows) {
dbt.Helper()
rows, err := dbt.db.Query(query, args...)
if err != nil {
dbt.fail("query", query, err)
Expand Down

0 comments on commit 278a0b9

Please sign in to comment.