Skip to content

Commit

Permalink
planner/core: add bit column test about display width range (#11985)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored Sep 6, 2019
1 parent dd25ed0 commit 702854f
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 250 deletions.
213 changes: 106 additions & 107 deletions ddl/db_integration_test.go

Large diffs are not rendered by default.

120 changes: 60 additions & 60 deletions ddl/db_partition_test.go

Large diffs are not rendered by default.

145 changes: 68 additions & 77 deletions ddl/db_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (s *testSerialSuite) TestCanceledJobTakeTime(c *C) {
ddl.WaitTimeWhenErrorOccured = 1 * time.Second
defer func() { ddl.WaitTimeWhenErrorOccured = originalWT }()
startTime := time.Now()
assertErrorCode(c, tk, "alter table t_cjtt add column b int", mysql.ErrNoSuchTable)
tk.MustGetErrCode("alter table t_cjtt add column b int", mysql.ErrNoSuchTable)
sub := time.Since(startTime)
c.Assert(sub, Less, ddl.WaitTimeWhenErrorOccured)
}
Expand Down
9 changes: 4 additions & 5 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package core_test

import (
. "github.com/pingcap/check"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/util/testkit"
)

Expand Down Expand Up @@ -77,7 +78,7 @@ func (s *testIntegrationSuite) TestPpdWithSetVar(c *C) {
tk.MustQuery("select t01.c1,t01.c2,t01.c3 from (select t1.*,@c3:=@c3+1 as c3 from (select t.*,@c3:=0 from t order by t.c1)t1)t01 where t01.c3=2 and t01.c2='d'").Check(testkit.Rows("2 d 2"))
}

func (s *testIntegrationSuite) BitColErrorMessage(c *C) {
func (s *testIntegrationSuite) TestBitColErrorMessage(c *C) {
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
tk := testkit.NewTestKit(c, store)
Expand All @@ -92,8 +93,6 @@ func (s *testIntegrationSuite) BitColErrorMessage(c *C) {
tk.MustExec("drop table bit_col_t")
tk.MustExec("create table bit_col_t (a bit(1))")
tk.MustExec("drop table bit_col_t")
_, err = tk.Exec("create table bit_col_t (a bit(0))")
c.Assert(err, NotNil)
_, err = tk.Exec("create table bit_col_t (a bit(65))")
c.Assert(err, NotNil)
tk.MustGetErrCode("create table bit_col_t (a bit(0))", mysql.ErrInvalidFieldSize)
tk.MustGetErrCode("create table bit_col_t (a bit(65))", mysql.ErrTooBigDisplaywidth)
}
1 change: 1 addition & 0 deletions types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func init() {
codeTruncatedWrongValue: mysql.ErrTruncatedWrongValue,
codeUnknown: mysql.ErrUnknown,
codeInvalidDefault: mysql.ErrInvalidDefault,
codeInvalidFieldSize: mysql.ErrInvalidFieldSize,
codeMBiggerThanD: mysql.ErrMBiggerThanD,
codeDataOutOfRange: mysql.ErrWarnDataOutOfRange,
codeDuplicatedValueInType: mysql.ErrDuplicatedValueInType,
Expand Down
12 changes: 12 additions & 0 deletions util/testkit/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/session"
Expand Down Expand Up @@ -251,6 +252,17 @@ func (tk *TestKit) ExecToErr(sql string, args ...interface{}) error {
return err
}

// MustGetErrCode executes a sql statement and assert it's error code.
func (tk *TestKit) MustGetErrCode(sql string, errCode int) {
_, err := tk.Exec(sql)
tk.c.Assert(err, check.NotNil)
originErr := errors.Cause(err)
tErr, ok := originErr.(*terror.Error)
tk.c.Assert(ok, check.IsTrue, check.Commentf("expect type 'terror.Error', but obtain '%T'", originErr))
sqlErr := tErr.ToSQLError()
tk.c.Assert(int(sqlErr.Code), check.Equals, errCode, check.Commentf("Assertion failed, origin err:\n %v", sqlErr))
}

// ResultSetToResult converts sqlexec.RecordSet to testkit.Result.
// It is used to check results of execute statement in binary mode.
func (tk *TestKit) ResultSetToResult(rs sqlexec.RecordSet, comment check.CommentInterface) *Result {
Expand Down

0 comments on commit 702854f

Please sign in to comment.