Skip to content

Commit

Permalink
ddl:enhance ddl unit tests in tidb (pingcap#6502)
Browse files Browse the repository at this point in the history
Add more test cases to improvement test coverage.
  • Loading branch information
ciscoxll authored and shenli committed May 14, 2018
1 parent 7f2b3bd commit 677176b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ func (s *testDBSuite) TestMySQLErrorCode(c *C) {
s.testErrorCode(c, sql, tmysql.ErrUnknownCharacterSet)
sql = "create table t1(a int) character set laitn1;"
s.testErrorCode(c, sql, tmysql.ErrUnknownCharacterSet)
sql = "create table test_error_code (a int not null ,b int not null,c int not null, d int not null, foreign key (b, c) references product(id));"
s.testErrorCode(c, sql, tmysql.ErrWrongFkDef)
sql = "create table test_error_code_2(c1 int, c2 int, c3 int, primary key(c1), primary key(c2));"
s.testErrorCode(c, sql, tmysql.ErrMultiplePriKey)
sql = "create table test_error_code_3(pt blob ,primary key (pt));"
s.testErrorCode(c, sql, tmysql.ErrBlobKeyWithoutLength)
sql = "create table test_error_code_3(a text, unique (a(3073)));"
s.testErrorCode(c, sql, tmysql.ErrTooLongKey)
sql = "create table test_error_code_3(`id` int, key `primary`(`id`));"
s.testErrorCode(c, sql, tmysql.ErrWrongNameForIndex)
sql = "create table t2(c1.c2 blob default null);"
s.testErrorCode(c, sql, tmysql.ErrWrongTableName)

Expand All @@ -173,10 +183,15 @@ func (s *testDBSuite) TestMySQLErrorCode(c *C) {
s.testErrorCode(c, sql, tmysql.ErrTooLongIdent)
sql = "alter table test_comment comment 'test comment'"
s.testErrorCode(c, sql, tmysql.ErrNoSuchTable)
sql = "alter table test_error_code_succ add column `a ` int ;"
s.testErrorCode(c, sql, tmysql.ErrWrongColumnName)

// drop column
sql = "alter table test_error_code_succ drop c_not_exist"
s.testErrorCode(c, sql, tmysql.ErrCantDropFieldOrKey)
s.tk.MustExec("create table test_drop_column (c1 int );")
sql = "alter table test_drop_column drop column c1;"
s.testErrorCode(c, sql, tmysql.ErrCantRemoveAllFields)
// add index
sql = "alter table test_error_code_succ add index idx (c_not_exist)"
s.testErrorCode(c, sql, tmysql.ErrKeyColumnDoesNotExits)
Expand All @@ -193,6 +208,10 @@ func (s *testDBSuite) TestMySQLErrorCode(c *C) {
s.testErrorCode(c, sql, tmysql.ErrWrongDBName)
sql = "alter table test_error_code_succ modify t.c1 bigint"
s.testErrorCode(c, sql, tmysql.ErrWrongTableName)
// insert value
s.tk.MustExec("create table test_error_code_null(c1 char(100) not null);")
sql = "insert into test_error_code_null (c1) values(null);"
s.testErrorCode(c, sql, tmysql.ErrBadNull)
}

func (s *testDBSuite) TestAddIndexAfterAddColumn(c *C) {
Expand All @@ -204,6 +223,8 @@ func (s *testDBSuite) TestAddIndexAfterAddColumn(c *C) {
s.tk.MustExec("alter table test_add_index_after_add_col add column c int not null default '0'")
sql := "alter table test_add_index_after_add_col add unique index cc(c) "
s.testErrorCode(c, sql, tmysql.ErrDupEntry)
sql = "alter table test_add_index_after_add_col add index idx_test(f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17);"
s.testErrorCode(c, sql, tmysql.ErrTooManyKeyParts)
}

func (s *testDBSuite) TestAddIndexWithPK(c *C) {
Expand Down

0 comments on commit 677176b

Please sign in to comment.