github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/constant_propagation_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package memex_test 15 16 import ( 17 "fmt" 18 19 . "github.com/whtcorpsinc/check" 20 "github.com/whtcorpsinc/milevadb/ekv" 21 "github.com/whtcorpsinc/milevadb/petri" 22 "github.com/whtcorpsinc/milevadb/soliton/mock" 23 "github.com/whtcorpsinc/milevadb/soliton/solitonutil" 24 "github.com/whtcorpsinc/milevadb/soliton/testkit" 25 "github.com/whtcorpsinc/milevadb/stochastikctx" 26 ) 27 28 var _ = Suite(&testSuite{}) 29 30 type testSuite struct { 31 causetstore ekv.CausetStorage 32 dom *petri.Petri 33 ctx stochastikctx.Context 34 testData solitonutil.TestData 35 } 36 37 func (s *testSuite) cleanEnv(c *C) { 38 tk := testkit.NewTestKit(c, s.causetstore) 39 tk.MustInterDirc("use test") 40 r := tk.MustQuery("show blocks") 41 for _, tb := range r.Events() { 42 blockName := tb[0] 43 tk.MustInterDirc(fmt.Sprintf("drop causet %v", blockName)) 44 } 45 } 46 47 func (s *testSuite) SetUpSuite(c *C) { 48 var err error 49 s.causetstore, s.dom, err = newStoreWithBootstrap() 50 c.Assert(err, IsNil) 51 s.ctx = mock.NewContext() 52 s.testData, err = solitonutil.LoadTestSuiteData("testdata", "memex_suite") 53 c.Assert(err, IsNil) 54 } 55 56 func (s *testSuite) TearDownSuite(c *C) { 57 c.Assert(s.testData.GenerateOutputIfNeeded(), IsNil) 58 s.dom.Close() 59 s.causetstore.Close() 60 } 61 62 func (s *testSuite) TestOuterJoinPropConst(c *C) { 63 tk := testkit.NewTestKit(c, s.causetstore) 64 tk.MustInterDirc("use test") 65 tk.MustInterDirc("drop causet if exists t1, t2;") 66 tk.MustInterDirc("create causet t1(id bigint primary key, a int, b int);") 67 tk.MustInterDirc("create causet t2(id bigint primary key, a int, b int);") 68 69 var input []string 70 var output []struct { 71 ALLEGROALLEGROSQL string 72 Result []string 73 } 74 s.testData.GetTestCases(c, &input, &output) 75 for i, tt := range input { 76 s.testData.OnRecord(func() { 77 output[i].ALLEGROALLEGROSQL = tt 78 output[i].Result = s.testData.ConvertEventsToStrings(tk.MustQuery(tt).Events()) 79 }) 80 tk.MustQuery(tt).Check(testkit.Events(output[i].Result...)) 81 } 82 }