Skip to content

Commit

Permalink
Add checkfields test and fix issue
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui committed Apr 30, 2024
1 parent eaacee9 commit 08dd851
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
7 changes: 5 additions & 2 deletions go/test/endtoend/utils/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func compareVitessAndMySQLResults(t TestingT, query string, vtConn *mysql.Conn,
return errors.New(errStr)
}

var checkFeildsRegExpr = regexp.MustCompile(`(.*)(\d*)`)
var checkFeildsRegExpr = regexp.MustCompile(`([a-zA-Z]*)(\d*)`)

func checkFields(t TestingT, columnName string, vtField, myField *querypb.Field) {
t.Helper()
Expand All @@ -257,14 +257,17 @@ func checkFields(t TestingT, columnName string, vtField, myField *querypb.Field)

if len(vtMatches) != 3 || len(vtMatches) != len(myMatches) || vtMatches[1] != myMatches[1] {
fail()
return
}
vtVal, vtErr := strconv.Atoi(vtMatches[2])
myVal, myErr := strconv.Atoi(vtMatches[2])
myVal, myErr := strconv.Atoi(myMatches[2])
if vtErr != nil || myErr != nil {
fail()
return
}
if vtVal <= myVal {
fail()
return
}
}

Expand Down
42 changes: 42 additions & 0 deletions go/test/endtoend/utils/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/mysqlctl"
querypb "vitess.io/vitess/go/vt/proto/query"
)

var (
Expand Down Expand Up @@ -67,6 +68,47 @@ func TestMain(m *testing.M) {
os.Exit(exitCode)
}

func TestCheckFields(t *testing.T) {
createField := func(typ querypb.Type) *querypb.Field {
return &querypb.Field{
Type: typ,
}
}

cases := []struct {
fail bool
vtField querypb.Type
myField querypb.Type
}{
{
vtField: querypb.Type_INT32,
myField: querypb.Type_INT32,
},
{
vtField: querypb.Type_INT64,
myField: querypb.Type_INT32,
},
{
fail: true,
vtField: querypb.Type_FLOAT32,
myField: querypb.Type_INT32,
},
{
fail: true,
vtField: querypb.Type_TIMESTAMP,
myField: querypb.Type_TUPLE,
},
}

for _, c := range cases {
t.Run(fmt.Sprintf("%s_%s", c.vtField.String(), c.myField.String()), func(t *testing.T) {
tt := &testing.T{}
checkFields(tt, "col", createField(c.vtField), createField(c.myField))
require.Equal(t, c.fail, tt.Failed())
})
}
}

func TestCreateMySQL(t *testing.T) {
ctx := context.Background()
conn, err := mysql.Connect(ctx, &mysqlParams)
Expand Down

0 comments on commit 08dd851

Please sign in to comment.