Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix nil onError handler on testHooks #42

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func init() {
hooks := &testHooks{}
hooks.noop()
hooks.reset()

sql.Register("sqlite3-benchmark", Wrap(&sqlite3.SQLiteDriver{}, hooks))
sql.Register("mysql-benchmark", Wrap(&mysql.MySQLDriver{}, hooks))
Expand Down
2 changes: 1 addition & 1 deletion sqlhooks_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestMySQL(t *testing.T) {
s.TestErrHookHook(t, "SELECT * FROM users WHERE id = $2", "INVALID_ARGS")

t.Run("DBWorks", func(t *testing.T) {
s.hooks.noop()
s.hooks.reset()
if _, err := s.db.Exec("DELETE FROM users"); err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion sqlhooks_postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestPostgres(t *testing.T) {
s.TestErrHookHook(t, "SELECT * FROM users WHERE id = $2", "INVALID_ARGS")

t.Run("DBWorks", func(t *testing.T) {
s.hooks.noop()
s.hooks.reset()
if _, err := s.db.Exec("DELETE FROM users"); err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion sqlhooks_sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestSQLite3(t *testing.T) {
s.TestErrHookHook(t, "SELECT * FROM users WHERE id = $2", "INVALID_ARGS")

t.Run("DBWorks", func(t *testing.T) {
s.hooks.noop()
s.hooks.reset()
if _, err := s.db.Exec("DELETE FROM users"); err != nil {
t.Fatal(err)
}
Expand Down
19 changes: 15 additions & 4 deletions sqlhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ type testHooks struct {
onError ErrorHook
}

func (h *testHooks) noop() {
noop := func(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
func newTestHooks() *testHooks {
th := &testHooks{}
th.reset()
return th
}

func (h *testHooks) reset() {
noop := func(ctx context.Context, _ string, _ ...interface{}) (context.Context, error) {
return ctx, nil
}

h.before, h.after = noop, noop
noopErr := func(_ context.Context, err error, _ string, _ ...interface{}) error {
return err
}

h.before, h.after, h.onError = noop, noop, noopErr
}

func (h *testHooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error) {
Expand All @@ -45,7 +55,8 @@ type suite struct {
}

func newSuite(t *testing.T, driver driver.Driver, dsn string) *suite {
hooks := &testHooks{}
hooks := newTestHooks()

driverName := fmt.Sprintf("sqlhooks-%s", time.Now().String())
sql.Register(driverName, Wrap(driver, hooks))

Expand Down