add more tests for sqlx (#442)

* add more tests for sqlx

* add more tests for sqlx
This commit is contained in:
Kevin Wan
2021-02-07 11:54:41 +08:00
committed by GitHub
parent ec6132b754
commit 8e889d694d
2 changed files with 72 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
package sqlx
import (
"errors"
"reflect"
"testing"
"github.com/go-sql-driver/mysql"
@@ -33,6 +35,15 @@ func TestBreakerOnNotHandlingDuplicateEntry(t *testing.T) {
assert.True(t, found)
}
func TestMysqlAcceptable(t *testing.T) {
conn := NewMysql("nomysql").(*commonSqlConn)
withMysqlAcceptable()(conn)
assert.EqualValues(t, reflect.ValueOf(mysqlAcceptable).Pointer(), reflect.ValueOf(conn.accept).Pointer())
assert.True(t, mysqlAcceptable(nil))
assert.False(t, mysqlAcceptable(errors.New("any")))
assert.False(t, mysqlAcceptable(new(mysql.MySQLError)))
}
func tryOnDuplicateEntryError(t *testing.T, accept func(error) bool) error {
logx.Disable()