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

expression: migrate test-infra to testify for constant_propagation_test.go #30430

Merged
merged 3 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
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
49 changes: 15 additions & 34 deletions expression/constant_propagation_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"
)
"testing"

var _ = Suite(&testSuite{})
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/testdata"
)

type testSuite struct {
store kv.Storage
dom *domain.Domain
ctx sessionctx.Context
testData testutil.TestData
}
func TestOuterJoinPropConst(t *testing.T) {
t.Parallel()

func (s *testSuite) 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", "expression_suite")
c.Assert(err, IsNil)
}
store, clean := testkit.CreateMockStore(t)
defer clean()

func (s *testSuite) TearDownSuite(c *C) {
c.Assert(s.testData.GenerateOutputIfNeeded(), IsNil)
s.dom.Close()
s.store.Close()
}

func (s *testSuite) TestOuterJoinPropConst(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2;")
tk.MustExec("create table t1(id bigint primary key, a int, b int);")
Expand All @@ -60,11 +39,13 @@ func (s *testSuite) TestOuterJoinPropConst(c *C) {
SQL string
Result []string
}
s.testData.GetTestCases(c, &input, &output)

expressionSuiteData := expression.GetExpressionSuiteData()
expressionSuiteData.GetTestCases(t, &input, &output)
for i, tt := range input {
s.testData.OnRecord(func() {
testdata.OnRecord(func() {
output[i].SQL = tt
output[i].Result = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Rows())
output[i].Result = testdata.ConvertRowsToStrings(tk.MustQuery(tt).Rows())
})
tk.MustQuery(tt).Check(testkit.Rows(output[i].Result...))
}
Expand Down
6 changes: 3 additions & 3 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6579,7 +6579,7 @@ func (s *testIntegrationSerialSuite) TestCacheConstEval(c *C) {
tk.MustExec("admin reload expr_pushdown_blacklist")
}

func (s *testSuite) TestIssue20071(c *C) {
func (s *testIntegrationSuite) TestIssue20071(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists table_30_utf8_4")
tk.MustExec("drop table if exists t")
Expand All @@ -6592,7 +6592,7 @@ func (s *testSuite) TestIssue20071(c *C) {
tk.MustExec("select a from table_30_utf8_4 order by a")
}

func (s *testSuite) TestVirtualGeneratedColumnAndLimit(c *C) {
func (s *testIntegrationSuite) TestVirtualGeneratedColumnAndLimit(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int, b int as (a + 1));")
Expand Down Expand Up @@ -7915,7 +7915,7 @@ func (s *testIntegrationSuite) TestIssue11333(c *C) {
tk.MustQuery(`select 0.000000000000000000000000000000000000000000000000000000000000000000000001;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000001"))
}

func (s *testSuite) TestIssue12206(c *C) {
func (s *testIntegrationSuite) TestIssue12206(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t12206;")
Expand Down
5 changes: 5 additions & 0 deletions expression/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestMain(m *testing.M) {
timeutil.SetSystemTZ("system")

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

opts := []goleak.Option{
goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),
Expand Down Expand Up @@ -76,3 +77,7 @@ func createContext(t *testing.T) *mock.Context {
func GetFlagSimplifyData() testdata.TestData {
return testDataMap["flag_simplify"]
}

func GetExpressionSuiteData() testdata.TestData {
return testDataMap["expression_suite"]
}
11 changes: 4 additions & 7 deletions expression/typeinfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ import (

func TestInferType(t *testing.T) {
t.Parallel()
store, dom, err := newStoreWithBootstrap()
require.NoError(t, err)
defer func() {
dom.Close()
err = store.Close()
require.NoError(t, err)
}()

store, clean := testkit.CreateMockStore(t)
defer clean()

s := InferTypeSuite{}
se, err := session.CreateSession4Test(store)
require.NoError(t, err)
Expand Down