vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/sec_vind/main_test.go (about) 1 /* 2 Copyright 2022 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package vtgate 18 19 import ( 20 "context" 21 _ "embed" 22 "flag" 23 "os" 24 "testing" 25 26 "vitess.io/vitess/go/test/endtoend/utils" 27 28 "github.com/stretchr/testify/require" 29 30 "vitess.io/vitess/go/mysql" 31 "vitess.io/vitess/go/test/endtoend/cluster" 32 ) 33 34 var ( 35 clusterInstance *cluster.LocalProcessCluster 36 vtParams mysql.ConnParams 37 KeyspaceName = "ks" 38 Cell = "test" 39 //go:embed schema.sql 40 SchemaSQL string 41 42 //go:embed vschema.json 43 VSchema string 44 ) 45 46 func TestMain(m *testing.M) { 47 defer cluster.PanicHandler(nil) 48 flag.Parse() 49 50 exitCode := func() int { 51 clusterInstance = cluster.NewCluster(Cell, "localhost") 52 defer clusterInstance.Teardown() 53 54 // Start topo server 55 err := clusterInstance.StartTopo() 56 if err != nil { 57 return 1 58 } 59 60 // Start keyspace 61 keyspace := &cluster.Keyspace{ 62 Name: KeyspaceName, 63 SchemaSQL: SchemaSQL, 64 VSchema: VSchema, 65 } 66 err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false) 67 if err != nil { 68 return 1 69 } 70 71 // Start vtgate 72 err = clusterInstance.StartVtgate() 73 if err != nil { 74 return 1 75 } 76 vtParams = mysql.ConnParams{ 77 Host: clusterInstance.Hostname, 78 Port: clusterInstance.VtgateMySQLPort, 79 } 80 return m.Run() 81 }() 82 os.Exit(exitCode) 83 } 84 85 func start(t *testing.T) (*mysql.Conn, func()) { 86 ctx := context.Background() 87 conn, err := mysql.Connect(ctx, &vtParams) 88 require.Nil(t, err) 89 90 deleteAll := func() { 91 _, _ = utils.ExecAllowError(t, conn, "set workload = oltp") 92 93 tables := []string{"t1", "lookup_t1"} 94 for _, table := range tables { 95 _, _ = utils.ExecAllowError(t, conn, "delete from "+table) 96 } 97 } 98 99 deleteAll() 100 101 return conn, func() { 102 deleteAll() 103 conn.Close() 104 cluster.PanicHandler(t) 105 } 106 } 107 108 func TestInAgainstSecondaryVindex(t *testing.T) { 109 conn, closer := start(t) 110 defer closer() 111 112 utils.AssertMatches(t, conn, `select 1 from t1 where c2 in ("abc")`, "[]") 113 }