From 95013bc8b3b2727a8c5b93565364aec0e65b958d Mon Sep 17 00:00:00 2001 From: tuuuuuu <83738345+MiaoMiaoGarden@users.noreply.github.com> Date: Wed, 22 Dec 2021 22:18:12 +0800 Subject: [PATCH] testify for partition_test --- ddl/ddl_test.go | 6 +++++ ddl/partition_test.go | 62 +++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/ddl/ddl_test.go b/ddl/ddl_test.go index 08eb1f2bbae1d..74eded0f9818a 100644 --- a/ddl/ddl_test.go +++ b/ddl/ddl_test.go @@ -113,6 +113,12 @@ func testCreateStore(c *C, name string) kv.Storage { return store } +func testCreateStoreT(t *testing.T, name string) kv.Storage { + store, err := mockstore.NewMockStore() + require.NoError(t, err) + return store +} + func testNewContext(d *ddl) sessionctx.Context { ctx := mock.NewContext() ctx.Store = d.store diff --git a/ddl/partition_test.go b/ddl/partition_test.go index f2cdd1c4e3597..0b993a7de0a8c 100644 --- a/ddl/partition_test.go +++ b/ddl/partition_test.go @@ -16,55 +16,41 @@ package ddl import ( "context" + "testing" - . "github.com/pingcap/check" - "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/model" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" + "github.com/stretchr/testify/require" ) -var _ = SerialSuites(&testPartitionSuite{}) - -type testPartitionSuite struct { - store kv.Storage -} - -func (s *testPartitionSuite) SetUpSuite(c *C) { - s.store = testCreateStore(c, "test_store") -} - -func (s *testPartitionSuite) TearDownSuite(c *C) { - err := s.store.Close() - c.Assert(err, IsNil) -} - -func (s *testPartitionSuite) TestDropAndTruncatePartition(c *C) { +func TestDropAndTruncatePartition(t *testing.T) { + store := testCreateStoreT(t, "test_store") d, err := testNewDDLAndStart( context.Background(), - WithStore(s.store), + WithStore(store), WithLease(testLease), ) - c.Assert(err, IsNil) + require.NoError(t, err) defer func() { err := d.Stop() - c.Assert(err, IsNil) + require.NoError(t, err) }() dbInfo, err := testSchemaInfo(d, "test_partition") - c.Assert(err, IsNil) - testCreateSchema(c, testNewContext(d), d, dbInfo) + require.NoError(t, err) + testCreateSchemaT(t, testNewContext(d), d, dbInfo) // generate 5 partition in tableInfo. - tblInfo, partIDs := buildTableInfoWithPartition(c, d) + tblInfo, partIDs := buildTableInfoWithPartition(t, d) ctx := testNewContext(d) - testCreateTable(c, ctx, d, dbInfo, tblInfo) + testCreateTableT(t, ctx, d, dbInfo, tblInfo) - testDropPartition(c, ctx, d, dbInfo, tblInfo, []string{"p0", "p1"}) + testDropPartition(t, ctx, d, dbInfo, tblInfo, []string{"p0", "p1"}) - testTruncatePartition(c, ctx, d, dbInfo, tblInfo, []int64{partIDs[3], partIDs[4]}) + testTruncatePartition(t, ctx, d, dbInfo, tblInfo, []int64{partIDs[3], partIDs[4]}) } -func buildTableInfoWithPartition(c *C, d *ddl) (*model.TableInfo, []int64) { +func buildTableInfoWithPartition(t *testing.T, d *ddl) (*model.TableInfo, []int64) { tbl := &model.TableInfo{ Name: model.NewCIStr("t"), } @@ -76,14 +62,14 @@ func buildTableInfoWithPartition(c *C, d *ddl) (*model.TableInfo, []int64) { ID: allocateColumnID(tbl), } genIDs, err := d.genGlobalIDs(1) - c.Assert(err, IsNil) + require.NoError(t, err) tbl.ID = genIDs[0] tbl.Columns = []*model.ColumnInfo{col} tbl.Charset = "utf8" tbl.Collate = "utf8_bin" partIDs, err := d.genGlobalIDs(5) - c.Assert(err, IsNil) + require.NoError(t, err) partInfo := &model.PartitionInfo{ Type: model.PartitionTypeRange, Expr: tbl.Columns[0].Name.L, @@ -130,12 +116,12 @@ func buildDropPartitionJob(dbInfo *model.DBInfo, tblInfo *model.TableInfo, partN } } -func testDropPartition(c *C, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo, tblInfo *model.TableInfo, partNames []string) *model.Job { +func testDropPartition(t *testing.T, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo, tblInfo *model.TableInfo, partNames []string) *model.Job { job := buildDropPartitionJob(dbInfo, tblInfo, partNames) err := d.doDDLJob(ctx, job) - c.Assert(err, IsNil) - v := getSchemaVer(c, ctx) - checkHistoryJobArgs(c, ctx, job.ID, &historyJobArgs{ver: v, tbl: tblInfo}) + require.NoError(t, err) + v := getSchemaVerT(t, ctx) + checkHistoryJobArgsT(t, ctx, job.ID, &historyJobArgs{ver: v, tbl: tblInfo}) return job } @@ -149,11 +135,11 @@ func buildTruncatePartitionJob(dbInfo *model.DBInfo, tblInfo *model.TableInfo, p } } -func testTruncatePartition(c *C, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo, tblInfo *model.TableInfo, pids []int64) *model.Job { +func testTruncatePartition(t *testing.T, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo, tblInfo *model.TableInfo, pids []int64) *model.Job { job := buildTruncatePartitionJob(dbInfo, tblInfo, pids) err := d.doDDLJob(ctx, job) - c.Assert(err, IsNil) - v := getSchemaVer(c, ctx) - checkHistoryJobArgs(c, ctx, job.ID, &historyJobArgs{ver: v, tbl: tblInfo}) + require.NoError(t, err) + v := getSchemaVerT(t, ctx) + checkHistoryJobArgsT(t, ctx, job.ID, &historyJobArgs{ver: v, tbl: tblInfo}) return job }