vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/queries/vexplain/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 vexplain
    18  
    19  import (
    20  	_ "embed"
    21  	"flag"
    22  	"os"
    23  	"testing"
    24  
    25  	"vitess.io/vitess/go/vt/vtgate/planbuilder"
    26  
    27  	"vitess.io/vitess/go/mysql"
    28  	"vitess.io/vitess/go/test/endtoend/cluster"
    29  )
    30  
    31  var (
    32  	clusterInstance *cluster.LocalProcessCluster
    33  	vtParams        mysql.ConnParams
    34  	shardedKs       = "ks"
    35  
    36  	shardedKsShards = []string{"-40", "40-80", "80-c0", "c0-"}
    37  	Cell            = "test"
    38  	//go:embed schema.sql
    39  	shardedSchemaSQL string
    40  
    41  	//go:embed vschema.json
    42  	shardedVSchema string
    43  )
    44  
    45  func TestMain(m *testing.M) {
    46  	defer cluster.PanicHandler(nil)
    47  	flag.Parse()
    48  
    49  	exitCode := func() int {
    50  		clusterInstance = cluster.NewCluster(Cell, "localhost")
    51  		defer clusterInstance.Teardown()
    52  
    53  		// Start topo server
    54  		err := clusterInstance.StartTopo()
    55  		if err != nil {
    56  			return 1
    57  		}
    58  
    59  		// Start keyspace
    60  		sKs := &cluster.Keyspace{
    61  			Name:      shardedKs,
    62  			SchemaSQL: shardedSchemaSQL,
    63  			VSchema:   shardedVSchema,
    64  		}
    65  
    66  		err = clusterInstance.StartKeyspace(*sKs, shardedKsShards, 0, false)
    67  		if err != nil {
    68  			return 1
    69  		}
    70  
    71  		// Start vtgate
    72  		clusterInstance.VtGatePlannerVersion = planbuilder.Gen4
    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  		return m.Run()
    84  	}()
    85  	os.Exit(exitCode)
    86  }