Skip to content

Commit

Permalink
Merge pull request #7552 from planetscale/jg_issue7551
Browse files Browse the repository at this point in the history
Add test with NULL input values for vindexes that did not have any.
  • Loading branch information
deepthi committed Feb 27, 2021
2 parents f47f73c + e3887db commit 5778b46
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 30 deletions.
3 changes: 3 additions & 0 deletions go/vt/vtgate/vindexes/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func TestBinaryMap(t *testing.T) {
}{{
in: sqltypes.NewVarChar("test1"),
out: []byte("test1"),
}, {
in: sqltypes.NULL,
out: []byte(nil),
}, {
in: sqltypes.NewVarChar("test2"),
out: []byte("test2"),
Expand Down
16 changes: 10 additions & 6 deletions go/vt/vtgate/vindexes/binarymd5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,23 @@ func TestBinaryMD5Info(t *testing.T) {

func TestBinaryMD5Map(t *testing.T) {
tcases := []struct {
in, out string
in sqltypes.Value
out string
}{{
in: "Test",
out: "\f\xbcf\x11\xf5T\vЀ\x9a8\x8d\xc9Za[",
in: sqltypes.NewVarBinary("test1"),
out: "Z\x10^\x8b\x9d@\xe12\x97\x80\xd6.\xa2&]\x8a",
}, {
in: "TEST",
in: sqltypes.NewVarBinary("TEST"),
out: "\x03;\xd9K\x11h\xd7\xe4\xf0\xd6D\xc3\xc9^5\xbf",
}, {
in: "Test",
in: sqltypes.NULL,
out: "\xd4\x1d\x8cُ\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~",
}, {
in: sqltypes.NewVarBinary("Test"),
out: "\f\xbcf\x11\xf5T\vЀ\x9a8\x8d\xc9Za[",
}}
for _, tcase := range tcases {
got, err := binVindex.Map(nil, []sqltypes.Value{sqltypes.NewVarBinary(tcase.in)})
got, err := binVindex.Map(nil, []sqltypes.Value{tcase.in})
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 2 additions & 0 deletions go/vt/vtgate/vindexes/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestNullMap(t *testing.T) {
sqltypes.NewInt64(5),
sqltypes.NewInt64(6),
sqltypes.NewVarChar("1234567890123"),
sqltypes.NULL,
})
require.NoError(t, err)
want := []key.Destination{
Expand All @@ -63,6 +64,7 @@ func TestNullMap(t *testing.T) {
key.DestinationKeyspaceID([]byte{0}),
key.DestinationKeyspaceID([]byte{0}),
key.DestinationKeyspaceID([]byte{0}),
key.DestinationKeyspaceID([]byte{0}),
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Map(): %#v, want %+v", got, want)
Expand Down
2 changes: 2 additions & 0 deletions go/vt/vtgate/vindexes/numeric_static_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestNumericStaticMapMap(t *testing.T) {
sqltypes.NewInt64(6),
sqltypes.NewInt64(7),
sqltypes.NewInt64(8),
sqltypes.NULL,
})
require.NoError(t, err)

Expand All @@ -78,6 +79,7 @@ func TestNumericStaticMapMap(t *testing.T) {
key.DestinationKeyspaceID([]byte("\x00\x00\x00\x00\x00\x00\x00\x06")),
key.DestinationKeyspaceID([]byte("\x00\x00\x00\x00\x00\x00\x00\x07")),
key.DestinationKeyspaceID([]byte("\x00\x00\x00\x00\x00\x00\x00\x08")),
key.DestinationNone{},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Map(): %+v, want %+v", got, want)
Expand Down
2 changes: 2 additions & 0 deletions go/vt/vtgate/vindexes/numeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestNumericMap(t *testing.T) {
sqltypes.NewInt64(7),
sqltypes.NewInt64(8),
sqltypes.NewInt32(8),
sqltypes.NULL,
})
require.NoError(t, err)
want := []key.Destination{
Expand All @@ -66,6 +67,7 @@ func TestNumericMap(t *testing.T) {
key.DestinationKeyspaceID([]byte("\x00\x00\x00\x00\x00\x00\x00\x07")),
key.DestinationKeyspaceID([]byte("\x00\x00\x00\x00\x00\x00\x00\x08")),
key.DestinationKeyspaceID([]byte("\x00\x00\x00\x00\x00\x00\x00\x08")),
key.DestinationNone{},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Map(): %+v, want %+v", got, want)
Expand Down
28 changes: 16 additions & 12 deletions go/vt/vtgate/vindexes/unicodeloosemd5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,44 @@ func TestUnicodeLooseMD5Info(t *testing.T) {

func TestUnicodeLooseMD5Map(t *testing.T) {
tcases := []struct {
in, out string
in sqltypes.Value
out string
}{{
in: "Test",
in: sqltypes.NewVarBinary("Test"),
out: "\v\x01\xfdu$96\x90I\x1dd\xf1\xf5",
}, {
in: "TEST",
in: sqltypes.NewVarBinary("TEST"),
out: "\v\x01\xfdu$96\x90I\x1dd\xf1\xf5",
}, {
in: "Te\u0301st",
in: sqltypes.NewVarBinary("Te\u0301st"),
out: "\v\x01\xfdu$96\x90I\x1dd\xf1\xf5",
}, {
in: "Tést",
in: sqltypes.NewVarBinary("Tést"),
out: "\v\x01\xfdu$96\x90I\x1dd\xf1\xf5",
}, {
in: "Bést",
in: sqltypes.NewVarBinary("Bést"),
out: "²3.Os\xd0\aA\x02bIpo/\xb6",
}, {
in: "Test ",
in: sqltypes.NewVarBinary("Test "),
out: "\v\x01\xfdu$96\x90I\x1dd\xf1\xf5",
}, {
in: " Test",
in: sqltypes.NewVarBinary(" Test"),
out: "\xa2\xe3Q\\~\x8d\xf1\xff\xd2\xcc\xfc\x11Ʊ\x9d\xd1",
}, {
in: "Test\t",
in: sqltypes.NewVarBinary("Test\t"),
out: "\x82Em\xd8z\x9cz\x02\xb1\xc2\x05kZ\xba\xa2r",
}, {
in: "TéstLooong",
in: sqltypes.NewVarBinary("TéstLooong"),
out: "\x96\x83\xe1+\x80C\f\xd4S\xf5\xdfߺ\x81ɥ",
}, {
in: "T",
in: sqltypes.NewVarBinary("T"),
out: "\xac\x0f\x91y\xf5\x1d\xb8\u007f\xe8\xec\xc0\xcf@ʹz",
}, {
in: sqltypes.NULL,
out: "\xd4\x1d\x8cُ\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~",
}}
for _, tcase := range tcases {
got, err := charVindexMD5.Map(nil, []sqltypes.Value{sqltypes.NewVarBinary(tcase.in)})
got, err := charVindexMD5.Map(nil, []sqltypes.Value{tcase.in})
if err != nil {
t.Error(err)
}
Expand Down
28 changes: 16 additions & 12 deletions go/vt/vtgate/vindexes/unicodeloosexxhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,44 @@ func TestUnicodeLooseXXHashInfo(t *testing.T) {

func TestUnicodeLooseXXHashMap(t *testing.T) {
tcases := []struct {
in, out string
in sqltypes.Value
out string
}{{
in: "Test",
in: sqltypes.NewVarBinary("Test"),
out: "B\xd2\x13a\bzL\a",
}, {
in: "TEst",
in: sqltypes.NewVarBinary("TEst"),
out: "B\xd2\x13a\bzL\a",
}, {
in: "Te\u0301st",
in: sqltypes.NewVarBinary("Te\u0301st"),
out: "B\xd2\x13a\bzL\a",
}, {
in: "Tést",
in: sqltypes.NewVarBinary("Tést"),
out: "B\xd2\x13a\bzL\a",
}, {
in: "Bést",
in: sqltypes.NewVarBinary("Bést"),
out: "\x92iu\xb9\xce.\xc3\x16",
}, {
in: "Test ",
in: sqltypes.NewVarBinary("Test "),
out: "B\xd2\x13a\bzL\a",
}, {
in: " Test",
in: sqltypes.NewVarBinary(" Test"),
out: "Oˋ\xe3N\xc0Wu",
}, {
in: "Test\t",
in: sqltypes.NewVarBinary("Test\t"),
out: " \xaf\x87\xfc6\xe3\xfdQ",
}, {
in: "TéstLooong",
in: sqltypes.NewVarBinary("TéstLooong"),
out: "\xd3\xea\x879B\xb4\x84\xa7",
}, {
in: "T",
in: sqltypes.NewVarBinary("T"),
out: "\xf8\x1c;\xe2\xd5\x01\xfe\x18",
}, {
in: sqltypes.NULL,
out: "\x99\xe9\xd8Q7\xdbF\xef",
}}
for _, tcase := range tcases {
got, err := charVindexXXHash.Map(nil, []sqltypes.Value{sqltypes.NewVarBinary(tcase.in)})
got, err := charVindexXXHash.Map(nil, []sqltypes.Value{tcase.in})
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit 5778b46

Please sign in to comment.