vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/queries/normalize/main_test.go (about)

     1  /*
     2  Copyright 2021 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 normalize
    18  
    19  import (
    20  	_ "embed"
    21  	"flag"
    22  	"os"
    23  	"testing"
    24  
    25  	"vitess.io/vitess/go/mysql"
    26  	"vitess.io/vitess/go/test/endtoend/cluster"
    27  )
    28  
    29  var (
    30  	clusterInstance *cluster.LocalProcessCluster
    31  	vtParams        mysql.ConnParams
    32  	keyspaceName    = "ks_normalize"
    33  	cell            = "test_normalize"
    34  
    35  	//go:embed schema.sql
    36  	schemaSQL string
    37  	//go:embed vschema.json
    38  	_ string
    39  )
    40  
    41  func TestMain(m *testing.M) {
    42  	defer cluster.PanicHandler(nil)
    43  	flag.Parse()
    44  
    45  	exitCode := func() int {
    46  		clusterInstance = cluster.NewCluster(cell, "localhost")
    47  		defer clusterInstance.Teardown()
    48  
    49  		// Start topo server
    50  		err := clusterInstance.StartTopo()
    51  		if err != nil {
    52  			return 1
    53  		}
    54  
    55  		// Start keyspace
    56  		keyspace := &cluster.Keyspace{
    57  			Name:      keyspaceName,
    58  			SchemaSQL: schemaSQL,
    59  		}
    60  		clusterInstance.VtGateExtraArgs = []string{}
    61  		clusterInstance.VtTabletExtraArgs = []string{}
    62  		err = clusterInstance.StartKeyspace(*keyspace, []string{"-"}, 1, false)
    63  		if err != nil {
    64  			return 1
    65  		}
    66  
    67  		// Start vtgate
    68  		err = clusterInstance.StartVtgate()
    69  		if err != nil {
    70  			return 1
    71  		}
    72  
    73  		vtParams = clusterInstance.GetVTParams(keyspaceName)
    74  		return m.Run()
    75  	}()
    76  	os.Exit(exitCode)
    77  }