Skip to content

Commit aacfbf6

Browse files
authored
*: move show tests. (pingcap#4542)
1 parent 1043b0f commit aacfbf6

3 files changed

Lines changed: 68 additions & 138 deletions

File tree

executor/show_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,41 @@ func (s *testSuite) TestIssue3641(c *C) {
361361
_, err = tk.Exec("show table status;")
362362
c.Assert(err.Error(), Equals, plan.ErrNoDB.Error())
363363
}
364+
365+
// TestShow2 is moved from session_test
366+
func (s *testSuite) TestShow2(c *C) {
367+
tk := testkit.NewTestKit(c, s.store)
368+
tk.MustExec("use test")
369+
370+
tk.MustExec("set global autocommit=0")
371+
tk1 := testkit.NewTestKit(c, s.store)
372+
tk1.MustQuery("show global variables where variable_name = 'autocommit'").Check(testkit.Rows("autocommit 0"))
373+
tk.MustExec("set global autocommit = 1")
374+
tk2 := testkit.NewTestKit(c, s.store)
375+
// TODO: In MySQL, the result is "autocommit ON".
376+
tk2.MustQuery("show global variables where variable_name = 'autocommit'").Check(testkit.Rows("autocommit 1"))
377+
378+
tk.MustExec("drop table if exists t")
379+
tk.MustExec(`create table if not exists t (c int) comment '注释'`)
380+
tk.MustQuery(`show columns from t`).Check(testutil.RowsWithSep(",", "c,int(11),YES,,<nil>,"))
381+
382+
tk.MustQuery("show collation where Charset = 'utf8' and Collation = 'utf8_bin'").Check(testutil.RowsWithSep(",", "utf8_bin,utf8,83,,Yes,1"))
383+
384+
tk.MustQuery("show tables").Check(testkit.Rows("t"))
385+
tk.MustQuery("show full tables").Check(testkit.Rows("t BASE TABLE"))
386+
387+
r, err := tk.Exec("show table status from test like 't'")
388+
c.Assert(err, IsNil)
389+
row, err := r.Next()
390+
c.Assert(err, IsNil)
391+
c.Assert(row.Data, HasLen, 18)
392+
c.Assert(row.Data[0].GetString(), Equals, "t")
393+
c.Assert(row.Data[17].GetString(), Equals, "注释")
394+
395+
tk.Se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, []byte("012345678901234567890"))
396+
397+
tk.MustQuery("show databases like 'test'").Check(testkit.Rows("test"))
398+
399+
tk.MustExec("grant all on *.* to 'root'@'%'")
400+
tk.MustQuery("show grants").Check(testkit.Rows("GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'"))
401+
}

new_session_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/pingcap/tidb/store/tikv"
3232
"github.com/pingcap/tidb/store/tikv/mock-tikv"
3333
"github.com/pingcap/tidb/terror"
34+
"github.com/pingcap/tidb/util/sqlexec"
3435
"github.com/pingcap/tidb/util/testkit"
3536
"github.com/pingcap/tidb/util/testleak"
3637
)
@@ -330,6 +331,35 @@ func (s *testSessionSuite) TestString(c *C) {
330331
c.Log(tk.Se.String())
331332
}
332333

334+
func (s *testSessionSuite) TestDatabase(c *C) {
335+
tk := testkit.NewTestKitWithInit(c, s.store)
336+
337+
// Test database.
338+
tk.MustExec("create database xxx")
339+
tk.MustExec("drop database xxx")
340+
341+
tk.MustExec("drop database if exists xxx")
342+
tk.MustExec("create database xxx")
343+
tk.MustExec("create database if not exists xxx")
344+
tk.MustExec("drop database if exists xxx")
345+
346+
// Test schema.
347+
tk.MustExec("create schema xxx")
348+
tk.MustExec("drop schema xxx")
349+
350+
tk.MustExec("drop schema if exists xxx")
351+
tk.MustExec("create schema xxx")
352+
tk.MustExec("create schema if not exists xxx")
353+
tk.MustExec("drop schema if exists xxx")
354+
}
355+
356+
func (s *testSessionSuite) TestExecRestrictedSQL(c *C) {
357+
tk := testkit.NewTestKitWithInit(c, s.store)
358+
r, _, err := tk.Se.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(tk.Se, "select 1;")
359+
c.Assert(err, IsNil)
360+
c.Assert(len(r), Equals, 1)
361+
}
362+
333363
var _ = Suite(&testSchemaSuite{})
334364

