Skip to content

Commit

Permalink
Simplify tests and regen code
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Jan 7, 2025
1 parent 72e2e1e commit c6f615c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions go/test/endtoend/utils/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ func (mcmp *MySQLCompare) Exec(query string) *sqltypes.Result {
return vtQr
}

// ExecVitessAndMySQL executes Vitess and MySQL with the queries provided.
func (mcmp *MySQLCompare) ExecVitessAndMySQL(vtQ, mQ string) *sqltypes.Result {
// ExecVitessAndMySQLDifferentQueries executes Vitess and MySQL with the queries provided.
func (mcmp *MySQLCompare) ExecVitessAndMySQLDifferentQueries(vtQ, mQ string) *sqltypes.Result {
mcmp.t.Helper()
vtQr, err := mcmp.VtConn.ExecuteFetch(vtQ, 1000, true)
require.NoError(mcmp.t, err, "[Vitess Error] for query: "+vtQ)
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/plan_tests/plan_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestE2ECases(t *testing.T) {
require.NoError(mcmp.AsT(), err)
sqlparser.RemoveKeyspaceIgnoreSysSchema(stmt)

mcmp.ExecVitessAndMySQL(test.Query, sqlparser.String(stmt))
mcmp.ExecVitessAndMySQLDifferentQueries(test.Query, sqlparser.String(stmt))
pd := utils.ExecTrace(mcmp.AsT(), mcmp.VtConn, test.Query)
verifyTestExpectations(mcmp.AsT(), pd, test)
if mcmp.VtConn.IsClosed() {
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/queries/misc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestMain(m *testing.M) {
vtParams = clusterInstance.GetVTParams(keyspaceName)

// create mysql instance and connection parameters
conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL)
conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL, uschemaSQL)
if err != nil {
fmt.Println(err)
return 1
Expand Down
23 changes: 13 additions & 10 deletions go/test/endtoend/vtgate/queries/misc/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/vt/sqlparser"

_ "github.com/go-sql-driver/mysql"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -189,7 +190,6 @@ func TestSetAndGetLastInsertID(t *testing.T) {
}

func TestSetAndGetLastInsertIDWithInsertUnsharded(t *testing.T) {
// in this test we can't use the mcmp, so we need to assert the returned values manually
mcmp, closer := start(t)
defer closer()

Expand All @@ -206,13 +206,16 @@ func TestSetAndGetLastInsertIDWithInsertUnsharded(t *testing.T) {

runTests := func(mcmp *utils.MySQLCompare) {
for _, test := range tests {

lastInsertID := getVal()
query := fmt.Sprintf(test, lastInsertID)
utils.Exec(mcmp.AsT(), mcmp.VtConn, query)
result := utils.Exec(mcmp.AsT(), mcmp.VtConn, "select last_insert_id()")
uintVal, err := result.Rows[0][0].ToCastUint64()

stmt, err := sqlparser.NewTestParser().Parse(query)
require.NoError(mcmp.AsT(), err)
require.EqualValues(mcmp.AsT(), lastInsertID, uintVal, query)
sqlparser.RemoveKeyspaceIgnoreSysSchema(stmt)

mcmp.ExecVitessAndMySQLDifferentQueries(query, sqlparser.String(stmt))
mcmp.Exec("select last_insert_id()")
}
}

Expand All @@ -230,11 +233,11 @@ func TestSetAndGetLastInsertIDWithInsertUnsharded(t *testing.T) {
}

// Now test to set the last insert id to 0, see that it has changed correctly even if the value is 0
utils.Exec(t, mcmp.VtConn, "insert into uks.unsharded(id1, id2) values (last_insert_id(0),12)")
result := utils.Exec(t, mcmp.VtConn, "select last_insert_id()")
uintVal, err := result.Rows[0][0].ToCastUint64()
require.NoError(t, err)
require.Zero(t, uintVal)
mcmp.ExecVitessAndMySQLDifferentQueries(
"insert into uks.unsharded(id1, id2) values (last_insert_id(0),12)",
"insert into unsharded(id1, id2) values (last_insert_id(0),12)",
)
mcmp.Exec("select last_insert_id()")
}

func TestSetAndGetLastInsertIDWithInsert(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions go/vt/sqlparser/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,3 +917,11 @@ func TestCloneComments(t *testing.T) {
assert.Equal(t, "b", val)
}
}

func TestRemoveKeyspace(t *testing.T) {
stmt, err := NewTestParser().Parse("select 1 from uks.unsharded")
require.NoError(t, err)
RemoveKeyspaceIgnoreSysSchema(stmt)

require.Equal(t, "select 1 from unsharded", String(stmt))
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/engine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c6f615c

Please sign in to comment.