Skip to content

Commit

Permalink
executor: migrate test-infra to testify for executor/write_test.go (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Nov 23, 2021
1 parent 205d9ab commit bba5fee
Show file tree
Hide file tree
Showing 6 changed files with 1,073 additions and 861 deletions.
9 changes: 0 additions & 9 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,6 @@ func TestGroupConcatAggr(t *testing.T) {
rows.Check(testkit.Rows("01234567", "12345"))
}

func fillData(tk *testkit.TestKit, table string) {
tk.MustExec("use test")
tk.MustExec(fmt.Sprintf("create table %s(id int not null default 1, name varchar(255), PRIMARY KEY(id));", table))

// insert data
tk.MustExec(fmt.Sprintf("insert INTO %s VALUES (1, \"hello\");", table))
tk.MustExec(fmt.Sprintf("insert into %s values (2, \"hello\");", table))
}

func TestSelectDistinct(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
Expand Down
25 changes: 12 additions & 13 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import (
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
testkit2 "github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/admin"
Expand All @@ -81,6 +82,7 @@ import (
"github.com/pingcap/tidb/util/testutil"
"github.com/pingcap/tidb/util/timeutil"
"github.com/pingcap/tipb/go-tipb"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/oracle"
"github.com/tikv/client-go/v2/testutils"
"github.com/tikv/client-go/v2/tikv"
Expand Down Expand Up @@ -112,7 +114,6 @@ var _ = SerialSuites(&testSuiteJoinSerial{&baseTestSuite{}})
var _ = Suite(&testSuite6{&baseTestSuite{}})
var _ = Suite(&testSuite7{&baseTestSuite{}})
var _ = Suite(&testSuite8{&baseTestSuite{}})
var _ = Suite(&testBypassSuite{})
var _ = Suite(&testUpdateSuite{})
var _ = Suite(&testPointGetSuite{})
var _ = SerialSuites(&testRecoverTable{})
Expand Down Expand Up @@ -617,35 +618,33 @@ type testCase struct {
}

func checkCases(tests []testCase, ld *executor.LoadDataInfo,
c *C, tk *testkit.TestKit, ctx sessionctx.Context, selectSQL, deleteSQL string) {
t *testing.T, tk *testkit2.TestKit, ctx sessionctx.Context, selectSQL, deleteSQL string) {
origin := ld.IgnoreLines
for _, tt := range tests {
ld.IgnoreLines = origin
c.Assert(ctx.NewTxn(context.Background()), IsNil)
require.Nil(t, ctx.NewTxn(context.Background()))
ctx.GetSessionVars().StmtCtx.DupKeyAsWarning = true
ctx.GetSessionVars().StmtCtx.BadNullAsWarning = true
ctx.GetSessionVars().StmtCtx.InLoadDataStmt = true
ctx.GetSessionVars().StmtCtx.InDeleteStmt = false
data, reachLimit, err1 := ld.InsertData(context.Background(), tt.data1, tt.data2)
c.Assert(err1, IsNil)
c.Assert(reachLimit, IsFalse)
require.NoError(t, err1)
require.False(t, reachLimit)
err1 = ld.CheckAndInsertOneBatch(context.Background(), ld.GetRows(), ld.GetCurBatchCnt())
c.Assert(err1, IsNil)
require.NoError(t, err1)
ld.SetMaxRowsInBatch(20000)
if tt.restData == nil {
c.Assert(data, HasLen, 0,
Commentf("data1:%v, data2:%v, data:%v", string(tt.data1), string(tt.data2), string(data)))
require.Len(t, data, 0, "data1:%v, data2:%v, data:%v", string(tt.data1), string(tt.data2), string(data))
} else {
c.Assert(data, DeepEquals, tt.restData,
Commentf("data1:%v, data2:%v, data:%v", string(tt.data1), string(tt.data2), string(data)))
require.Equal(t, tt.restData, data, "data1:%v, data2:%v, data:%v", string(tt.data1), string(tt.data2), string(data))
}
ld.SetMessage()
tk.CheckLastMessage(tt.expectedMsg)
require.Equal(t, tt.expectedMsg, tk.Session().LastMessage())
ctx.StmtCommit()
txn, err := ctx.Txn(true)
c.Assert(err, IsNil)
require.NoError(t, err)
err = txn.Commit(context.Background())
c.Assert(err, IsNil)
require.NoError(t, err)
r := tk.MustQuery(selectSQL)
r.Check(testutil.RowsWithSep("|", tt.expected...))
tk.MustExec(deleteSQL)
Expand Down
11 changes: 11 additions & 0 deletions executor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package executor_test

import (
"fmt"
"os"
"testing"

"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/testdata"
"github.com/pingcap/tidb/testkit/testmain"
"github.com/pingcap/tidb/util/testbridge"
Expand Down Expand Up @@ -64,3 +66,12 @@ func TestMain(m *testing.M) {

goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...)
}

func fillData(tk *testkit.TestKit, table string) {
tk.MustExec("use test")
tk.MustExec(fmt.Sprintf("create table %s(id int not null default 1, name varchar(255), PRIMARY KEY(id));", table))

// insert data
tk.MustExec(fmt.Sprintf("insert INTO %s VALUES (1, \"hello\");", table))
tk.MustExec(fmt.Sprintf("insert into %s values (2, \"hello\");", table))
}
Loading

0 comments on commit bba5fee

Please sign in to comment.