335365
type testSchemaSuite struct {

session_test.go

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -793,69 +793,6 @@ func (s *testSessionSuite) TestMySQLTypes(c *C) {
793793
mustExecSQL(c, se, dropDBSQL)
794794
}
795795

796-
func (s *testSessionSuite) TestShow(c *C) {
797-
defer testleak.AfterTest(c)()
798-
dbName := "test_show"
799-
dropDBSQL := fmt.Sprintf("drop database %s;", dbName)
800-
se := newSession(c, s.store, dbName)
801-
802-
mustExecSQL(c, se, "set global autocommit=1")
803-
r := mustExecSQL(c, se, "show global variables where variable_name = 'autocommit'")
804-
row, err := r.Next()
805-
c.Assert(err, IsNil)
806-
match(c, row.Data, "autocommit", "ON")
807-
808-
mustExecSQL(c, se, "drop table if exists t")
809-
mustExecSQL(c, se, `create table if not exists t (c int) comment '注释'`)
810-
r = mustExecSQL(c, se, `show columns from t`)
811-
rows, err := GetRows(r)
812-
c.Assert(err, IsNil)
813-
c.Assert(rows, HasLen, 1)
814-
match(c, rows[0], "c", "int(11)", "YES", "", nil, "")
815-
816-
r = mustExecSQL(c, se, "show collation where Charset = 'utf8' and Collation = 'utf8_bin'")
817-
row, err = r.Next()
818-
c.Assert(err, IsNil)
819-
match(c, row.Data, "utf8_bin", "utf8", 83, "", "Yes", 1)
820-
821-
r = mustExecSQL(c, se, "show tables")
822-
row, err = r.Next()
823-
c.Assert(err, IsNil)
824-
c.Assert(row.Data, HasLen, 1)
825-
826-
r = mustExecSQL(c, se, "show full tables")
827-
row, err = r.Next()
828-
c.Assert(err, IsNil)
829-
c.Assert(row.Data, HasLen, 2)
830-
831-
r = mustExecSQL(c, se, "show create table t")
832-
row, err = r.Next()
833-
c.Assert(err, IsNil)
834-
c.Assert(row.Data, HasLen, 2)
835-
c.Assert(row.Data[0].GetString(), Equals, "t")
836-
837-
r = mustExecSQL(c, se, fmt.Sprintf("show table status from %s like 't';", dbName))
838-
row, err = r.Next()
839-
c.Assert(err, IsNil)
840-
c.Assert(row.Data, HasLen, 18)
841-
c.Assert(row.Data[0].GetString(), Equals, "t")
842-
c.Assert(row.Data[17].GetString(), Equals, "注释")
843-
844-
r = mustExecSQL(c, se, "show databases like 'test'")
845-
row, err = r.Next()
846-
c.Assert(err, IsNil)
847-
c.Assert(row.Data, HasLen, 1)
848-
c.Assert(row.Data[0].GetString(), Equals, "test")
849-
850-
r = mustExecSQL(c, se, "grant all on *.* to 'root'@'%'")
851-
r = mustExecSQL(c, se, "show grants")
852-
row, err = r.Next()
853-
c.Assert(err, IsNil)
854-
c.Assert(row.Data, HasLen, 1)
855-
856-
mustExecSQL(c, se, dropDBSQL)
857-
}
858-
859796
func (s *testSessionSuite) TestBit(c *C) {
860797
defer testleak.AfterTest(c)()
861798
dbName := "test_bit"
@@ -979,33 +916,6 @@ func (s *testSessionSuite) TestSet(c *C) {
979916
mustExecSQL(c, se, dropDBSQL)
980917
}
981918

982-
func (s *testSessionSuite) TestDatabase(c *C) {
983-
defer testleak.AfterTest(c)()
984-
dbName := "test_database"
985-
dropDBSQL := fmt.Sprintf("drop database %s;", dbName)
986-
se := newSession(c, s.store, dbName)
987-
988-
// Test database.
989-
mustExecSQL(c, se, "create database xxx")
990-
mustExecSQL(c, se, "drop database xxx")
991-
992-
mustExecSQL(c, se, "drop database if exists xxx")
993-
mustExecSQL(c, se, "create database xxx")
994-
mustExecSQL(c, se, "create database if not exists xxx")
995-
mustExecSQL(c, se, "drop database if exists xxx")
996-
997-
// Test schema.
998-
mustExecSQL(c, se, "create schema xxx")
999-
mustExecSQL(c, se, "drop schema xxx")
1000-
1001-
mustExecSQL(c, se, "drop schema if exists xxx")
1002-
mustExecSQL(c, se, "create schema xxx")
1003-
mustExecSQL(c, se, "create schema if not exists xxx")
1004-
mustExecSQL(c, se, "drop schema if exists xxx")
1005-
1006-
mustExecSQL(c, se, dropDBSQL)
1007-
}
1008-
1009919
func (s *testSessionSuite) TestWhereLike(c *C) {
1010920
defer testleak.AfterTest(c)()
1011921
dbName := "test_where_like"
@@ -1051,18 +961,6 @@ func (s *testSessionSuite) TestDefaultFlenBug(c *C) {
1051961
c.Assert(err, IsNil)
1052962
}
1053963

1054-
func (s *testSessionSuite) TestExecRestrictedSQL(c *C) {
1055-
defer testleak.AfterTest(c)()
1056-
dbName := "test_exec_restricted_sql"
1057-
dropDBSQL := fmt.Sprintf("drop database %s;", dbName)
1058-
se := newSession(c, s.store, dbName).(*session)
1059-
r, _, err := se.ExecRestrictedSQL(se, "select 1;")
1060-
c.Assert(err, IsNil)
1061-
c.Assert(len(r), Equals, 1)
1062-
1063-
mustExecSQL(c, se, dropDBSQL)
1064-
}
1065-
1066964
func (s *testSessionSuite) TestOrderBy(c *C) {
1067965
defer testleak.AfterTest(c)()
1068966
dbName := "test_order_by"
@@ -1294,24 +1192,6 @@ func (s *testSessionSuite) TestFieldText(c *C) {
12941192
mustExecSQL(c, se, dropDBSQL)
12951193
}
12961194

1297-
func (s *testSessionSuite) TestIndexPointLookup(c *C) {
1298-
defer testleak.AfterTest(c)()
1299-
dbName := "test_index_point_lookup"
1300-
dropDBSQL := fmt.Sprintf("drop database %s;", dbName)
1301-
se := newSession(c, s.store, dbName)
1302-
mustExecSQL(c, se, "drop table if exists t")
1303-
mustExecSQL(c, se, "create table t (a int)")
1304-
mustExecSQL(c, se, "insert t values (1), (2), (3)")
1305-
mustExecMatch(c, se, "select * from t where a = '1.1';", [][]interface{}{})
1306-
mustExecMatch(c, se, "select * from t where a > '1.1';", [][]interface{}{{2}, {3}})
1307-
mustExecMatch(c, se, "select * from t where a = '2';", [][]interface{}{{2}})
1308-
mustExecMatch(c, se, "select * from t where a = 3;", [][]interface{}{{3}})
1309-
mustExecMatch(c, se, "select * from t where a = 4;", [][]interface{}{})
1310-
mustExecSQL(c, se, "drop table t")
1311-
1312-
mustExecSQL(c, se, dropDBSQL)
1313-
}
1314-
13151195
func (s *testSessionSuite) TestIssue454(c *C) {
13161196
defer testleak.AfterTest(c)()
13171197
dbName := "test_issue454"
@@ -1451,24 +1331,6 @@ func (s *testSessionSuite) TestRetryPreparedStmt(c *C) {
14511331
mustExecSQL(c, se, dropDBSQL)
14521332
}
14531333

1454-
func (s *testSessionSuite) TestSleep(c *C) {
1455-
defer testleak.AfterTest(c)()
1456-
dbName := "test_sleep"
1457-
dropDBSQL := fmt.Sprintf("drop database %s;", dbName)
1458-
se := newSession(c, s.store, dbName)
1459-
1460-
mustExecSQL(c, se, "select sleep(0.01);")
1461-
mustExecSQL(c, se, "drop table if exists t;")
1462-
mustExecSQL(c, se, "create table t (a int);")
1463-
mustExecSQL(c, se, "insert t values (sleep(0.02));")
1464-
r := mustExecSQL(c, se, "select * from t;")
1465-
row, err := r.Next()
1466-
c.Assert(err, IsNil)
1467-
match(c, row.Data, 0)
1468-
1469-
mustExecSQL(c, se, dropDBSQL)
1470-
}
1471-
14721334
func (s *testSessionSuite) TestIssue893(c *C) {
14731335
defer testleak.AfterTest(c)()
14741336
dbName := "test_issue893"

0 commit comments

Comments
 (0)