-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Replace t.fatalf with testify require #16038
Changes from 1 commit
e0eee4f
6b67e76
91d9c25
4239566
3c10f00
6b4b485
e03a735
49876f3
ccdc5f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,11 +62,11 @@ func TestRegisterService(t *testing.T) { | |
closer := StartTracing(serviceName) | ||
tracer, ok := closer.(*fakeTracer) | ||
if !ok { | ||
t.Fatalf("did not get the expected tracer, got %+v (%T)", tracer, tracer) | ||
require.FailNow(t, fmt.Sprintf("did not get the expected tracer, got %+v (%T)", tracer, tracer)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we replace this |
||
} | ||
|
||
if tracer.name != serviceName { | ||
t.Fatalf("expected the name to be `%v` but it was `%v`", serviceName, tracer.name) | ||
require.FailNow(t, fmt.Sprintf("expected the name to be `%v` but it was `%v`", serviceName, tracer.name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we replace with |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ import ( | |
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"vitess.io/vitess/go/mysql" | ||
"vitess.io/vitess/go/mysql/binlog" | ||
"vitess.io/vitess/go/mysql/collations" | ||
|
@@ -519,17 +521,12 @@ func TestStreamerParseRBRNameEscapes(t *testing.T) { | |
|
||
go sendTestEvents(events, input) | ||
_, err := bls.parseEvents(context.Background(), events, errs) | ||
if err != ErrServerEOF { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
require.Equal(t, ErrServerEOF, err, "unexpected error: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use |
||
|
||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("binlogConnStreamer.parseEvents(): got:\n%+v\nwant:\n%+v", got, want) | ||
for i, fbt := range got { | ||
t.Errorf("Got (%v)=%v", i, fbt.statements) | ||
} | ||
for i, fbt := range want { | ||
t.Errorf("Want(%v)=%v", i, fbt.statements) | ||
} | ||
assert.True(t, reflect.DeepEqual(got, want), "binlogConnStreamer.parseEvents(): got:\n%+v\nwant:\n%+v", got, want) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
for i, fbt := range got { | ||
assert.Equal(t, fbt.statements, want[i].statements, "Got (%v)=%v, want (%v)=%v", i, fbt.statements, i, want[i].statements) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems superfluous given we've validated the equality of the entire slice, above? |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" | ||
querypb "vitess.io/vitess/go/vt/proto/query" | ||
) | ||
|
@@ -60,9 +61,7 @@ func TestTablesFilterPass(t *testing.T) { | |
}) | ||
_ = f(eventToken, statements) | ||
want := `statement: <6, "set1"> statement: <7, "dml1 /* _stream included1 (id ) (500 ); */"> statement: <7, "dml2 /* _stream included2 (id ) (500 ); */"> position: "MariaDB/0-41983-1" ` | ||
if want != got { | ||
t.Errorf("want\n%s, got\n%s", want, got) | ||
} | ||
assert.Equal(t, want, got, "binlogConnStreamer.tablesFilterFunc(): got:\n%+v\nwant:\n%+v", got, want) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove the |
||
} | ||
|
||
func TestTablesFilterSkip(t *testing.T) { | ||
|
@@ -90,9 +89,7 @@ func TestTablesFilterSkip(t *testing.T) { | |
}) | ||
_ = f(eventToken, statements) | ||
want := `position: "MariaDB/0-41983-1" ` | ||
if want != got { | ||
t.Errorf("want %s, got %s", want, got) | ||
} | ||
assert.Equal(t, want, got, "binlogConnStreamer.tablesFilterFunc(): got:\n%+v\nwant:\n%+v", got, want) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove the |
||
} | ||
|
||
func TestTablesFilterDDL(t *testing.T) { | ||
|
@@ -120,9 +117,7 @@ func TestTablesFilterDDL(t *testing.T) { | |
}) | ||
_ = f(eventToken, statements) | ||
want := `position: "MariaDB/0-41983-1" ` | ||
if want != got { | ||
t.Errorf("want %s, got %s", want, got) | ||
} | ||
assert.Equal(t, want, got, "binlogConnStreamer.tablesFilterFunc(): got:\n%+v\nwant:\n%+v", got, want) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove the |
||
} | ||
|
||
func TestTablesFilterMalformed(t *testing.T) { | ||
|
@@ -156,9 +151,7 @@ func TestTablesFilterMalformed(t *testing.T) { | |
}) | ||
_ = f(eventToken, statements) | ||
want := `position: "MariaDB/0-41983-1" ` | ||
if want != got { | ||
t.Errorf("want %s, got %s", want, got) | ||
} | ||
assert.Equal(t, want, got, "binlogConnStreamer.tablesFilterFunc(): got:\n%+v\nwant:\n%+v", got, want) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove the |
||
} | ||
|
||
func bltToString(tx *binlogdatapb.BinlogTransaction) string { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,9 @@ package wrangler | |
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"vitess.io/vitess/go/vt/logutil" | ||
topodatapb "vitess.io/vitess/go/vt/proto/topodata" | ||
"vitess.io/vitess/go/vt/topo" | ||
|
@@ -48,20 +48,14 @@ func TestInitTabletShardConversion(t *testing.T) { | |
Shard: "80-C0", | ||
} | ||
|
||
if err := wr.TopoServer().InitTablet(context.Background(), tablet, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/); err != nil { | ||
t.Fatalf("InitTablet failed: %v", err) | ||
} | ||
err := wr.TopoServer().InitTablet(context.Background(), tablet, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/) | ||
require.NoError(t, err, "InitTablet failed") | ||
Ari1009 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ti, err := ts.GetTablet(context.Background(), tablet.Alias) | ||
if err != nil { | ||
t.Fatalf("GetTablet failed: %v", err) | ||
} | ||
if ti.Shard != "80-c0" { | ||
t.Errorf("Got wrong tablet.Shard, got %v expected 80-c0", ti.Shard) | ||
} | ||
if string(ti.KeyRange.Start) != "\x80" || string(ti.KeyRange.End) != "\xc0" { | ||
t.Errorf("Got wrong tablet.KeyRange, got %v expected 80-c0", ti.KeyRange) | ||
} | ||
require.NoError(t, err, "GetTablet failed") | ||
require.Equal(t, "80-c0", ti.Shard, "Got wrong tablet.Shard") | ||
require.Equal(t, "\x80", string(ti.KeyRange.Start), "Got wrong tablet.KeyRange start") | ||
require.Equal(t, "\xc0", string(ti.KeyRange.End), "Got wrong tablet.KeyRange end") | ||
Ari1009 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// TestDeleteTabletBasic tests delete of non-primary tablet | ||
|
@@ -82,17 +76,14 @@ func TestDeleteTabletBasic(t *testing.T) { | |
Keyspace: "test", | ||
} | ||
|
||
if err := wr.TopoServer().InitTablet(context.Background(), tablet, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/); err != nil { | ||
t.Fatalf("InitTablet failed: %v", err) | ||
} | ||
err := wr.TopoServer().InitTablet(context.Background(), tablet, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/) | ||
require.NoError(t, err, "InitTablet failed") | ||
|
||
if _, err := ts.GetTablet(context.Background(), tablet.Alias); err != nil { | ||
t.Fatalf("GetTablet failed: %v", err) | ||
} | ||
_, err = ts.GetTablet(context.Background(), tablet.Alias) | ||
require.NoError(t, err, "GetTablet failed") | ||
|
||
if err := wr.DeleteTablet(context.Background(), tablet.Alias, false); err != nil { | ||
t.Fatalf("DeleteTablet failed: %v", err) | ||
} | ||
err = wr.DeleteTablet(context.Background(), tablet.Alias, false) | ||
require.NoError(t, err, "DeleteTablet failed") | ||
Ari1009 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// TestDeleteTabletTruePrimary tests that you can delete a true primary tablet | ||
|
@@ -115,31 +106,27 @@ func TestDeleteTabletTruePrimary(t *testing.T) { | |
Type: topodatapb.TabletType_PRIMARY, | ||
} | ||
|
||
if err := wr.TopoServer().InitTablet(context.Background(), tablet, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/); err != nil { | ||
t.Fatalf("InitTablet failed: %v", err) | ||
} | ||
if _, err := ts.GetTablet(context.Background(), tablet.Alias); err != nil { | ||
t.Fatalf("GetTablet failed: %v", err) | ||
} | ||
err := wr.TopoServer().InitTablet(context.Background(), tablet, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/) | ||
require.NoError(t, err, "InitTablet failed") | ||
|
||
_, err = ts.GetTablet(context.Background(), tablet.Alias) | ||
require.NoError(t, err, "GetTablet failed") | ||
|
||
// set PrimaryAlias and PrimaryTermStartTime on shard to match chosen primary tablet | ||
if _, err := ts.UpdateShardFields(context.Background(), "test", "0", func(si *topo.ShardInfo) error { | ||
_, err = ts.UpdateShardFields(context.Background(), "test", "0", func(si *topo.ShardInfo) error { | ||
si.PrimaryAlias = tablet.Alias | ||
si.PrimaryTermStartTime = tablet.PrimaryTermStartTime | ||
return nil | ||
}); err != nil { | ||
t.Fatalf("UpdateShardFields failed: %v", err) | ||
} | ||
}) | ||
require.NoError(t, err, "UpdateShardFields failed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the last string here either. |
||
|
||
err := wr.DeleteTablet(context.Background(), tablet.Alias, false) | ||
err = wr.DeleteTablet(context.Background(), tablet.Alias, false) | ||
wantError := "as it is a primary, use allow_primary flag" | ||
if err == nil || !strings.Contains(err.Error(), wantError) { | ||
t.Fatalf("DeleteTablet on primary: want error = %v, got error = %v", wantError, err) | ||
} | ||
require.Error(t, err, "DeleteTablet on primary: want error") | ||
require.Contains(t, err.Error(), wantError, "DeleteTablet on primary: want specific error message") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use a single |
||
|
||
if err := wr.DeleteTablet(context.Background(), tablet.Alias, true); err != nil { | ||
t.Fatalf("DeleteTablet failed: %v", err) | ||
} | ||
err = wr.DeleteTablet(context.Background(), tablet.Alias, true) | ||
require.NoError(t, err, "DeleteTablet failed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ari1009 I think you can remove this one. |
||
} | ||
|
||
// TestDeleteTabletFalsePrimary tests that you can delete a false primary tablet | ||
|
@@ -162,9 +149,8 @@ func TestDeleteTabletFalsePrimary(t *testing.T) { | |
Type: topodatapb.TabletType_PRIMARY, | ||
} | ||
|
||
if err := wr.TopoServer().InitTablet(context.Background(), tablet1, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/); err != nil { | ||
t.Fatalf("InitTablet failed: %v", err) | ||
} | ||
err := wr.TopoServer().InitTablet(context.Background(), tablet1, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/) | ||
require.NoError(t, err, "InitTablet failed") | ||
|
||
tablet2 := &topodatapb.Tablet{ | ||
Alias: &topodatapb.TabletAlias{ | ||
|
@@ -175,23 +161,20 @@ func TestDeleteTabletFalsePrimary(t *testing.T) { | |
Shard: "0", | ||
Type: topodatapb.TabletType_PRIMARY, | ||
} | ||
if err := wr.TopoServer().InitTablet(context.Background(), tablet2, true /*allowPrimaryOverride*/, false /*createShardAndKeyspace*/, false /*allowUpdate*/); err != nil { | ||
t.Fatalf("InitTablet failed: %v", err) | ||
} | ||
err = wr.TopoServer().InitTablet(context.Background(), tablet2, true /*allowPrimaryOverride*/, false /*createShardAndKeyspace*/, false /*allowUpdate*/) | ||
require.NoError(t, err, "InitTablet failed") | ||
|
||
// set PrimaryAlias and PrimaryTermStartTime on shard to match chosen primary tablet | ||
if _, err := ts.UpdateShardFields(context.Background(), "test", "0", func(si *topo.ShardInfo) error { | ||
_, err = ts.UpdateShardFields(context.Background(), "test", "0", func(si *topo.ShardInfo) error { | ||
si.PrimaryAlias = tablet2.Alias | ||
si.PrimaryTermStartTime = tablet2.PrimaryTermStartTime | ||
return nil | ||
}); err != nil { | ||
t.Fatalf("UpdateShardFields failed: %v", err) | ||
} | ||
}) | ||
require.NoError(t, err, "UpdateShardFields failed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well. |
||
|
||
// Should be able to delete old (false) primary with allowPrimary = false | ||
if err := wr.DeleteTablet(context.Background(), tablet1.Alias, false); err != nil { | ||
t.Fatalf("DeleteTablet failed: %v", err) | ||
} | ||
err = wr.DeleteTablet(context.Background(), tablet1.Alias, false) | ||
require.NoError(t, err, "DeleteTablet failed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too. |
||
} | ||
|
||
// TestDeleteTabletShardNonExisting tests that you can delete a true primary | ||
|
@@ -214,29 +197,25 @@ func TestDeleteTabletShardNonExisting(t *testing.T) { | |
Type: topodatapb.TabletType_PRIMARY, | ||
} | ||
|
||
if err := wr.TopoServer().InitTablet(context.Background(), tablet, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/); err != nil { | ||
t.Fatalf("InitTablet failed: %v", err) | ||
} | ||
if _, err := ts.GetTablet(context.Background(), tablet.Alias); err != nil { | ||
t.Fatalf("GetTablet failed: %v", err) | ||
} | ||
err := wr.TopoServer().InitTablet(context.Background(), tablet, false /*allowPrimaryOverride*/, true /*createShardAndKeyspace*/, false /*allowUpdate*/) | ||
require.NoError(t, err, "InitTablet failed") | ||
|
||
_, err = ts.GetTablet(context.Background(), tablet.Alias) | ||
require.NoError(t, err, "GetTablet failed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the additional string here. |
||
|
||
// set PrimaryAlias and PrimaryTermStartTime on shard to match chosen primary tablet | ||
if _, err := ts.UpdateShardFields(context.Background(), "test", "0", func(si *topo.ShardInfo) error { | ||
_, err = ts.UpdateShardFields(context.Background(), "test", "0", func(si *topo.ShardInfo) error { | ||
si.PrimaryAlias = tablet.Alias | ||
si.PrimaryTermStartTime = tablet.PrimaryTermStartTime | ||
return nil | ||
}); err != nil { | ||
t.Fatalf("UpdateShardFields failed: %v", err) | ||
} | ||
}) | ||
require.NoError(t, err, "UpdateShardFields failed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need here either. |
||
|
||
// trigger a shard deletion | ||
if err := ts.DeleteShard(context.Background(), "test", "0"); err != nil { | ||
t.Fatalf("DeleteShard failed: %v", err) | ||
} | ||
err = ts.DeleteShard(context.Background(), "test", "0") | ||
require.NoError(t, err, "DeleteShard failed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need here either. |
||
|
||
// DeleteTablet should not fail if a shard no longer exist | ||
if err := wr.DeleteTablet(context.Background(), tablet.Alias, true); err != nil { | ||
t.Fatalf("DeleteTablet failed: %v", err) | ||
} | ||
err = wr.DeleteTablet(context.Background(), tablet.Alias, true) | ||
require.NoError(t, err, "DeleteTablet failed") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"vitess.io/vitess/go/sqltypes" | ||
|
@@ -151,15 +152,11 @@ func TestVExec(t *testing.T) { | |
if testCase.errorString == "" { | ||
require.NoError(t, err) | ||
for _, result := range results { | ||
if !testCase.result.Equal(result) { | ||
t.Errorf("mismatched result:\nwant: %v\ngot: %v", testCase.result, result) | ||
} | ||
assert.True(t, testCase.result.Equal(result), "mismatched result:\nwant: %v\ngot: %v", testCase.result, result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove the |
||
} | ||
} else { | ||
require.Error(t, err) | ||
if !strings.Contains(err.Error(), testCase.errorString) { | ||
t.Fatalf("Wrong error, want %s, got %s", testCase.errorString, err.Error()) | ||
} | ||
assert.Contains(t, err.Error(), testCase.errorString, "Wrong error, want %s, got %s", testCase.errorString, err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use |
||
} | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a redaction of severity from
Fatalf
toassert
. Should this not be at leastrequire
?