*: Add test case
This commit is contained in:
@ -198,10 +198,12 @@ func (e *Error) NotEqual(err error) bool {
|
||||
// ToSQLError convert Error to mysql.SQLError.
|
||||
func (e *Error) ToSQLError() *mysql.SQLError {
|
||||
code := e.getMySQLErrorCode()
|
||||
return &mysql.SQLError{
|
||||
Code: code,
|
||||
Message: e.message,
|
||||
}
|
||||
return mysql.NewErrf(code, e.message)
|
||||
/*
|
||||
return &mysql.SQLError{
|
||||
Code: code,
|
||||
Message: e.message,
|
||||
}*/
|
||||
}
|
||||
|
||||
var defaultMySQLErrorCode uint16
|
||||
|
||||
@ -17,8 +17,9 @@ import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
. "github.com/pingcap/check"
|
||||
tmysql "github.com/pingcap/tidb/mysql"
|
||||
)
|
||||
|
||||
func TestT(t *testing.T) {
|
||||
@ -220,6 +221,26 @@ func runTestConcurrentUpdate(c *C) {
|
||||
})
|
||||
}
|
||||
|
||||
func runTestErrorCode(c *C) {
|
||||
runTests(c, dsn, func(dbt *DBTest) {
|
||||
dbt.mustExec("create table test (c int PRIMARY KEY);")
|
||||
dbt.mustExec("insert into test values (1);")
|
||||
txn1, err := dbt.db.Begin()
|
||||
c.Assert(err, IsNil)
|
||||
_, err = txn1.Exec("insert into test values(1)")
|
||||
c.Assert(err, IsNil)
|
||||
err = txn1.Commit()
|
||||
checkErrorCode(c, err, tmysql.ErrDupEntry)
|
||||
})
|
||||
}
|
||||
|
||||
func checkErrorCode(c *C, e error, code uint16) {
|
||||
c.Assert(e, NotNil)
|
||||
me, ok := e.(*mysql.MySQLError)
|
||||
c.Assert(ok, IsTrue)
|
||||
c.Assert(me.Number, Equals, code)
|
||||
}
|
||||
|
||||
func runTestAuth(c *C) {
|
||||
runTests(c, dsn, func(dbt *DBTest) {
|
||||
dbt.mustExec(`CREATE USER 'test'@'%' IDENTIFIED BY '123';`)
|
||||
|
||||
@ -68,6 +68,10 @@ func (ts *TidbTestSuite) TestConcurrentUpdate(c *C) {
|
||||
runTestConcurrentUpdate(c)
|
||||
}
|
||||
|
||||
func (ts *TidbTestSuite) TestErrorCode(c *C) {
|
||||
runTestErrorCode(c)
|
||||
}
|
||||
|
||||
func (ts *TidbTestSuite) TestAuth(c *C) {
|
||||
runTestAuth(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user