Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: migrate test-infra to testify for ddl/db_partition_test.go #30952

Merged
merged 2 commits into from
Dec 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 24 additions & 38 deletions ddl/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}