-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prakhar Gurunani <[email protected]>
- Loading branch information
1 parent
c5c1b0d
commit 088697b
Showing
4 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
go/test/endtoend/vtgate/queries/rowcolumncount/main_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
68 changes: 68 additions & 0 deletions
68
go/test/endtoend/vtgate/queries/rowcolumncount/rowcolumncount_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
go/test/endtoend/vtgate/queries/rowcolumncount/vschema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} | ||
} | ||
} |