Skip to content

Commit

Permalink
mark fail, mustExec and mustQuery as test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Oct 7, 2023
1 parent 3798012 commit 870fecb
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 870fecb

Please sign in to comment.