Skip to content

Commit

Permalink
Update unit test framework
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Apr 17, 2024
1 parent 1f10e2a commit 96d50f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 38 deletions.
29 changes: 2 additions & 27 deletions go/vt/vttablet/tabletserver/vstreamer/helper_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"context"
"fmt"
"slices"
"strconv"
"strings"
"testing"

Expand All @@ -60,7 +59,7 @@ const (
lengthInt = 11
lengthBlob = 65535
lengthText = 262140
lengthSet = 56
lengthSet = 204 // This is the expected length of the only SET column in the test schema
)

var (
Expand Down Expand Up @@ -312,10 +311,8 @@ func (ts *TestSpec) getBindVarsForInsert(stmt sqlparser.Statement) (string, map[
v.Format(bufV)
s := bufV.String()
switch fe.cols[i].dataTypeLowered {
case "varchar", "char", "binary", "varbinary", "blob", "text":
case "varchar", "char", "binary", "varbinary", "blob", "text", "enum", "set":
s = strings.Trim(s, "'")
case "set", "enum":
s = ts.getMetadataMap(table, fe.cols[i], s)
}
bv[fe.cols[i].name] = s
}
Expand Down Expand Up @@ -530,28 +527,6 @@ func (ts *TestSpec) setMetadataMap(table, col, value string) {
ts.metadata[getMetadataKey(table, col)] = valuesReversed
}

func (ts *TestSpec) getMetadataMap(table string, col *TestColumn, value string) string {
var bits int64
value = strings.Trim(value, "'")
meta := ts.metadata[getMetadataKey(table, col.name)]
values := strings.Split(value, ",")
for _, v := range values {
v2 := strings.Trim(v, "'")
for i, m := range meta {
m2 := strings.Trim(m, "'")
if m2 == v2 {
switch col.dataTypeLowered {
case "set":
bits |= 1 << uint(i)
case "enum":
bits = int64(i) + 1
}
}
}
}
return strconv.FormatInt(bits, 10)
}

func (ts *TestSpec) getRowEvent(table string, bv map[string]string, fe *TestFieldEvent, stmt sqlparser.Statement, flags uint32) string {
ev := &binlogdatapb.RowEvent{
TableName: table,
Expand Down
15 changes: 4 additions & 11 deletions go/vt/vttablet/tabletserver/vstreamer/vstreamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,16 @@ func TestSetAndEnum(t *testing.T) {
ts := &TestSpec{
t: t,
ddls: []string{
"create table t1(id int, val binary(4), color set('red','green','blue'), size enum('S','M','L'), primary key(id))",
"create table t1(id int, val binary(4), color set('red','green','blue','black','white','pink','purple','yellow','brown'), size enum('S','M','L'), primary key(id))",
},
}
defer ts.Close()
ts.Init()
ts.tests = [][]*TestQuery{{
{"begin", nil},
{"insert into t1 values (1, 'aaa', 'red,blue', 'S')", []TestRowEvent{
{event: "type:FIELD field_event:{table_name:\"t1\" fields:{name:\"id\" type:INT32 table:\"t1\" org_table:\"t1\" database:\"vttest\" org_name:\"id\" column_length:11 charset:63 column_type:\"int\"} fields:{name:\"val\" type:BINARY table:\"t1\" org_table:\"t1\" database:\"vttest\" org_name:\"val\" column_length:4 charset:63 column_type:\"binary(4)\"} fields:{name:\"color\" type:SET table:\"t1\" org_table:\"t1\" database:\"vttest\" org_name:\"color\" column_length:56 charset:255 column_type:\"set('red','green','blue')\"} fields:{name:\"size\" type:ENUM table:\"t1\" org_table:\"t1\" database:\"vttest\" org_name:\"size\" column_length:4 charset:255 column_type:\"enum('S','M','L')\"}}"},
{event: "type:ROW row_event:{table_name:\"t1\" row_changes:{after:{lengths:1 lengths:4 lengths:8 lengths:1 values:\"1aaa\\x00red,blueS\"}}}"},
}},
{"insert into t1 values (2, 'bbb', 'green', 'M')", []TestRowEvent{
{event: "type:ROW row_event:{table_name:\"t1\" row_changes:{after:{lengths:1 lengths:4 lengths:5 lengths:1 values:\"2bbb\\x00greenM\"}}}"},
}},
{"insert into t1 values (3, 'ccc', 'red,blue,green', 'L')", []TestRowEvent{
{event: "type:ROW row_event:{table_name:\"t1\" row_changes:{after:{lengths:1 lengths:4 lengths:14 lengths:1 values:\"3ccc\\x00red,green,blueL\"}}}"},
}},
{"insert into t1 values (1, 'aaa', 'red,blue', 'S')", nil},
{"insert into t1 values (2, 'bbb', 'green,pink,purple,yellow,brown', 'M')", nil},
{"insert into t1 values (3, 'ccc', 'red,green,blue', 'L')", nil},
{"commit", nil},
}}
ts.Run()
Expand Down

0 comments on commit 96d50f5

Please sign in to comment.