From 088697b28ca760910b3cde4dbd039ad70713a528 Mon Sep 17 00:00:00 2001 From: Prakhar Gurunani Date: Wed, 15 Nov 2023 22:40:43 +0000 Subject: [PATCH] tests: use e2e Signed-off-by: Prakhar Gurunani --- .../queries/rowcolumncount/main_test.go | 97 +++++++++++++++++++ .../rowcolumncount/rowcolumncount_test.go | 68 +++++++++++++ .../vtgate/queries/rowcolumncount/schema.sql | 8 ++ .../queries/rowcolumncount/vschema.json | 18 ++++ 4 files changed, 191 insertions(+) create mode 100644 go/test/endtoend/vtgate/queries/rowcolumncount/main_test.go create mode 100644 go/test/endtoend/vtgate/queries/rowcolumncount/rowcolumncount_test.go create mode 100644 go/test/endtoend/vtgate/queries/rowcolumncount/schema.sql create mode 100644 go/test/endtoend/vtgate/queries/rowcolumncount/vschema.json diff --git a/go/test/endtoend/vtgate/queries/rowcolumncount/main_test.go b/go/test/endtoend/vtgate/queries/rowcolumncount/main_test.go new file mode 100644 index 00000000000..556ae4553c4 --- /dev/null +++ b/go/test/endtoend/vtgate/queries/rowcolumncount/main_test.go @@ -0,0 +1,97 @@ +/* +Copyright 2023 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package misc + +import ( + _ "embed" + "flag" + "fmt" + "os" + "testing" + + "vitess.io/vitess/go/test/endtoend/utils" + + "vitess.io/vitess/go/mysql" + "vitess.io/vitess/go/test/endtoend/cluster" +) + +var ( + clusterInstance *cluster.LocalProcessCluster + vtParams mysql.ConnParams + mysqlParams mysql.ConnParams + keyspaceName = "ks_col_row" + cell = "zone" + + //go:embed schema.sql + schemaSQL string + + //go:embed vschema.json + vschema string +) + +func TestMain(m *testing.M) { + defer cluster.PanicHandler(nil) + flag.Parse() + + exitCode := func() int { + clusterInstance = cluster.NewCluster(cell, "localhost") + defer clusterInstance.Teardown() + + // Start topo server + err := clusterInstance.StartTopo() + if err != nil { + return 1 + } + + clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, + "--queryserver-config-max-result-size", "1000000", + "--queryserver-config-query-timeout", "200", + "--queryserver-config-query-pool-timeout", "200") + + // Start keyspace + keyspace := &cluster.Keyspace{ + Name: keyspaceName, + SchemaSQL: schemaSQL, + VSchema: vschema, + } + err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false) + if err != nil { + return 1 + } + + clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, + "--query-timeout", "100") + // Start vtgate + err = clusterInstance.StartVtgate() + if err != nil { + return 1 + } + + vtParams = clusterInstance.GetVTParams(keyspaceName) + + // create mysql instance and connection parameters + conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL) + if err != nil { + fmt.Println(err) + return 1 + } + defer closer() + mysqlParams = conn + return m.Run() + }() + os.Exit(exitCode) +} diff --git a/go/test/endtoend/vtgate/queries/rowcolumncount/rowcolumncount_test.go b/go/test/endtoend/vtgate/queries/rowcolumncount/rowcolumncount_test.go new file mode 100644 index 00000000000..4630398eb04 --- /dev/null +++ b/go/test/endtoend/vtgate/queries/rowcolumncount/rowcolumncount_test.go @@ -0,0 +1,68 @@ +/* +Copyright 2023 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package misc + +import ( + "context" + "testing" + + _ "github.com/go-sql-driver/mysql" + "github.com/stretchr/testify/require" + "vitess.io/vitess/go/vt/vterrors" + + "vitess.io/vitess/go/mysql" + "vitess.io/vitess/go/test/endtoend/cluster" + "vitess.io/vitess/go/test/endtoend/utils" +) + +func start(t *testing.T) (*mysql.Conn, func()) { + vtConn, err := mysql.Connect(context.Background(), &vtParams) + require.NoError(t, err) + + deleteAll := func() { + tables := []string{"music", "user"} + for _, table := range tables { + utils.Exec(t, vtConn, "delete from "+table) + } + } + + deleteAll() + + return vtConn, func() { + deleteAll() + vtConn.Close() + cluster.PanicHandler(t) + } +} + +func TestExtraColLength(t *testing.T) { + vtconn, closer := start(t) + defer closer() + + _, err := utils.ExecAllowError(t, vtconn, "insert into test (one, two, three, four) values (1, 2, 3)") + + require.Equal(t, err, vterrors.VT03006()) +} + +func TestExtraRowLength(t *testing.T) { + vtconn, closer := start(t) + defer closer() + + _, err := utils.ExecAllowError(t, vtconn, "insert into test (one, two, three) values (1, 2, 3, 4)") + + require.Equal(t, err, vterrors.VT03006()) +} diff --git a/go/test/endtoend/vtgate/queries/rowcolumncount/schema.sql b/go/test/endtoend/vtgate/queries/rowcolumncount/schema.sql new file mode 100644 index 00000000000..f1c6ab5e3fd --- /dev/null +++ b/go/test/endtoend/vtgate/queries/rowcolumncount/schema.sql @@ -0,0 +1,8 @@ +create table if not exists a( + one int, + two int, + three int, + four int, + five int, + primary key(one) +) Engine=InnoDB; \ No newline at end of file diff --git a/go/test/endtoend/vtgate/queries/rowcolumncount/vschema.json b/go/test/endtoend/vtgate/queries/rowcolumncount/vschema.json new file mode 100644 index 00000000000..ed205b59953 --- /dev/null +++ b/go/test/endtoend/vtgate/queries/rowcolumncount/vschema.json @@ -0,0 +1,18 @@ +{ + "sharded": true, + "vindexes": { + "hash": { + "type": "hash" + } + }, + "tables": { + "a": { + "column_vindexes": [ + { + "column": "one", + "name": "hash" + } + ] + } + } +} \ No newline at end of file