vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/queries/union/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 union
    18  
    19  import (
    20  	_ "embed"
    21  	"flag"
    22  	"fmt"
    23  	"os"
    24  	"testing"
    25  
    26  	"vitess.io/vitess/go/mysql"
    27  	"vitess.io/vitess/go/test/endtoend/cluster"
    28  	"vitess.io/vitess/go/test/endtoend/utils"
    29  )
    30  
    31  var (
    32  	clusterInstance *cluster.LocalProcessCluster
    33  	vtParams        mysql.ConnParams
    34  	mysqlParams     mysql.ConnParams
    35  	keyspaceName    = "ks_union"
    36  	cell            = "test_union"
    37  
    38  	//go:embed schema.sql
    39  	schemaSQL string
    40  
    41  	//go:embed vschema.json
    42  	vschema 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  		keyspace := &cluster.Keyspace{
    61  			Name:      keyspaceName,
    62  			SchemaSQL: schemaSQL,
    63  			VSchema:   vschema,
    64  		}
    65  		clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"}
    66  		clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal", "--queryserver-config-schema-change-signal-interval", "0.1"}
    67  		err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false)
    68  		if err != nil {
    69  			return 1
    70  		}
    71  
    72  		clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true")
    73  		// Start vtgate
    74  		err = clusterInstance.StartVtgate()
    75  		if err != nil {
    76  			return 1
    77  		}
    78  
    79  		vtParams = clusterInstance.GetVTParams(keyspaceName)
    80  
    81  		// create mysql instance and connection parameters
    82  		conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL)
    83  		if err != nil {
    84  			fmt.Println(err)
    85  			return 1
    86  		}
    87  		defer closer()
    88  		mysqlParams = conn
    89  		return m.Run()
    90  	}()
    91  	os.Exit(exitCode)
    92  }