Skip to content

Commit

Permalink
expression: migrate test-infra to testify for flag_simplify_test.go (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun committed Dec 6, 2021
1 parent ffe9b38 commit 9c62e96
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 35 deletions.
48 changes: 14 additions & 34 deletions expression/flag_simplify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,20 @@
package expression_test

import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testutil"
)

var _ = Suite(&testFlagSimplifySuite{})
"testing"

type testFlagSimplifySuite struct {
store kv.Storage
dom *domain.Domain
ctx sessionctx.Context
testData testutil.TestData
}
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/testdata"
)

func (s *testFlagSimplifySuite) SetUpSuite(c *C) {
var err error
s.store, s.dom, err = newStoreWithBootstrap()
c.Assert(err, IsNil)
s.ctx = mock.NewContext()
s.testData, err = testutil.LoadTestSuiteData("testdata", "flag_simplify")
c.Assert(err, IsNil)
}
func TestSimplifyExpressionByFlag(t *testing.T) {
t.Parallel()

func (s *testFlagSimplifySuite) TearDownSuite(c *C) {
c.Assert(s.testData.GenerateOutputIfNeeded(), IsNil)
s.dom.Close()
s.store.Close()
}
store, clean := testkit.CreateMockStore(t)
defer clean()

func (s *testFlagSimplifySuite) TestSimplifyExpressionByFlag(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(id int primary key, a bigint unsigned not null, b bigint unsigned)")
Expand All @@ -59,11 +38,12 @@ func (s *testFlagSimplifySuite) TestSimplifyExpressionByFlag(c *C) {
SQL string
Plan []string
}
s.testData.GetTestCases(c, &input, &output)
flagSimplifyData := expression.GetFlagSimplifyData()
flagSimplifyData.GetTestCases(t, &input, &output)
for i, tt := range input {
s.testData.OnRecord(func() {
testdata.OnRecord(func() {
output[i].SQL = tt
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Rows())
output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery(tt).Rows())
})
tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...))
}
Expand Down
15 changes: 14 additions & 1 deletion expression/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/testkit/testdata"
"github.com/pingcap/tidb/testkit/testmain"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testbridge"
Expand All @@ -28,6 +29,8 @@ import (
"go.uber.org/goleak"
)

var testDataMap = make(testdata.BookKeeper)

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
testmain.ShortCircuitForBench(m)
Expand All @@ -45,13 +48,19 @@ func TestMain(m *testing.M) {
// Note, SetSystemTZ() is a sync.Once operation.
timeutil.SetSystemTZ("system")

testDataMap.LoadTestSuiteData("testdata", "flag_simplify")

opts := []goleak.Option{
goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
goleak.IgnoreTopFunction("github.com/pingcap/tidb/table/tables.mockRemoteService"),
}

goleak.VerifyTestMain(m, opts...)
callback := func(i int) int {
testDataMap.GenerateOutputIfNeeded()
return i
}
goleak.VerifyTestMain(testmain.WrapTestingM(m, callback), opts...)
}

func createContext(t *testing.T) *mock.Context {
Expand All @@ -63,3 +72,7 @@ func createContext(t *testing.T) *mock.Context {
ctx.GetSessionVars().PlanColumnID = 0
return ctx
}

func GetFlagSimplifyData() testdata.TestData {
return testDataMap["flag_simplify"]
}

0 comments on commit 9c62e96

Please sign in to comment.