Skip to content

Commit

Permalink
test: clean up test
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Dec 16, 2024
1 parent 1d6d4ae commit f6c0859
Showing 1 changed file with 30 additions and 112 deletions.
142 changes: 30 additions & 112 deletions go/vt/vttablet/endtoend/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ import (
func TestSimpleRead(t *testing.T) {
vstart := framework.DebugVars()
_, err := framework.NewClient().Execute("select * from vitess_test where intval=1", nil)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
vend := framework.DebugVars()
compareIntDiff(t, vend, "Queries/TotalCount", vstart, 1)
compareIntDiff(t, vend, "Queries/Histograms/Select/Count", vstart, 1)
Expand All @@ -69,15 +66,9 @@ func TestBinary(t *testing.T) {
"(4, null, null, '\\0\\'\\\"\\b\\n\\r\\t\\Z\\\\\x00\x0f\xf0\xff')",
nil,
)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
qr, err := client.Execute("select binval from vitess_test where intval=4", nil)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
want := sqltypes.Result{
Fields: []*querypb.Field{
{
Expand Down Expand Up @@ -106,18 +97,10 @@ func TestBinary(t *testing.T) {
"insert into vitess_test values(5, null, null, :bindata)",
map[string]*querypb.BindVariable{"bindata": sqltypes.StringBindVariable(binaryData)},
)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
qr, err = client.Execute("select binval from vitess_test where intval=5", nil)
if err != nil {
t.Error(err)
return
}
if !qr.Equal(&want) {
t.Errorf("Execute: \n%#v, want \n%#v", prettyPrint(*qr), prettyPrint(want))
}
require.NoError(t, err)
assert.Truef(t, qr.Equal(&want), "Execute: \n%#v, want \n%#v", prettyPrint(*qr), prettyPrint(want))
}

func TestNocacheListArgs(t *testing.T) {
Expand All @@ -130,10 +113,7 @@ func TestNocacheListArgs(t *testing.T) {
"list": sqltypes.TestBindVariable([]any{2, 3, 4}),
},
)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
assert.Equal(t, 2, len(qr.Rows))

qr, err = client.Execute(
Expand All @@ -142,10 +122,7 @@ func TestNocacheListArgs(t *testing.T) {
"list": sqltypes.TestBindVariable([]any{3, 4}),
},
)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
assert.Equal(t, 1, len(qr.Rows))

qr, err = client.Execute(
Expand All @@ -154,10 +131,7 @@ func TestNocacheListArgs(t *testing.T) {
"list": sqltypes.TestBindVariable([]any{3}),
},
)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
assert.Equal(t, 1, len(qr.Rows))

// Error case
Expand All @@ -167,21 +141,15 @@ func TestNocacheListArgs(t *testing.T) {
"list": sqltypes.TestBindVariable([]any{}),
},
)
want := "empty list supplied for list (CallerID: dev)"
if err == nil || err.Error() != want {
t.Errorf("Error: %v, want %s", err, want)
return
}
assert.EqualError(t, err, "empty list supplied for list (CallerID: dev)")
}

func TestIntegrityError(t *testing.T) {
vstart := framework.DebugVars()
client := framework.NewClient()
_, err := client.Execute("insert into vitess_test values(1, null, null, null)", nil)
want := "Duplicate entry '1'"
if err == nil || !strings.HasPrefix(err.Error(), want) {
t.Errorf("Error: %v, want prefix %s", err, want)
}
assert.ErrorContains(t, err, want)
compareIntDiff(t, framework.DebugVars(), "Errors/ALREADY_EXISTS", vstart, 1)
}

Expand All @@ -197,10 +165,7 @@ func TestTrailingComment(t *testing.T) {
"select * from vitess_test where intval=:ival /* comment1 */ /* comment2 */",
} {
_, err := client.Execute(query, bindVars)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
v2 := framework.Server.QueryPlanCacheLen()
if v2 != v1+1 {
t.Errorf("QueryEnginePlanCacheLength(%s): %d, want %d", query, v2, v1+1)
Expand All @@ -211,17 +176,11 @@ func TestTrailingComment(t *testing.T) {
func TestSchemaReload(t *testing.T) {
ctx := context.Background()
conn, err := mysql.Connect(ctx, &connParams)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
defer conn.Close()

_, err = conn.ExecuteFetch("create table vitess_temp(intval int)", 10, false)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
defer conn.ExecuteFetch("drop table vitess_temp", 10, false)

framework.Server.ReloadSchema(context.Background())
Expand All @@ -246,10 +205,7 @@ func TestSchemaReload(t *testing.T) {
func TestSidecarTables(t *testing.T) {
ctx := context.Background()
conn, err := mysql.Connect(ctx, &connParams)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
defer conn.Close()
for _, table := range []string{
"redo_state",
Expand All @@ -258,10 +214,7 @@ func TestSidecarTables(t *testing.T) {
"dt_participant",
} {
_, err = conn.ExecuteFetch(fmt.Sprintf("describe _vt.%s", table), 10, false)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
}
}

Expand Down Expand Up @@ -336,10 +289,7 @@ func TestBindInSelect(t *testing.T) {
"select :bv from dual",
map[string]*querypb.BindVariable{"bv": sqltypes.StringBindVariable("abcd")},
)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
want := &sqltypes.Result{
Fields: []*querypb.Field{{
Name: "abcd",
Expand All @@ -365,10 +315,7 @@ func TestBindInSelect(t *testing.T) {
"select :bv from dual",
map[string]*querypb.BindVariable{"bv": sqltypes.StringBindVariable("\x00\xff")},
)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
want = &sqltypes.Result{
Fields: []*querypb.Field{{
Name: "",
Expand All @@ -392,16 +339,10 @@ func TestBindInSelect(t *testing.T) {

func TestHealth(t *testing.T) {
response, err := http.Get(fmt.Sprintf("%s/debug/health", framework.ServerAddress))
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
defer response.Body.Close()
result, err := io.ReadAll(response.Body)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
if string(result) != "ok" {
t.Errorf("Health check: %s, want ok", result)
}
Expand Down Expand Up @@ -567,27 +508,18 @@ func TestDBAStatements(t *testing.T) {
client := framework.NewClient()

qr, err := client.Execute("show variables like 'version'", nil)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
wantCol := sqltypes.NewVarChar("version")
if !reflect.DeepEqual(qr.Rows[0][0], wantCol) {
t.Errorf("Execute: \n%#v, want \n%#v", qr.Rows[0][0], wantCol)
}

qr, err = client.Execute("describe vitess_a", nil)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
assert.Equal(t, 4, len(qr.Rows))

qr, err = client.Execute("explain vitess_a", nil)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
assert.Equal(t, 4, len(qr.Rows))
}

Expand Down Expand Up @@ -664,37 +596,26 @@ func TestClientFoundRows(t *testing.T) {
func TestLastInsertId(t *testing.T) {
client := framework.NewClient()
_, err := client.Execute("insert ignore into vitess_autoinc_seq SET name = 'foo', sequence = 0", nil)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
defer client.Execute("delete from vitess_autoinc_seq where name = 'foo'", nil)

if err := client.Begin(true); err != nil {
t.Fatal(err)
}
err = client.Begin(true)
require.NoError(t, err)
defer client.Rollback()

res, err := client.Execute("insert ignore into vitess_autoinc_seq SET name = 'foo', sequence = 0", nil)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

qr, err := client.Execute("update vitess_autoinc_seq set sequence=last_insert_id(sequence + 1) where name='foo'", nil)
require.NoError(t, err)

insID := res.InsertID

if want, got := insID+1, qr.InsertID; want != got {
t.Errorf("insertId mismatch; got %v, want %v", got, want)
}
assert.Equal(t, insID+1, qr.InsertID, "insertID")

qr, err = client.Execute("select sequence from vitess_autoinc_seq where name = 'foo'", nil)
require.NoError(t, err)

wantCol := sqltypes.NewUint64(insID + uint64(1))
if !reflect.DeepEqual(qr.Rows[0][0], wantCol) {
t.Errorf("Execute: \n%#v, want \n%#v", qr.Rows[0][0], wantCol)
}
assert.Truef(t, qr.Rows[0][0].Equal(wantCol), "Execute: \n%#v, want \n%#v", qr.Rows[0][0], wantCol)
}

func TestAppDebugRequest(t *testing.T) {
Expand Down Expand Up @@ -781,10 +702,7 @@ func TestSelectBooleanSystemVariables(t *testing.T) {
fmt.Sprintf("select :%s", tc.Variable),
map[string]*querypb.BindVariable{tc.Variable: sqltypes.BoolBindVariable(tc.Value)},
)
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)
require.NotEmpty(t, qr.Fields, "fields should not be empty")
require.Equal(t, tc.Type, qr.Fields[0].Type, fmt.Sprintf("invalid type, wants: %+v, but got: %+v\n", tc.Type, qr.Fields[0].Type))
}
Expand Down

0 comments on commit f6c0859

Please sign in to comment.