Skip to content

Commit

Permalink
feat: fix error contain checks in vtgate package
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Aug 28, 2024
1 parent a54d5ec commit 5992f48
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go/test/endtoend/utils/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (mcmp *MySQLCompare) AssertContainsError(query, expected string) {
mcmp.t.Helper()
_, err := mcmp.ExecAllowAndCompareError(query, CompareOptions{})
require.Error(mcmp.t, err)
assert.Contains(mcmp.t, err.Error(), expected, "actual error: %s", err.Error())
assert.ErrorContains(mcmp.t, err, expected, "actual error: %s", err.Error())
}

// AssertMatchesNoOrder executes the given query against both Vitess and MySQL.
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func AssertContainsError(t *testing.T, conn *mysql.Conn, query, expected string)
t.Helper()
_, err := ExecAllowError(t, conn, query)
require.Error(t, err)
assert.Contains(t, err.Error(), expected, "actual error: %s", err.Error())
assert.ErrorContains(t, err, expected, "actual error: %s", err.Error())
}

// AssertMatchesNoOrder executes the given query and makes sure it matches the given `expected` string.
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/gen4/system_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestMultipleSchemaPredicates(t *testing.T) {
"where t.table_schema = '%s' and c.table_schema = '%s' and c.table_schema = '%s'", shardedKs, shardedKs, "a")
_, err = conn.ExecuteFetch(query, 1000, true)
require.Error(t, err)
require.Contains(t, err.Error(), "specifying two different database in the query is not supported")
require.ErrorContains(t, err, "specifying two different database in the query is not supported")
}

func TestQuerySystemTables(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions go/test/endtoend/vtgate/grpc_api/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func TestEffectiveCallerIDWithNoAccess(t *testing.T) {
ctx = callerid.NewContext(ctx, callerid.NewEffectiveCallerID("user_no_access", "", ""), nil)
_, err = session.Execute(ctx, query, nil)
require.Error(t, err)
assert.Contains(t, err.Error(), "Select command denied to user")
assert.Contains(t, err.Error(), "for table 'test_table' (ACL check error)")
assert.ErrorContains(t, err, "Select command denied to user")
assert.ErrorContains(t, err, "for table 'test_table' (ACL check error)")
}

// TestAuthenticatedUserWithAccess verifies that an authenticated gRPC static user with ACL access can execute queries
Expand Down Expand Up @@ -89,8 +89,8 @@ func TestAuthenticatedUserNoAccess(t *testing.T) {
query := "SELECT id FROM test_table"
_, err = session.Execute(ctx, query, nil)
require.Error(t, err)
assert.Contains(t, err.Error(), "Select command denied to user")
assert.Contains(t, err.Error(), "for table 'test_table' (ACL check error)")
assert.ErrorContains(t, err, "Select command denied to user")
assert.ErrorContains(t, err, "for table 'test_table' (ACL check error)")
}

// TestUnauthenticatedUser verifies that an unauthenticated gRPC user cannot execute queries
Expand All @@ -106,5 +106,5 @@ func TestUnauthenticatedUser(t *testing.T) {
query := "SELECT id FROM test_table"
_, err = session.Execute(ctx, query, nil)
require.Error(t, err)
assert.Contains(t, err.Error(), "invalid credentials")
assert.ErrorContains(t, err, "invalid credentials")
}
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestConsistentLookup(t *testing.T) {
mysqlErr := err.(*sqlerror.SQLError)
assert.Equal(t, sqlerror.ERDupEntry, mysqlErr.Num)
assert.Equal(t, "23000", mysqlErr.State)
assert.Contains(t, mysqlErr.Message, "reverted partial DML execution")
assert.ErrorContains(t, mysqlErr, "reverted partial DML execution")

// Simple delete.
utils.Exec(t, conn, "begin")
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func TestDescribeVindex(t *testing.T) {
mysqlErr := err.(*sqlerror.SQLError)
assert.Equal(t, sqlerror.ERNoSuchTable, mysqlErr.Num)
assert.Equal(t, "42S02", mysqlErr.State)
assert.Contains(t, mysqlErr.Message, "NotFound desc")
assert.ErrorContains(t, mysqlErr, "NotFound desc")
}

func TestEmptyQuery(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func TestMultipleSchemaPredicates(t *testing.T) {
"where t.table_schema = '%s' and c.table_schema = '%s' and c.table_schema = '%s'", keyspaceName, keyspaceName, "a")
_, err := mcmp.VtConn.ExecuteFetch(query, 1000, true)
require.Error(t, err)
require.Contains(t, err.Error(), "specifying two different database in the query is not supported")
require.ErrorContains(t, err, "specifying two different database in the query is not supported")

if utils.BinaryIsAtLeastAtVersion(20, "vtgate") {
_, _ = mcmp.ExecNoCompare("select * from information_schema.columns where table_schema = '' limit 1")
Expand Down
8 changes: 4 additions & 4 deletions go/test/endtoend/vtgate/queries/timeout/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func TestQueryTimeoutWithTables(t *testing.T) {
// the query usually takes more than 5ms to return. So this should fail.
_, err := utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ QUERY_TIMEOUT_MS=1 */ count(*) from uks.unsharded where id1 > 31")
require.Error(t, err)
assert.Contains(t, err.Error(), "context deadline exceeded")
assert.Contains(t, err.Error(), "(errno 1317) (sqlstate 70100)")
assert.ErrorContains(t, err, "context deadline exceeded")
assert.ErrorContains(t, err, "(errno 1317) (sqlstate 70100)")

// sharded
utils.Exec(t, mcmp.VtConn, "insert /*vt+ QUERY_TIMEOUT_MS=1000 */ into ks_misc.t1(id1, id2) values (1,2),(2,4),(3,6),(4,8),(5,10)")
Expand All @@ -94,8 +94,8 @@ func TestQueryTimeoutWithTables(t *testing.T) {
utils.Exec(t, mcmp.VtConn, "select /*vt+ QUERY_TIMEOUT_MS=500 */ sleep(0.1) from t1 where id1 = 1")
_, err = utils.ExecAllowError(t, mcmp.VtConn, "select /*vt+ QUERY_TIMEOUT_MS=20 */ sleep(0.1) from t1 where id1 = 1")
require.Error(t, err)
assert.Contains(t, err.Error(), "context deadline exceeded")
assert.Contains(t, err.Error(), "(errno 1317) (sqlstate 70100)")
assert.ErrorContains(t, err, "context deadline exceeded")
assert.ErrorContains(t, err, "(errno 1317) (sqlstate 70100)")
}

// TestQueryTimeoutWithShardTargeting tests the query timeout with shard targeting.
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/sequence/seq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func TestDotTableSeq(t *testing.T) {
mysqlErr := err.(*sqlerror.SQLError)
assert.Equal(t, sqlerror.ERDupEntry, mysqlErr.Num)
assert.Equal(t, "23000", mysqlErr.State)
assert.Contains(t, mysqlErr.Message, "Duplicate entry")
assert.ErrorContains(t, mysqlErr, "Duplicate entry")
}

func TestInsertAllDefaults(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/unsharded/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func TestCallProcedure(t *testing.T) {

_, err = conn.ExecuteFetch(`CALL out_parameter(@foo)`, 100, true)
require.Error(t, err)
require.Contains(t, err.Error(), "OUT and INOUT parameters are not supported")
require.ErrorContains(t, err, "OUT and INOUT parameters are not supported")
}

func TestTempTable(t *testing.T) {
Expand Down

0 comments on commit 5992f48

Please sign in to comment.