From 18faa1eb9b91e1eb89c9dfd5be90a107a62d4503 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Mon, 21 Nov 2022 08:00:42 +0100 Subject: [PATCH] Update all the Go dependencies (#11741) * Update all the Go dependencies This seems to work for the basics just fine, so let's have CI take a run at this as well to update these. Only one small update to the Azure blob storage handling seems needed so far. Signed-off-by: Dirkjan Bussink * Use correct proto comparisons We're using `reflect.DeepEqual` or `testify` helpers that essentially use that in a number of places are comparing protobufs. This is not supported though, protobufs are not comparable with `reflect.DeepEqual`. This is exposed because of the tiny patch bump of protobuf which changes some internal optimization of how it initializes protobufs that breaks all this. Instead, move to the appropriate helpers here. Signed-off-by: Dirkjan Bussink Signed-off-by: Dirkjan Bussink --- go/sqltypes/result_test.go | 39 ++++++------ go/stats/statsd/statsd_test.go | 62 ++++++++++--------- go/vt/mysqlctl/azblobbackupstorage/azblob.go | 2 +- go/vt/vtadmin/api_test.go | 18 +++--- go/vt/vtgate/engine/limit_test.go | 60 +++++++++++------- go/vt/vtgate/executor_dml_test.go | 3 +- go/vt/vtgate/executor_test.go | 6 +- .../tabletmanager/vreplication/engine_test.go | 10 +-- .../tabletserver/connpool/dbconn_test.go | 11 ++-- .../tabletserver/health_streamer_test.go | 11 ++-- .../messager/message_manager_test.go | 12 ++-- .../tabletserver/query_executor_test.go | 14 ++--- .../tabletserver/state_manager_test.go | 2 +- 13 files changed, 132 insertions(+), 118 deletions(-) diff --git a/go/sqltypes/result_test.go b/go/sqltypes/result_test.go index c0525f8dc03..90d2eb9af65 100644 --- a/go/sqltypes/result_test.go +++ b/go/sqltypes/result_test.go @@ -17,7 +17,6 @@ limitations under the License. package sqltypes import ( - "reflect" "testing" "vitess.io/vitess/go/test/utils" @@ -31,20 +30,20 @@ func TestRepair(t *testing.T) { }, { Type: VarChar, }} - in := Result{ + in := &Result{ Rows: [][]Value{ {TestValue(VarBinary, "1"), TestValue(VarBinary, "aa")}, {TestValue(VarBinary, "2"), TestValue(VarBinary, "bb")}, }, } - want := Result{ + want := &Result{ Rows: [][]Value{ {TestValue(Int64, "1"), TestValue(VarChar, "aa")}, {TestValue(Int64, "2"), TestValue(VarChar, "bb")}, }, } in.Repair(fields) - if !reflect.DeepEqual(in, want) { + if !in.Equal(want) { t.Errorf("Repair:\n%#v, want\n%#v", in, want) } } @@ -85,7 +84,7 @@ func TestTruncate(t *testing.T) { } out := in.Truncate(0) - if !reflect.DeepEqual(out, in) { + if !out.Equal(in) { t.Errorf("Truncate(0):\n%v, want\n%v", out, in) } @@ -102,7 +101,7 @@ func TestTruncate(t *testing.T) { {TestValue(Int64, "3")}, }, } - if !reflect.DeepEqual(out, want) { + if !out.Equal(want) { t.Errorf("Truncate(1):\n%v, want\n%v", out, want) } } @@ -279,19 +278,21 @@ func TestStripMetaData(t *testing.T) { }, }} for _, tcase := range testcases { - inCopy := tcase.in.Copy() - out := inCopy.StripMetadata(tcase.includedFields) - if !reflect.DeepEqual(out, tcase.expected) { - t.Errorf("StripMetaData unexpected result for %v: %v", tcase.name, out) - } - if len(tcase.in.Fields) > 0 { - // check the out array is different than the in array. - if out.Fields[0] == inCopy.Fields[0] && tcase.includedFields != querypb.ExecuteOptions_ALL { - t.Errorf("StripMetaData modified original Field for %v", tcase.name) + t.Run(tcase.name, func(t *testing.T) { + inCopy := tcase.in.Copy() + out := inCopy.StripMetadata(tcase.includedFields) + if !out.Equal(tcase.expected) { + t.Errorf("StripMetaData unexpected result for %v: %v", tcase.name, out) + } + if len(tcase.in.Fields) > 0 { + // check the out array is different than the in array. + if out.Fields[0] == inCopy.Fields[0] && tcase.includedFields != querypb.ExecuteOptions_ALL { + t.Errorf("StripMetaData modified original Field for %v", tcase.name) + } } - } - // check we didn't change the original result. - utils.MustMatch(t, tcase.in, inCopy) + // check we didn't change the original result. + utils.MustMatch(t, tcase.in, inCopy) + }) } } @@ -340,7 +341,7 @@ func TestAppendResult(t *testing.T) { result.AppendResult(src) - if !reflect.DeepEqual(result, want) { + if !result.Equal(want) { t.Errorf("Got:\n%#v, want:\n%#v", result, want) } } diff --git a/go/stats/statsd/statsd_test.go b/go/stats/statsd/statsd_test.go index 982ad321f0e..c615da3cdfd 100644 --- a/go/stats/statsd/statsd_test.go +++ b/go/stats/statsd/statsd_test.go @@ -55,8 +55,8 @@ func TestStatsdCounter(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.counter_name:1|c" - assert.Equal(t, result, expected) + expected := "test.counter_name:1|c\n" + assert.Equal(t, expected, result) } }) if !found { @@ -84,8 +84,8 @@ func TestStatsdGauge(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.gauge_name:10.000000|g" - assert.Equal(t, result, expected) + expected := "test.gauge_name:10|g\n" + assert.Equal(t, expected, result) } }) if !found { @@ -113,8 +113,8 @@ func TestStatsdGaugeFloat64(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.gauge_name_f64:3.140000|g" - assert.Equal(t, result, expected) + expected := "test.gauge_name_f64:3.14|g\n" + assert.Equal(t, expected, result) } }) if !found { @@ -143,8 +143,8 @@ func TestStatsdGaugeFunc(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.gauge_func_name:2.000000|g" - assert.Equal(t, result, expected) + expected := "test.gauge_func_name:2|g\n" + assert.Equal(t, expected, result) } }) if !found { @@ -172,8 +172,8 @@ func TestStatsdCounterDuration(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.counter_duration_name:1.000000|ms" - assert.Equal(t, result, expected) + expected := "test.counter_duration_name:1.000000|ms\n" + assert.Equal(t, expected, result) } }) if !found { @@ -203,11 +203,12 @@ func TestStatsdCountersWithSingleLabel(t *testing.T) { result := strings.Split(string(bytes[:n]), "\n") sort.Strings(result) expected := []string{ + "", "test.counter_with_single_label_name:0|c|#label:tag2", "test.counter_with_single_label_name:2|c|#label:tag1", } for i, res := range result { - assert.Equal(t, res, expected[i]) + assert.Equal(t, expected[i], res) } } }) @@ -236,8 +237,8 @@ func TestStatsdCountersWithMultiLabels(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.counter_with_multiple_label_name:1|c|#label1:foo,label2:bar" - assert.Equal(t, result, expected) + expected := "test.counter_with_multiple_label_name:1|c|#label1:foo,label2:bar\n" + assert.Equal(t, expected, result) } }) if !found { @@ -271,11 +272,12 @@ func TestStatsdCountersFuncWithMultiLabels(t *testing.T) { result := strings.Split(string(bytes[:n]), "\n") sort.Strings(result) expected := []string{ + "", "test.counter_func_with_multiple_labels_name:1|c|#label1:foo,label2:bar", "test.counter_func_with_multiple_labels_name:2|c|#label1:bar,label2:baz", } for i, res := range result { - assert.Equal(t, res, expected[i]) + assert.Equal(t, expected[i], res) } } }) @@ -304,8 +306,8 @@ func TestStatsdGaugesWithMultiLabels(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.gauges_with_multiple_label_name:3.000000|g|#label1:foo,label2:bar" - assert.Equal(t, result, expected) + expected := "test.gauges_with_multiple_label_name:3|g|#label1:foo,label2:bar\n" + assert.Equal(t, expected, result) } }) if !found { @@ -339,11 +341,12 @@ func TestStatsdGaugesFuncWithMultiLabels(t *testing.T) { result := strings.Split(string(bytes[:n]), "\n") sort.Strings(result) expected := []string{ - "test.gauges_func_with_multiple_labels_name:1.000000|g|#label1:foo,label2:bar", - "test.gauges_func_with_multiple_labels_name:2.000000|g|#label1:bar,label2:baz", + "", + "test.gauges_func_with_multiple_labels_name:1|g|#label1:foo,label2:bar", + "test.gauges_func_with_multiple_labels_name:2|g|#label1:bar,label2:baz", } for i, res := range result { - assert.Equal(t, res, expected[i]) + assert.Equal(t, expected[i], res) } } }) @@ -372,8 +375,8 @@ func TestStatsdGaugesWithSingleLabel(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.gauges_with_single_label_name:1.000000|g|#label1:bar" - assert.Equal(t, result, expected) + expected := "test.gauges_with_single_label_name:1|g|#label1:bar\n" + assert.Equal(t, expected, result) } }) if !found { @@ -401,8 +404,8 @@ func TestStatsdMultiTimings(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.multi_timings_name:10.000000|ms|#label1:foo,label2:bar" - assert.Equal(t, result, expected) + expected := "test.multi_timings_name:10.000000|ms|#label1:foo,label2:bar\n" + assert.Equal(t, expected, result) } }) if !found { @@ -430,8 +433,8 @@ func TestStatsdTimings(t *testing.T) { t.Fatal(err) } result := string(bytes[:n]) - expected := "test.timings_name:2.000000|ms|#label1:foo" - assert.Equal(t, result, expected) + expected := "test.timings_name:2.000000|ms|#label1:foo\n" + assert.Equal(t, expected, result) } }) if !found { @@ -462,12 +465,13 @@ func TestStatsdHistogram(t *testing.T) { } result := string(bytes[:n]) expected := []string{ - "test.histogram_name:2.000000|h", - "test.histogram_name:3.000000|h", - "test.histogram_name:6.000000|h", + "test.histogram_name:2|h", + "test.histogram_name:3|h", + "test.histogram_name:6|h", + "", } for i, res := range strings.Split(result, "\n") { - assert.Equal(t, res, expected[i]) + assert.Equal(t, expected[i], res) } } }) diff --git a/go/vt/mysqlctl/azblobbackupstorage/azblob.go b/go/vt/mysqlctl/azblobbackupstorage/azblob.go index beddc33333c..660abcc5008 100644 --- a/go/vt/mysqlctl/azblobbackupstorage/azblob.go +++ b/go/vt/mysqlctl/azblobbackupstorage/azblob.go @@ -264,7 +264,7 @@ func (bh *AZBlobBackupHandle) ReadFile(ctx context.Context, filename string) (io } blobURL := containerURL.NewBlobURL(obj) - resp, err := blobURL.Download(ctx, 0, azblob.CountToEnd, azblob.BlobAccessConditions{}, false) + resp, err := blobURL.Download(ctx, 0, azblob.CountToEnd, azblob.BlobAccessConditions{}, false, azblob.ClientProvidedKeyOptions{}) if err != nil { return nil, err } diff --git a/go/vt/vtadmin/api_test.go b/go/vt/vtadmin/api_test.go index 04f758c68c0..f1c9833ca98 100644 --- a/go/vt/vtadmin/api_test.go +++ b/go/vt/vtadmin/api_test.go @@ -567,7 +567,7 @@ func TestFindSchema(t *testing.T) { } assert.NoError(t, err) - assert.Equal(t, tt.expected, resp) + assert.Truef(t, proto.Equal(tt.expected, resp), "expected %v, got %v", tt.expected, resp) }) } @@ -815,7 +815,7 @@ func TestFindSchema(t *testing.T) { } assert.NoError(t, err) - assert.Equal(t, expected, schema) + assert.Truef(t, proto.Equal(expected, schema), "expected %v, got %v", expected, schema) }) } @@ -1091,7 +1091,7 @@ func TestGetKeyspace(t *testing.T) { } assert.NoError(t, err) - assert.Equal(t, tt.expected, ks) + assert.Truef(t, proto.Equal(tt.expected, ks), "expected %v, got %v", tt.expected, ks) }, vtctlds...) }) } @@ -1575,7 +1575,7 @@ func TestGetSchema(t *testing.T) { } assert.NoError(t, err) - assert.Equal(t, tt.expected, resp) + assert.Truef(t, proto.Equal(tt.expected, resp), "expected %v, got %v", tt.expected, resp) }) }) } @@ -1742,7 +1742,7 @@ func TestGetSchema(t *testing.T) { } assert.NoError(t, err) - assert.Equal(t, expected, schema) + assert.Truef(t, proto.Equal(expected, schema), "expected %v, got %v", expected, schema) }) } @@ -2556,7 +2556,7 @@ func TestGetSchemas(t *testing.T) { } assert.NoError(t, err) - assert.ElementsMatch(t, expected.Schemas, resp.Schemas) + assert.Truef(t, proto.Equal(expected, resp), "expected: %v, got: %v", expected, resp) }) } @@ -2717,7 +2717,7 @@ func TestGetSrvVSchema(t *testing.T) { } require.NoError(t, err) - assert.Equal(t, tt.expected, resp) + assert.Truef(t, proto.Equal(tt.expected, resp), "expected %v, got %v", tt.expected, resp) }) }) } @@ -3609,7 +3609,7 @@ func TestGetVSchema(t *testing.T) { } assert.NoError(t, err) - assert.Equal(t, tt.expected, resp) + assert.Truef(t, proto.Equal(tt.expected, resp), "expected %v, got %v", tt.expected, resp) }) } } @@ -4155,7 +4155,7 @@ func TestGetWorkflow(t *testing.T) { } assert.NoError(t, err) - assert.Equal(t, tt.expected, resp) + assert.Truef(t, proto.Equal(tt.expected, resp), "expected %v, got %v", tt.expected, resp) }) } } diff --git a/go/vt/vtgate/engine/limit_test.go b/go/vt/vtgate/engine/limit_test.go index 0aacb93fe40..dcdc43880a0 100644 --- a/go/vt/vtgate/engine/limit_test.go +++ b/go/vt/vtgate/engine/limit_test.go @@ -19,7 +19,6 @@ package engine import ( "context" "errors" - "reflect" "testing" "github.com/stretchr/testify/assert" @@ -62,7 +61,7 @@ func TestLimitExecute(t *testing.T) { "a|1", "b|2", ) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n%v, want\n%v", result, wantResult) } @@ -89,7 +88,7 @@ func TestLimitExecute(t *testing.T) { result, err = l.TryExecute(context.Background(), &noopVCursor{}, bindVars, false) require.NoError(t, err) - if !reflect.DeepEqual(result, inputResult) { + if !result.Equal(inputResult) { t.Errorf("l.Execute:\n%v, want\n%v", result, wantResult) } @@ -110,7 +109,7 @@ func TestLimitExecute(t *testing.T) { result, err = l.TryExecute(context.Background(), &noopVCursor{}, bindVars, false) require.NoError(t, err) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n%v, want\n%v", result, wantResult) } @@ -136,7 +135,7 @@ func TestLimitExecute(t *testing.T) { result, err = l.TryExecute(context.Background(), &noopVCursor{}, map[string]*querypb.BindVariable{"l": sqltypes.Int64BindVariable(2)}, false) require.NoError(t, err) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n%v, want\n%v", result, wantResult) } } @@ -174,7 +173,7 @@ func TestLimitOffsetExecute(t *testing.T) { "a|1", "b|2", ) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n%v, want\n%v", result, wantResult) } @@ -205,7 +204,7 @@ func TestLimitOffsetExecute(t *testing.T) { ) result, err = l.TryExecute(context.Background(), &noopVCursor{}, bindVars, false) require.NoError(t, err) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n got %v, want\n%v", result, wantResult) } @@ -235,7 +234,7 @@ func TestLimitOffsetExecute(t *testing.T) { ) result, err = l.TryExecute(context.Background(), &noopVCursor{}, bindVars, false) require.NoError(t, err) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n got %v, want\n%v", result, wantResult) } @@ -266,7 +265,7 @@ func TestLimitOffsetExecute(t *testing.T) { ) result, err = l.TryExecute(context.Background(), &noopVCursor{}, bindVars, false) require.NoError(t, err) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n got %v, want\n%v", result, wantResult) } @@ -295,7 +294,7 @@ func TestLimitOffsetExecute(t *testing.T) { ) result, err = l.TryExecute(context.Background(), &noopVCursor{}, bindVars, false) require.NoError(t, err) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n got %v, want\n%v", result, wantResult) } @@ -323,7 +322,7 @@ func TestLimitOffsetExecute(t *testing.T) { ) result, err = l.TryExecute(context.Background(), &noopVCursor{}, bindVars, false) require.NoError(t, err) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n got %v, want\n%v", result, wantResult) } @@ -349,7 +348,7 @@ func TestLimitOffsetExecute(t *testing.T) { } result, err = l.TryExecute(context.Background(), &noopVCursor{}, map[string]*querypb.BindVariable{"l": sqltypes.Int64BindVariable(1), "o": sqltypes.Int64BindVariable(1)}, false) require.NoError(t, err) - if !reflect.DeepEqual(result, wantResult) { + if !result.Equal(wantResult) { t.Errorf("l.Execute:\n got %v, want\n%v", result, wantResult) } } @@ -387,8 +386,11 @@ func TestLimitStreamExecute(t *testing.T) { "a|1", "b|2", ) - if !reflect.DeepEqual(results, wantResults) { - t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + require.Len(t, results, len(wantResults)) + for i, result := range results { + if !result.Equal(wantResults[i]) { + t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + } } // Test with bind vars. @@ -400,8 +402,11 @@ func TestLimitStreamExecute(t *testing.T) { return nil }) require.NoError(t, err) - if !reflect.DeepEqual(results, wantResults) { - t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + require.Len(t, results, len(wantResults)) + for i, result := range results { + if !result.Equal(wantResults[i]) { + t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + } } // Test with limit equal to input @@ -420,8 +425,11 @@ func TestLimitStreamExecute(t *testing.T) { "---", "c|3", ) - if !reflect.DeepEqual(results, wantResults) { - t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + require.Len(t, results, len(wantResults)) + for i, result := range results { + if !result.Equal(wantResults[i]) { + t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + } } // Test with limit higher than input. @@ -434,8 +442,11 @@ func TestLimitStreamExecute(t *testing.T) { }) require.NoError(t, err) // wantResults is same as before. - if !reflect.DeepEqual(results, wantResults) { - t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + require.Len(t, results, len(wantResults)) + for i, result := range results { + if !result.Equal(wantResults[i]) { + t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + } } } @@ -477,8 +488,11 @@ func TestOffsetStreamExecute(t *testing.T) { "---", "e|5", ) - if !reflect.DeepEqual(results, wantResults) { - t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + require.Len(t, results, len(wantResults)) + for i, result := range results { + if !result.Equal(wantResults[i]) { + t.Errorf("l.StreamExecute:\n%s, want\n%s", sqltypes.PrintResults(results), sqltypes.PrintResults(wantResults)) + } } } @@ -495,7 +509,7 @@ func TestLimitGetFields(t *testing.T) { got, err := l.GetFields(context.Background(), nil, nil) require.NoError(t, err) - if !reflect.DeepEqual(got, result) { + if !got.Equal(result) { t.Errorf("l.GetFields:\n%v, want\n%v", got, result) } } diff --git a/go/vt/vtgate/executor_dml_test.go b/go/vt/vtgate/executor_dml_test.go index 05fcb59255d..983450c83cd 100644 --- a/go/vt/vtgate/executor_dml_test.go +++ b/go/vt/vtgate/executor_dml_test.go @@ -19,7 +19,6 @@ package vtgate import ( "context" "fmt" - "reflect" "strings" "testing" @@ -1165,7 +1164,7 @@ func TestInsertShardedIgnore(t *testing.T) { query = "insert ignore into insert_ignore_test(pv, owned, verify) values (1, 1, 1)" qr, err := executorExec(executor, query, nil) require.NoError(t, err) - if !reflect.DeepEqual(qr, &sqltypes.Result{}) { + if !qr.Equal(&sqltypes.Result{}) { t.Errorf("qr: %v, want empty result", qr) } assertQueries(t, sbc1, nil) diff --git a/go/vt/vtgate/executor_test.go b/go/vt/vtgate/executor_test.go index 6e80f3841aa..32121c37c79 100644 --- a/go/vt/vtgate/executor_test.go +++ b/go/vt/vtgate/executor_test.go @@ -1110,7 +1110,7 @@ func TestExecutorComment(t *testing.T) { if err != nil { t.Error(err) } - if !reflect.DeepEqual(gotResult, wantResult) { + if !gotResult.Equal(wantResult) { t.Errorf("Exec %s: %v, want %v", stmt, gotResult, wantResult) } } @@ -1453,9 +1453,7 @@ func TestExecutorCreateVindexDDL(t *testing.T) { sbc2.ExecCount.Get(), sbclookup.ExecCount.Get(), } - if !reflect.DeepEqual(gotCount, wantCount) { - t.Errorf("Exec %s: %v, want %v", stmt, gotCount, wantCount) - } + require.Equal(t, wantCount, gotCount) } func TestExecutorAddDropVschemaTableDDL(t *testing.T) { diff --git a/go/vt/vttablet/tabletmanager/vreplication/engine_test.go b/go/vt/vttablet/tabletmanager/vreplication/engine_test.go index 4c57f21dca1..66ca9213e26 100644 --- a/go/vt/vttablet/tabletmanager/vreplication/engine_test.go +++ b/go/vt/vttablet/tabletmanager/vreplication/engine_test.go @@ -175,7 +175,7 @@ func TestEngineExec(t *testing.T) { t.Fatal(err) } wantqr := &sqltypes.Result{InsertID: 1} - if !reflect.DeepEqual(qr, wantqr) { + if !qr.Equal(wantqr) { t.Errorf("Exec: %v, want %v", qr, wantqr) } dbClient.Wait() @@ -217,7 +217,7 @@ func TestEngineExec(t *testing.T) { t.Fatal(err) } wantqr = &sqltypes.Result{RowsAffected: 1} - if !reflect.DeepEqual(qr, wantqr) { + if !qr.Equal(wantqr) { t.Errorf("Exec: %v, want %v", qr, wantqr) } dbClient.Wait() @@ -257,7 +257,7 @@ func TestEngineExec(t *testing.T) { t.Fatal(err) } wantqr = &sqltypes.Result{RowsAffected: 1} - if !reflect.DeepEqual(qr, wantqr) { + if !qr.Equal(wantqr) { t.Errorf("Exec: %v, want %v", qr, wantqr) } dbClient.Wait() @@ -355,7 +355,7 @@ func TestEngineSelect(t *testing.T) { if err != nil { t.Fatal(err) } - if !reflect.DeepEqual(qr, wantResult) { + if !qr.Equal(wantResult) { t.Errorf("Exec: %v, want %v", qr, wantResult) } } @@ -558,7 +558,7 @@ func TestCreateDBAndTable(t *testing.T) { t.Fatal(err) } wantqr := &sqltypes.Result{InsertID: 1} - if !reflect.DeepEqual(qr, wantqr) { + if !qr.Equal(wantqr) { t.Errorf("Exec: %v, want %v", qr, wantqr) } dbClient.Wait() diff --git a/go/vt/vttablet/tabletserver/connpool/dbconn_test.go b/go/vt/vttablet/tabletserver/connpool/dbconn_test.go index 5b0401621c0..62ec0b6d12e 100644 --- a/go/vt/vttablet/tabletserver/connpool/dbconn_test.go +++ b/go/vt/vttablet/tabletserver/connpool/dbconn_test.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "reflect" "strings" "testing" "time" @@ -79,7 +78,7 @@ func TestDBConnExec(t *testing.T) { t.Fatalf("should not get an error, err: %v", err) } expectedResult.Fields = nil - if !reflect.DeepEqual(expectedResult, result) { + if !expectedResult.Equal(result) { t.Errorf("Exec: %v, want %v", expectedResult, result) } @@ -152,7 +151,7 @@ func TestDBConnExecLost(t *testing.T) { t.Fatalf("should not get an error, err: %v", err) } expectedResult.Fields = nil - if !reflect.DeepEqual(expectedResult, result) { + if !expectedResult.Equal(result) { t.Errorf("Exec: %v, want %v", expectedResult, result) } @@ -226,7 +225,7 @@ func TestDBConnDeadline(t *testing.T) { t.Fatalf("should not get an error, err: %v", err) } expectedResult.Fields = nil - if !reflect.DeepEqual(expectedResult, result) { + if !expectedResult.Equal(result) { t.Errorf("Exec: %v, want %v", expectedResult, result) } @@ -240,7 +239,7 @@ func TestDBConnDeadline(t *testing.T) { t.Fatalf("should not get an error, err: %v", err) } expectedResult.Fields = nil - if !reflect.DeepEqual(expectedResult, result) { + if !expectedResult.Equal(result) { t.Errorf("Exec: %v, want %v", expectedResult, result) } @@ -405,7 +404,7 @@ func TestDBConnStream(t *testing.T) { if err != nil { t.Fatalf("should not get an error, err: %v", err) } - if !reflect.DeepEqual(expectedResult, &result) { + if !expectedResult.Equal(&result) { t.Errorf("Exec: %v, want %v", expectedResult, &result) } // Stream fail diff --git a/go/vt/vttablet/tabletserver/health_streamer_test.go b/go/vt/vttablet/tabletserver/health_streamer_test.go index 443dc4fafbf..a3c69432f9f 100644 --- a/go/vt/vttablet/tabletserver/health_streamer_test.go +++ b/go/vt/vttablet/tabletserver/health_streamer_test.go @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/mysql/fakesqldb" @@ -116,7 +117,7 @@ func TestHealthStreamerBroadcast(t *testing.T) { HealthError: "tabletserver uninitialized", }, } - assert.Equal(t, want, shr) + assert.Truef(t, proto.Equal(want, shr), "want: %v, got: %v", want, shr) hs.ChangeState(topodatapb.TabletType_REPLICA, time.Time{}, 0, nil, false) shr = <-ch @@ -130,7 +131,7 @@ func TestHealthStreamerBroadcast(t *testing.T) { BinlogPlayersCount: 2, }, } - assert.Equal(t, want, shr) + assert.Truef(t, proto.Equal(want, shr), "want: %v, got: %v", want, shr) // Test primary and timestamp. now := time.Now() @@ -148,7 +149,7 @@ func TestHealthStreamerBroadcast(t *testing.T) { BinlogPlayersCount: 2, }, } - assert.Equal(t, want, shr) + assert.Truef(t, proto.Equal(want, shr), "want: %v, got: %v", want, shr) // Test non-serving, and 0 timestamp for non-primary. hs.ChangeState(topodatapb.TabletType_REPLICA, now, 1*time.Second, nil, false) @@ -164,7 +165,7 @@ func TestHealthStreamerBroadcast(t *testing.T) { BinlogPlayersCount: 2, }, } - assert.Equal(t, want, shr) + assert.Truef(t, proto.Equal(want, shr), "want: %v, got: %v", want, shr) // Test Health error. hs.ChangeState(topodatapb.TabletType_REPLICA, now, 0, errors.New("repl err"), false) @@ -180,7 +181,7 @@ func TestHealthStreamerBroadcast(t *testing.T) { BinlogPlayersCount: 2, }, } - assert.Equal(t, want, shr) + assert.Truef(t, proto.Equal(want, shr), "want: %v, got: %v", want, shr) } func TestReloadSchema(t *testing.T) { diff --git a/go/vt/vttablet/tabletserver/messager/message_manager_test.go b/go/vt/vttablet/tabletserver/messager/message_manager_test.go index a6158906e5a..28ea5b0a38a 100644 --- a/go/vt/vttablet/tabletserver/messager/message_manager_test.go +++ b/go/vt/vttablet/tabletserver/messager/message_manager_test.go @@ -216,7 +216,7 @@ func TestMessageManagerSend(t *testing.T) { want := &sqltypes.Result{ Fields: testFields, } - if got := <-r1.ch; !reflect.DeepEqual(got, want) { + if got := <-r1.ch; !got.Equal(want) { t.Errorf("Received: %v, want %v", got, want) } // Set the channel to verify call to Postpone. @@ -230,7 +230,7 @@ func TestMessageManagerSend(t *testing.T) { sqltypes.NULL, }}, } - if got := <-r1.ch; !reflect.DeepEqual(got, want) { + if got := <-r1.ch; !got.Equal(want) { t.Errorf("Received: %v, want %v", got, want) } @@ -415,7 +415,7 @@ func TestMessageManagerBatchSend(t *testing.T) { sqltypes.NULL, }}, } - if got := <-r1.ch; !reflect.DeepEqual(got, want) { + if got := <-r1.ch; !got.Equal(want) { t.Errorf("Received: %v, want %v", got, row1) } mm.mu.Lock() @@ -432,7 +432,7 @@ func TestMessageManagerBatchSend(t *testing.T) { sqltypes.NULL, }}, } - if got := <-r1.ch; !reflect.DeepEqual(got, want) { + if got := <-r1.ch; !got.Equal(want) { t.Errorf("Received: %+v, want %+v", got, row1) } } @@ -481,7 +481,7 @@ func TestMessageManagerStreamerSimple(t *testing.T) { sqltypes.NewVarBinary("1"), }}, } - if got := <-r1.ch; !reflect.DeepEqual(got, want) { + if got := <-r1.ch; !got.Equal(want) { t.Errorf("Received: %v, want %v", got, want) } } @@ -569,7 +569,7 @@ func TestMessageManagerStreamerAndPoller(t *testing.T) { sqltypes.NewVarBinary("3"), }}, } - if got := <-r1.ch; !reflect.DeepEqual(got, want) { + if got := <-r1.ch; !got.Equal(want) { t.Errorf("Received: %v, want %v", got, want) } } diff --git a/go/vt/vttablet/tabletserver/query_executor_test.go b/go/vt/vttablet/tabletserver/query_executor_test.go index 526419c4f49..e8e96614443 100644 --- a/go/vt/vttablet/tabletserver/query_executor_test.go +++ b/go/vt/vttablet/tabletserver/query_executor_test.go @@ -17,17 +17,15 @@ limitations under the License. package tabletserver import ( + "context" "fmt" "io" "math/rand" - "reflect" "strings" "testing" "vitess.io/vitess/go/vt/vttablet/tabletserver/tx" - "context" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -686,7 +684,7 @@ func TestQueryExecutorPlanNextval(t *testing.T) { sqltypes.NewInt64(2), }}, } - if !reflect.DeepEqual(got, want) { + if !got.Equal(want) { t.Fatalf("qre.Execute() =\n%#v, want:\n%#v", got, want) } @@ -718,7 +716,7 @@ func TestQueryExecutorPlanNextval(t *testing.T) { sqltypes.NewInt64(3), }}, } - if !reflect.DeepEqual(got, want) { + if !got.Equal(want) { t.Fatalf("qre.Execute() =\n%#v, want:\n%#v", got, want) } @@ -750,7 +748,7 @@ func TestQueryExecutorPlanNextval(t *testing.T) { sqltypes.NewInt64(5), }}, } - if !reflect.DeepEqual(got, want) { + if !got.Equal(want) { t.Fatalf("qre.Execute() =\n%#v, want:\n%#v", got, want) } } @@ -857,7 +855,7 @@ func TestQueryExecutorTableAcl(t *testing.T) { if err != nil { t.Fatalf("got: %v, want nil", err) } - if !reflect.DeepEqual(got, want) { + if !got.Equal(want) { t.Fatalf("qre.Execute() = %v, want: %v", got, want) } } @@ -901,7 +899,7 @@ func TestQueryExecutorTableAclNoPermission(t *testing.T) { if err != nil { t.Fatalf("got: %v, want nil", err) } - if !reflect.DeepEqual(got, want) { + if !got.Equal(want) { t.Fatalf("qre.Execute() = %v, want: %v", got, want) } tsv.StopService() diff --git a/go/vt/vttablet/tabletserver/state_manager_test.go b/go/vt/vttablet/tabletserver/state_manager_test.go index bb809d5b142..efe57e737cb 100644 --- a/go/vt/vttablet/tabletserver/state_manager_test.go +++ b/go/vt/vttablet/tabletserver/state_manager_test.go @@ -639,7 +639,7 @@ func TestStateManagerNotify(t *testing.T) { TabletAlias: &topodatapb.TabletAlias{}, } sm.hcticks.Stop() - assert.Equal(t, wantshr, gotshr) + assert.Truef(t, proto.Equal(gotshr, wantshr), "got: %v, want: %v", gotshr, wantshr) sm.StopService() }