Skip to content

Commit

Permalink
chore: use interface instead of struct for tests (vitessio#15581)
Browse files Browse the repository at this point in the history
  • Loading branch information
systay authored and timvaillancourt committed Jun 19, 2024
1 parent 0474726 commit 529c16b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
13 changes: 11 additions & 2 deletions go/test/endtoend/utils/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ import (
"vitess.io/vitess/go/test/utils"
)

type TestingT interface {
require.TestingT
Helper()
}

type MySQLCompare struct {
t *testing.T
t TestingT
MySQLConn, VtConn *mysql.Conn
}

func NewMySQLCompare(t *testing.T, vtParams, mysqlParams mysql.ConnParams) (MySQLCompare, error) {
func NewMySQLCompare(t TestingT, vtParams, mysqlParams mysql.ConnParams) (MySQLCompare, error) {
ctx := context.Background()
vtConn, err := mysql.Connect(ctx, &vtParams)
if err != nil {
Expand All @@ -54,6 +59,10 @@ func NewMySQLCompare(t *testing.T, vtParams, mysqlParams mysql.ConnParams) (MySQ
}, nil
}

func (mcmp *MySQLCompare) AsT() *testing.T {
return mcmp.t.(*testing.T)
}

func (mcmp *MySQLCompare) Close() {
mcmp.VtConn.Close()
mcmp.MySQLConn.Close()
Expand Down
8 changes: 3 additions & 5 deletions go/test/endtoend/utils/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"os"
"path"
"testing"

"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -132,7 +131,7 @@ func prepareMySQLWithSchema(params mysql.ConnParams, sql string) error {
return nil
}

func compareVitessAndMySQLResults(t *testing.T, query string, vtQr, mysqlQr *sqltypes.Result, compareColumns bool) {
func compareVitessAndMySQLResults(t TestingT, query string, vtQr, mysqlQr *sqltypes.Result, compareColumns bool) {
if vtQr == nil && mysqlQr == nil {
return
}
Expand Down Expand Up @@ -188,10 +187,9 @@ func compareVitessAndMySQLResults(t *testing.T, query string, vtQr, mysqlQr *sql
t.Error(errStr)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_vschema)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_vschema)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

t.Error undefined (type TestingT has no field or method Error)) (typecheck)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

t.Error undefined (type TestingT has no field or method Error)) (typecheck)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_gen4)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_gen4)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_transaction)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_transaction)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_readafterwrite)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_readafterwrite)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_vindex_heavy)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_vindex_heavy)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_concurrentdml)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_concurrentdml)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (13)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (13)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (mysql80)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (mysql80)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_schema_tracker)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_schema_tracker)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vttablet_prscomplex)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vttablet_prscomplex)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_queries)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_queries)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (12)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (12)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_partial_keyspace)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_partial_keyspace)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

t.Error undefined (type TestingT has no field or method Error)) (typecheck)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

t.Error undefined (type TestingT has no field or method Error)) (typecheck)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Queries)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Queries)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Queries)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Queries)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Schema)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Schema)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Schema)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Schema)

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old Vtctl

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old Vtctl

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old Vtctl

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old Vtctl

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old VTTablet

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old VTTablet

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old VTTablet

t.Error undefined (type TestingT has no field or method Error)

Check failure on line 187 in go/test/endtoend/utils/mysql.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old VTTablet

t.Error undefined (type TestingT has no field or method Error)
}

func compareVitessAndMySQLErrors(t *testing.T, vtErr, mysqlErr error) {
func compareVitessAndMySQLErrors(t TestingT, vtErr, mysqlErr error) {
if vtErr != nil && mysqlErr != nil || vtErr == nil && mysqlErr == nil {
return
}
out := fmt.Sprintf("Vitess and MySQL are not erroring the same way.\nVitess error: %v\nMySQL error: %v", vtErr, mysqlErr)
t.Error(out)
t.Errorf("Vitess and MySQL are not erroring the same way.\nVitess error: %v\nMySQL error: %v", vtErr, mysqlErr)
}
2 changes: 1 addition & 1 deletion go/test/endtoend/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func ExecCompareMySQL(t *testing.T, vtConn, mysqlConn *mysql.Conn, query string)

// ExecAllowError executes the given query without failing the test if it produces
// an error. The error is returned to the client, along with the result set.
func ExecAllowError(t *testing.T, conn *mysql.Conn, query string) (*sqltypes.Result, error) {
func ExecAllowError(t TestingT, conn *mysql.Conn, query string) (*sqltypes.Result, error) {
t.Helper()
return conn.ExecuteFetch(query, 1000, true)
}
Expand Down

0 comments on commit 529c16b

Please sign in to comment.