Skip to content

Commit

Permalink
tests: use e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Prakhar Gurunani <[email protected]>
  • Loading branch information
FirePing32 committed Nov 15, 2023
1 parent c5c1b0d commit 088697b
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 0 deletions.
97 changes: 97 additions & 0 deletions go/test/endtoend/vtgate/queries/rowcolumncount/main_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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())
}
8 changes: 8 additions & 0 deletions go/test/endtoend/vtgate/queries/rowcolumncount/schema.sql
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 18 additions & 0 deletions go/test/endtoend/vtgate/queries/rowcolumncount/vschema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sharded": true,
"vindexes": {
"hash": {
"type": "hash"
}
},
"tables": {
"a": {
"column_vindexes": [
{
"column": "one",
"name": "hash"
}
]
}
}
}

0 comments on commit 088697b

Please sign in to comment.