vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/queries/derived/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 misc 18 19 import ( 20 _ "embed" 21 "flag" 22 "fmt" 23 "os" 24 "testing" 25 26 "vitess.io/vitess/go/test/endtoend/utils" 27 28 "vitess.io/vitess/go/mysql" 29 "vitess.io/vitess/go/test/endtoend/cluster" 30 ) 31 32 var ( 33 clusterInstance *cluster.LocalProcessCluster 34 vtParams mysql.ConnParams 35 mysqlParams mysql.ConnParams 36 keyspaceName = "ks_derived" 37 cell = "test_derived" 38 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 clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true") 72 // Start vtgate 73 err = clusterInstance.StartVtgate() 74 if err != nil { 75 return 1 76 } 77 78 vtParams = mysql.ConnParams{ 79 Host: clusterInstance.Hostname, 80 Port: clusterInstance.VtgateMySQLPort, 81 } 82 83 // create mysql instance and connection parameters 84 conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL) 85 if err != nil { 86 fmt.Println(err) 87 return 1 88 } 89 defer closer() 90 mysqlParams = conn 91 return m.Run() 92 }() 93 os.Exit(exitCode) 94 }