vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/queries/foundrows/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 foundrows
    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_found_rows"
    37  	cell            = "test_found_rows"
    38  )
    39  
    40  var (
    41  	//go:embed schema.sql
    42  	schemaSQL string
    43  
    44  	//go:embed vschema.json
    45  	vschema string
    46  )
    47  
    48  func TestMain(m *testing.M) {
    49  	defer cluster.PanicHandler(nil)
    50  	flag.Parse()
    51  
    52  	exitCode := func() int {
    53  		clusterInstance = cluster.NewCluster(cell, "localhost")
    54  		defer clusterInstance.Teardown()
    55  
    56  		// Start topo server
    57  		err := clusterInstance.StartTopo()
    58  		if err != nil {
    59  			return 1
    60  		}
    61  
    62  		// Start keyspace
    63  		keyspace := &cluster.Keyspace{
    64  			Name:      keyspaceName,
    65  			SchemaSQL: schemaSQL,
    66  			VSchema:   vschema,
    67  		}
    68  		clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"}
    69  		clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal", "--queryserver-config-schema-change-signal-interval", "0.1"}
    70  		err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false)
    71  		if err != nil {
    72  			return 1
    73  		}
    74  
    75  		clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true")
    76  		// Start vtgate
    77  		err = clusterInstance.StartVtgate()
    78  		if err != nil {
    79  			return 1
    80  		}
    81  
    82  		vtParams = clusterInstance.GetVTParams(keyspaceName)
    83  
    84  		// create mysql instance and connection parameters
    85  		conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL)
    86  		if err != nil {
    87  			fmt.Println(err)
    88  			return 1
    89  		}
    90  		defer closer()
    91  		mysqlParams = conn
    92  		return m.Run()
    93  	}()
    94  	os.Exit(exitCode)
    95  }