From 5992f48119997e90af73e43186924abafb0d5869 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Wed, 28 Aug 2024 11:53:13 +0530 Subject: [PATCH] feat: fix error contain checks in vtgate package Signed-off-by: Manan Gupta --- go/test/endtoend/utils/cmp.go | 2 +- go/test/endtoend/utils/utils.go | 2 +- go/test/endtoend/vtgate/gen4/system_schema_test.go | 2 +- go/test/endtoend/vtgate/grpc_api/acl_test.go | 10 +++++----- go/test/endtoend/vtgate/lookup_test.go | 2 +- go/test/endtoend/vtgate/misc_test.go | 2 +- .../informationschema/informationschema_test.go | 2 +- .../endtoend/vtgate/queries/timeout/timeout_test.go | 8 ++++---- go/test/endtoend/vtgate/sequence/seq_test.go | 2 +- go/test/endtoend/vtgate/unsharded/main_test.go | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/go/test/endtoend/utils/cmp.go b/go/test/endtoend/utils/cmp.go index 32c90a27a5b..3b47e1f68dc 100644 --- a/go/test/endtoend/utils/cmp.go +++ b/go/test/endtoend/utils/cmp.go @@ -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. diff --git a/go/test/endtoend/utils/utils.go b/go/test/endtoend/utils/utils.go index 345f1e787b4..35404981164 100644 --- a/go/test/endtoend/utils/utils.go +++ b/go/test/endtoend/utils/utils.go @@ -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. diff --git a/go/test/endtoend/vtgate/gen4/system_schema_test.go b/go/test/endtoend/vtgate/gen4/system_schema_test.go index fba953d51ae..fc4983935e9 100644 --- a/go/test/endtoend/vtgate/gen4/system_schema_test.go +++ b/go/test/endtoend/vtgate/gen4/system_schema_test.go @@ -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) { diff --git a/go/test/endtoend/vtgate/grpc_api/acl_test.go b/go/test/endtoend/vtgate/grpc_api/acl_test.go index 2819a3e41d1..d0ac003169d 100644 --- a/go/test/endtoend/vtgate/grpc_api/acl_test.go +++ b/go/test/endtoend/vtgate/grpc_api/acl_test.go @@ -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 @@ -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 @@ -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") } diff --git a/go/test/endtoend/vtgate/lookup_test.go b/go/test/endtoend/vtgate/lookup_test.go index b4b53295d8d..75f4a007076 100644 --- a/go/test/endtoend/vtgate/lookup_test.go +++ b/go/test/endtoend/vtgate/lookup_test.go @@ -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") diff --git a/go/test/endtoend/vtgate/misc_test.go b/go/test/endtoend/vtgate/misc_test.go index bcb4f68a935..1c5e6a0c1b2 100644 --- a/go/test/endtoend/vtgate/misc_test.go +++ b/go/test/endtoend/vtgate/misc_test.go @@ -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) { diff --git a/go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go b/go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go index c696e7b0a9d..c5568b2db49 100644 --- a/go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go +++ b/go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go @@ -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") diff --git a/go/test/endtoend/vtgate/queries/timeout/timeout_test.go b/go/test/endtoend/vtgate/queries/timeout/timeout_test.go index d5e116e155b..09bbcf8cc96 100644 --- a/go/test/endtoend/vtgate/queries/timeout/timeout_test.go +++ b/go/test/endtoend/vtgate/queries/timeout/timeout_test.go @@ -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)") @@ -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. diff --git a/go/test/endtoend/vtgate/sequence/seq_test.go b/go/test/endtoend/vtgate/sequence/seq_test.go index dd7542becc5..1bda37094b2 100644 --- a/go/test/endtoend/vtgate/sequence/seq_test.go +++ b/go/test/endtoend/vtgate/sequence/seq_test.go @@ -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) { diff --git a/go/test/endtoend/vtgate/unsharded/main_test.go b/go/test/endtoend/vtgate/unsharded/main_test.go index 91326acce4d..e1818735ed1 100644 --- a/go/test/endtoend/vtgate/unsharded/main_test.go +++ b/go/test/endtoend/vtgate/unsharded/main_test.go @@ -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) {