Skip to content

Commit

Permalink
fix all unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
3AceShowHand committed Nov 21, 2023
1 parent b52a50a commit 0f9f79a
Showing 1 changed file with 3 additions and 36 deletions.
39 changes: 3 additions & 36 deletions pkg/sink/codec/canal/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,39 +225,34 @@ func TestGetMySQLType4IntTypes(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[0].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[0].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "int", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "int(10)", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "tinyint", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "tinyint(3)", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "smallint", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "smallint(5)", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[3].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "mediumint", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "mediumint(8)", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[4].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "bigint", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -276,39 +271,34 @@ func TestGetMySQLType4IntTypes(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[0].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[0].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "int unsigned", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "int(10) unsigned", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "tinyint unsigned", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "tinyint(3) unsigned", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "smallint unsigned", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "smallint(5) unsigned", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[3].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "mediumint unsigned", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "mediumint(8) unsigned", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[4].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "bigint unsigned", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -327,39 +317,34 @@ func TestGetMySQLType4IntTypes(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[0].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[0].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "int unsigned zerofill", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "int(10) unsigned zerofill", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "tinyint unsigned zerofill", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "tinyint(3) unsigned zerofill", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "smallint unsigned zerofill", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "smallint(5) unsigned zerofill", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[3].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "mediumint unsigned zerofill", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "mediumint(8) unsigned zerofill", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[4].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "bigint unsigned zerofill", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -377,7 +362,6 @@ func TestGetMySQLType4IntTypes(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "bit", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -397,7 +381,6 @@ func TestGetMySQLType4IntTypes(t *testing.T) {
// bool is identical to tinyint in the TiDB.
columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[3].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "tinyint", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand Down Expand Up @@ -447,15 +430,13 @@ func TestGetMySQLType4FloatType(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "float", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "float(10,3)", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "float", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -469,8 +450,6 @@ func TestGetMySQLType4FloatType(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]

mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "double", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand Down Expand Up @@ -511,15 +490,13 @@ func TestGetMySQLType4FloatType(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[3].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[3].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "float unsigned zerofill", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "float unsigned zerofill", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[4].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[4].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "double unsigned zerofill", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -538,15 +515,13 @@ func TestGetMySQLType4Decimal(t *testing.T) {

columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag := tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType := utils.GetMySQLType(columnInfo, false)
require.Equal(t, "decimal", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "decimal(10,0)", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "decimal", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -560,15 +535,14 @@ func TestGetMySQLType4Decimal(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "decimal", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "decimal(5,0)", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
flag := tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "decimal", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -585,7 +559,6 @@ func TestGetMySQLType4Decimal(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "decimal unsigned", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand Down Expand Up @@ -615,15 +588,14 @@ func TestGetMySQLType4TimeTypes(t *testing.T) {

columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag := tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType := utils.GetMySQLType(columnInfo, false)
require.Equal(t, "time", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "time", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
flag := tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "time", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -640,7 +612,6 @@ func TestGetMySQLType4TimeTypes(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "datetime", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand All @@ -665,7 +636,6 @@ func TestGetMySQLType4TimeTypes(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "timestamp", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand Down Expand Up @@ -706,7 +676,6 @@ func TestGetMySQLType4TimeTypes(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "year", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand Down Expand Up @@ -736,15 +705,14 @@ func TestGetMySQLType4Char(t *testing.T) {

columnInfo, ok := tableInfo.GetColumnInfo(colInfos[1].ID)
require.True(t, ok)
flag := tableInfo.ColumnsFlag[colInfos[1].ID]
mysqlType := utils.GetMySQLType(columnInfo, false)
require.Equal(t, "char", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
require.Equal(t, "char(1)", mysqlType)

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
flag := tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "char", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand Down Expand Up @@ -849,7 +817,6 @@ func TestGetMySQLType4BinaryType(t *testing.T) {

columnInfo, ok = tableInfo.GetColumnInfo(colInfos[2].ID)
require.True(t, ok)
flag = tableInfo.ColumnsFlag[colInfos[2].ID]
mysqlType = utils.GetMySQLType(columnInfo, false)
require.Equal(t, "binary", mysqlType)
mysqlType = utils.GetMySQLType(columnInfo, true)
Expand Down

0 comments on commit 0f9f79a

Please sign in to comment.