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

This commit is contained in:
tison
2021-12-07 16:29:55 +08:00
committed by GitHub
parent 6eb14e0e8d
commit e7aeae7eda
4 changed files with 27 additions and 44 deletions

View File

@ -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"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/testdata"
)
var _ = Suite(&testSuite{})
func TestOuterJoinPropConst(t *testing.T) {
t.Parallel()
type testSuite struct {
store kv.Storage
dom *domain.Domain
ctx sessionctx.Context
testData testutil.TestData
}
store, clean := testkit.CreateMockStore(t)
defer clean()
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)
}
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);")
@ -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...))
}

View File

@ -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")
@ -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));")
@ -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;")

View File

@ -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"),
@ -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"]
}

View File

@ -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)