Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
amyangfei committed Apr 3, 2023
1 parent 4ae8d27 commit 35a7073
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cdc/sink/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,17 @@ func NewMySQLSink(
"some types of DDL may fail to be executed",
zap.String("hostname", hostName), zap.String("port", port))
}
db, err := GetDBConnImpl(ctx, dsnStr)

isTiDB, err := CheckIsTiDB(ctx, testDB)
if err != nil {
return nil, err
}
params.isTiDB = isTiDB

isTiDB, err := CheckIsTiDB(ctx, db)
db, err := GetDBConnImpl(ctx, dsnStr)
if err != nil {
return nil, err
}
params.isTiDB = isTiDB

log.Info("Start mysql sink")

Expand Down
4 changes: 4 additions & 0 deletions cdc/sink/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,10 @@ func mockTestDBWithSQLMode(adjustSQLMode bool, sqlMode interface{}) (*sql.DB, er
"where character_set_name = 'gbk';").WillReturnRows(
sqlmock.NewRows([]string{"character_set_name"}).AddRow("gbk"),
)
mock.ExpectQuery("select tidb_version()").WillReturnError(&dmysql.MySQLError{
Number: 1305,
Message: "FUNCTION test.tidb_version does not exist",
})

mock.ExpectClose()
return db, nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/applier/redo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/DATA-DOG/go-sqlmock"
dmysql "github.com/go-sql-driver/mysql"
"github.com/phayes/freeport"
"github.com/pingcap/tiflow/cdc/model"
"github.com/pingcap/tiflow/cdc/redo/common"
Expand Down Expand Up @@ -149,6 +150,10 @@ func TestApplyDMLs(t *testing.T) {
"where character_set_name = 'gbk';").WillReturnRows(
sqlmock.NewRows([]string{"character_set_name"}).AddRow("gbk"),
)
mock.ExpectQuery("select tidb_version()").WillReturnError(&dmysql.MySQLError{
Number: 1305,
Message: "FUNCTION test.tidb_version does not exist",
})
mock.ExpectClose()
return db, nil
}
Expand Down

0 comments on commit 35a7073

Please sign in to comment.