diff --git a/tests/common/alarm_test.go b/tests/common/alarm_test.go index bbb2d89ddea2..0f3ebee98cae 100644 --- a/tests/common/alarm_test.go +++ b/tests/common/alarm_test.go @@ -21,6 +21,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/testutils" @@ -39,9 +41,7 @@ func TestAlarm(t *testing.T) { testutils.ExecuteUntil(ctx, t, func() { // test small put still works smallbuf := strings.Repeat("a", 64) - if err := cc.Put(ctx, "1st_test", smallbuf, config.PutOptions{}); err != nil { - t.Fatalf("alarmTest: put kv error (%v)", err) - } + require.NoErrorf(t, cc.Put(ctx, "1st_test", smallbuf, config.PutOptions{}), "alarmTest: put kv error") // write some chunks to fill up the database buf := strings.Repeat("b", os.Getpagesize()) @@ -56,9 +56,7 @@ func TestAlarm(t *testing.T) { // quota alarm should now be on alarmResp, err := cc.AlarmList(ctx) - if err != nil { - t.Fatalf("alarmTest: Alarm error (%v)", err) - } + require.NoErrorf(t, err, "alarmTest: Alarm error") // check that Put is rejected when alarm is on if err = cc.Put(ctx, "3rd_test", smallbuf, config.PutOptions{}); err != nil { @@ -69,9 +67,7 @@ func TestAlarm(t *testing.T) { // get latest revision to compact sresp, err := cc.Status(ctx) - if err != nil { - t.Fatalf("get endpoint status error: %v", err) - } + require.NoErrorf(t, err, "get endpoint status error") var rvs int64 for _, resp := range sresp { if resp != nil && resp.Header != nil { @@ -82,13 +78,10 @@ func TestAlarm(t *testing.T) { // make some space _, err = cc.Compact(ctx, rvs, config.CompactOption{Physical: true, Timeout: 10 * time.Second}) - if err != nil { - t.Fatalf("alarmTest: Compact error (%v)", err) - } + require.NoErrorf(t, err, "alarmTest: Compact error") - if err = cc.Defragment(ctx, config.DefragOption{Timeout: 10 * time.Second}); err != nil { - t.Fatalf("alarmTest: defrag error (%v)", err) - } + err = cc.Defragment(ctx, config.DefragOption{Timeout: 10 * time.Second}) + require.NoErrorf(t, err, "alarmTest: defrag error") // turn off alarm for _, alarm := range alarmResp.Alarms { @@ -97,15 +90,12 @@ func TestAlarm(t *testing.T) { Alarm: alarm.Alarm, } _, err = cc.AlarmDisarm(ctx, alarmMember) - if err != nil { - t.Fatalf("alarmTest: Alarm error (%v)", err) - } + require.NoErrorf(t, err, "alarmTest: Alarm error") } // put one more key below quota - if err := cc.Put(ctx, "4th_test", smallbuf, config.PutOptions{}); err != nil { - t.Fatal(err) - } + err = cc.Put(ctx, "4th_test", smallbuf, config.PutOptions{}) + require.NoError(t, err) }) } @@ -123,14 +113,12 @@ func TestAlarmlistOnMemberRestart(t *testing.T) { testutils.ExecuteUntil(ctx, t, func() { for i := 0; i < 6; i++ { - if _, err := cc.AlarmList(ctx); err != nil { - t.Fatalf("Unexpected error: %v", err) - } + _, err := cc.AlarmList(ctx) + require.NoErrorf(t, err, "Unexpected error") } clus.Members()[0].Stop() - if err := clus.Members()[0].Start(ctx); err != nil { - t.Fatalf("failed to start etcdserver: %v", err) - } + err := clus.Members()[0].Start(ctx) + require.NoErrorf(t, err, "failed to start etcdserver") }) } diff --git a/tests/common/auth_test.go b/tests/common/auth_test.go index 92454dd72f63..e52e0721305f 100644 --- a/tests/common/auth_test.go +++ b/tests/common/auth_test.go @@ -378,14 +378,12 @@ func TestAuthTxn(t *testing.T) { // keys with 2 suffix are granted to test-user, see Line 399 grantedKeys := []string{"c2", "s2", "f2"} for _, key := range keys { - if err := cc.Put(ctx, key, "v", config.PutOptions{}); err != nil { - t.Fatal(err) - } + err := cc.Put(ctx, key, "v", config.PutOptions{}) + require.NoError(t, err) } for _, key := range grantedKeys { - if err := cc.Put(ctx, key, "v", config.PutOptions{}); err != nil { - t.Fatal(err) - } + err := cc.Put(ctx, key, "v", config.PutOptions{}) + require.NoError(t, err) } require.NoErrorf(t, setupAuth(cc, []authRole{testRole}, []authUser{rootUser, testUser}), "failed to enable auth") @@ -394,9 +392,8 @@ func TestAuthTxn(t *testing.T) { // grant keys to test-user for _, key := range grantedKeys { - if _, err := rootAuthClient.RoleGrantPermission(ctx, testRoleName, key, "", clientv3.PermissionType(clientv3.PermReadWrite)); err != nil { - t.Fatal(err) - } + _, err := rootAuthClient.RoleGrantPermission(ctx, testRoleName, key, "", clientv3.PermissionType(clientv3.PermReadWrite)) + require.NoError(t, err) } for _, req := range reqs { resp, err := testUserAuthClient.Txn(ctx, req.compare, req.ifSuccess, req.ifFail, config.TxnOptions{ diff --git a/tests/common/compact_test.go b/tests/common/compact_test.go index 584be40407b0..f1bcb6e68a19 100644 --- a/tests/common/compact_test.go +++ b/tests/common/compact_test.go @@ -21,6 +21,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/testutils" @@ -52,22 +53,17 @@ func TestCompact(t *testing.T) { testutils.ExecuteUntil(ctx, t, func() { var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}} for i := range kvs { - if err := cc.Put(ctx, kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil { - t.Fatalf("compactTest #%d: put kv error (%v)", i, err) - } + err := cc.Put(ctx, kvs[i].Key, kvs[i].Val, config.PutOptions{}) + require.NoErrorf(t, err, "compactTest #%d: put kv error", i) } get, err := cc.Get(ctx, "key", config.GetOptions{Revision: 3}) - if err != nil { - t.Fatalf("compactTest: Get kv by revision error (%v)", err) - } + require.NoErrorf(t, err, "compactTest: Get kv by revision error") getkvs := testutils.KeyValuesFromGetResponse(get) assert.Equal(t, kvs[1:2], getkvs) _, err = cc.Compact(ctx, 4, tc.options) - if err != nil { - t.Fatalf("compactTest: Compact error (%v)", err) - } + require.NoErrorf(t, err, "compactTest: Compact error") _, err = cc.Get(ctx, "key", config.GetOptions{Revision: 3}) if err != nil { diff --git a/tests/common/defrag_test.go b/tests/common/defrag_test.go index 0197ced37563..9a29dc554e86 100644 --- a/tests/common/defrag_test.go +++ b/tests/common/defrag_test.go @@ -19,6 +19,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/testutils" ) @@ -34,17 +36,13 @@ func TestDefragOnline(t *testing.T) { defer clus.Close() var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}} for i := range kvs { - if err := cc.Put(ctx, kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil { - t.Fatalf("compactTest #%d: put kv error (%v)", i, err) - } + err := cc.Put(ctx, kvs[i].Key, kvs[i].Val, config.PutOptions{}) + require.NoErrorf(t, err, "compactTest #%d: put kv error", i) } _, err := cc.Compact(ctx, 4, config.CompactOption{Physical: true, Timeout: 10 * time.Second}) - if err != nil { - t.Fatalf("defrag_test: compact with revision error (%v)", err) - } + require.NoErrorf(t, err, "defrag_test: compact with revision error") - if err = cc.Defragment(ctx, options); err != nil { - t.Fatalf("defrag_test: defrag error (%v)", err) - } + err = cc.Defragment(ctx, options) + require.NoErrorf(t, err, "defrag_test: defrag error") }) } diff --git a/tests/common/member_test.go b/tests/common/member_test.go index 2d1039faba38..6cebf6a2664f 100644 --- a/tests/common/member_test.go +++ b/tests/common/member_test.go @@ -249,9 +249,7 @@ func TestMemberRemove(t *testing.T) { // It ensures that `MemberRemove` function does not return an "etcdserver: server stopped" error. func memberToRemove(ctx context.Context, t *testing.T, client intf.Client, clusterSize int) (memberID uint64, clusterID uint64) { listResp, err := client.MemberList(ctx, false) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) clusterID = listResp.Header.ClusterId if clusterSize == 1 { @@ -259,9 +257,7 @@ func memberToRemove(ctx context.Context, t *testing.T, client intf.Client, clust } else { // get status of the specific member that client has connected to statusResp, err := client.Status(ctx) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) // choose a member that client has not connected to for _, m := range listResp.Members { diff --git a/tests/e2e/cluster_downgrade_test.go b/tests/e2e/cluster_downgrade_test.go index 6fbc75bf7f6d..5ba905e7b2c8 100644 --- a/tests/e2e/cluster_downgrade_test.go +++ b/tests/e2e/cluster_downgrade_test.go @@ -218,16 +218,13 @@ func downgradeEnable(t *testing.T, epc *e2e.EtcdProcessCluster, ver *semver.Vers c := epc.Etcdctl() testutils.ExecuteWithTimeout(t, 20*time.Second, func() { err := c.DowngradeEnable(context.TODO(), ver.String()) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) }) } func stopEtcd(t *testing.T, ep e2e.EtcdProcess) { - if err := ep.Stop(); err != nil { - t.Fatal(err) - } + err := ep.Stop() + require.NoError(t, err) } func validateVersion(t *testing.T, cfg *e2e.EtcdProcessClusterConfig, member e2e.EtcdProcess, expect version.Versions) { @@ -260,14 +257,10 @@ func leader(t *testing.T, epc *e2e.EtcdProcessCluster) e2e.EtcdProcess { Endpoints: endpoints, DialTimeout: 3 * time.Second, }) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer cli.Close() resp, err := cli.Status(ctx, endpoints[0]) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if resp.Header.GetMemberId() == resp.Leader { return epc.Procs[i] } diff --git a/tests/e2e/corrupt_test.go b/tests/e2e/corrupt_test.go index 57693a66ab1c..492929c0812a 100644 --- a/tests/e2e/corrupt_test.go +++ b/tests/e2e/corrupt_test.go @@ -68,16 +68,12 @@ func corruptTest(cx ctlCtx) { cx.t.Log("connecting clientv3...") eps := cx.epc.EndpointsGRPC() cli1, err := clientv3.New(clientv3.Config{Endpoints: []string{eps[1]}, DialTimeout: 3 * time.Second}) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) defer cli1.Close() sresp, err := cli1.Status(context.TODO(), eps[0]) cx.t.Logf("checked status sresp:%v err:%v", sresp, err) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) id0 := sresp.Header.GetMemberId() cx.t.Log("stopping etcd[0]...") @@ -86,16 +82,13 @@ func corruptTest(cx ctlCtx) { // corrupting first member by modifying backend offline. fp := datadir.ToBackendFileName(cx.epc.Procs[0].Config().DataDirPath) cx.t.Logf("corrupting backend: %v", fp) - if err = cx.corruptFunc(fp); err != nil { - cx.t.Fatal(err) - } + err = cx.corruptFunc(fp) + require.NoError(cx.t, err) cx.t.Log("restarting etcd[0]") ep := cx.epc.Procs[0] proc, err := e2e.SpawnCmd(append([]string{ep.Config().ExecPath}, ep.Config().Args...), cx.envMap) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) defer proc.Stop() cx.t.Log("waiting for etcd[0] failure...") diff --git a/tests/e2e/ctl_v3_grpc_test.go b/tests/e2e/ctl_v3_grpc_test.go index 30567782e875..7c501fb8776c 100644 --- a/tests/e2e/ctl_v3_grpc_test.go +++ b/tests/e2e/ctl_v3_grpc_test.go @@ -25,6 +25,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.etcd.io/etcd/pkg/v3/expect" "go.etcd.io/etcd/tests/v3/framework/config" @@ -166,9 +167,7 @@ func assertAuthority(t *testing.T, expectAuthorityPattern string, clus *e2e.Etcd line = strings.TrimSuffix(line, "\r") u, err := url.Parse(clus.Procs[i].EndpointsGRPC()[0]) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) expectAuthority := strings.ReplaceAll(expectAuthorityPattern, "${MEMBER_PORT}", u.Port()) expectLine := fmt.Sprintf(`http2: decoded hpack field header field ":authority" = %q`, expectAuthority) assert.True(t, strings.HasSuffix(line, expectLine), fmt.Sprintf("Got %q expected suffix %q", line, expectLine)) diff --git a/tests/e2e/ctl_v3_move_leader_test.go b/tests/e2e/ctl_v3_move_leader_test.go index 0410d9e2de57..1b544fe74803 100644 --- a/tests/e2e/ctl_v3_move_leader_test.go +++ b/tests/e2e/ctl_v3_move_leader_test.go @@ -71,9 +71,7 @@ func testCtlV3MoveLeader(t *testing.T, cfg e2e.EtcdProcessClusterConfig, envVars } var err error tcfg, err = tinfo.ClientConfig() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } var leadIdx int @@ -85,9 +83,7 @@ func testCtlV3MoveLeader(t *testing.T, cfg e2e.EtcdProcessClusterConfig, envVars DialTimeout: 3 * time.Second, TLS: tcfg, }) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) resp, err := cli.Status(ctx, ep) if err != nil { diff --git a/tests/e2e/etcd_config_test.go b/tests/e2e/etcd_config_test.go index 87a5f7666d94..1763c85f5310 100644 --- a/tests/e2e/etcd_config_test.go +++ b/tests/e2e/etcd_config_test.go @@ -81,9 +81,7 @@ func TestEtcdMultiPeer(t *testing.T) { "--initial-cluster", ic, } p, err := e2e.SpawnCmd(args, nil) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) procs[i] = p } @@ -234,9 +232,7 @@ func TestEtcdPeerCNAuth(t *testing.T) { commonArgs = append(commonArgs, args...) p, err := e2e.SpawnCmd(commonArgs, nil) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) procs[i] = p } @@ -324,9 +320,7 @@ func TestEtcdPeerMultiCNAuth(t *testing.T) { commonArgs = append(commonArgs, args...) p, err := e2e.SpawnCmd(commonArgs, nil) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) procs[i] = p } @@ -400,9 +394,7 @@ func TestEtcdPeerNameAuth(t *testing.T) { commonArgs = append(commonArgs, args...) p, err := e2e.SpawnCmd(commonArgs, nil) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) procs[i] = p } @@ -509,9 +501,7 @@ func TestEtcdPeerLocalAddr(t *testing.T) { commonArgs = append(commonArgs, args...) p, err := e2e.SpawnCmd(commonArgs, nil) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) procs[i] = p } @@ -594,9 +584,7 @@ func TestGrpcproxyAndListenCipherSuite(t *testing.T) { for _, test := range cases { t.Run(test.name, func(t *testing.T) { pw, err := e2e.SpawnCmd(test.args, nil) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if err = pw.Stop(); err != nil { t.Fatal(err) } diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index a36a2269b853..a64951df0cdd 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -25,6 +25,7 @@ import ( "github.com/coreos/go-semver/semver" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.uber.org/zap" "go.uber.org/zap/zaptest" @@ -255,13 +256,9 @@ func assertSnapshotsMatch(t testing.TB, firstDataDir, secondDataDir string, patc sort.Strings(secondFiles) for i := 0; i < len(firstFiles); i++ { firstSnapshot, err := snap.Read(lg, firstFiles[i]) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) secondSnapshot, err := snap.Read(lg, secondFiles[i]) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) assertMembershipEqual(t, openSnap(patch(firstSnapshot.Data)), openSnap(patch(secondSnapshot.Data))) } } diff --git a/tests/integration/clientv3/lease/leasing_test.go b/tests/integration/clientv3/lease/leasing_test.go index 2164e8f5b188..106696ff5ace 100644 --- a/tests/integration/clientv3/lease/leasing_test.go +++ b/tests/integration/clientv3/lease/leasing_test.go @@ -24,6 +24,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.etcd.io/etcd/client/pkg/v3/testutil" clientv3 "go.etcd.io/etcd/client/v3" @@ -644,9 +645,7 @@ func TestLeasingTxnOwnerGet(t *testing.T) { for i := range presps { k := fmt.Sprintf("k-%d", i) presp, err := client.Put(context.TODO(), k, k+k) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) presps[i] = presp if _, err = lkv.Get(context.TODO(), k); err != nil { @@ -1179,9 +1178,7 @@ func testLeasingOwnerDelete(t *testing.T, del clientv3.Op) { // confirm keys are invalidated from cache and deleted on etcd for i := 0; i < 8; i++ { resp, err := lkv.Get(context.TODO(), fmt.Sprintf("key/%d", i)) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if len(resp.Kvs) != 0 { t.Fatalf("expected no keys on key/%d, got %+v", i, resp) } @@ -1308,13 +1305,9 @@ func testLeasingDeleteRangeContend(t *testing.T, op clientv3.Op) { for i := 0; i < maxKey; i++ { key := fmt.Sprintf("key/%d", i) resp, err := putkv.Get(context.TODO(), key) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) servResp, err := clus.Client(0).Get(context.TODO(), key) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if !reflect.DeepEqual(resp.Kvs, servResp.Kvs) { t.Errorf("#%d: expected %+v, got %+v", i, servResp.Kvs, resp.Kvs) } @@ -1849,13 +1842,9 @@ func TestLeasingTxnOwnerPutBranch(t *testing.T) { for i := 0; i < n; i++ { k := fmt.Sprintf("tree/%d", i) lkvResp, err := lkv.Get(context.TODO(), k) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) clusResp, err := clus.Client(1).Get(context.TODO(), k) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if !reflect.DeepEqual(clusResp.Kvs, lkvResp.Kvs) { t.Fatalf("expected %+v, got %+v", clusResp.Kvs, lkvResp.Kvs) } diff --git a/tests/integration/clientv3/maintenance_test.go b/tests/integration/clientv3/maintenance_test.go index 7dc912a3a2f7..519d1bbd1ebf 100644 --- a/tests/integration/clientv3/maintenance_test.go +++ b/tests/integration/clientv3/maintenance_test.go @@ -62,9 +62,7 @@ func TestMaintenanceHashKV(t *testing.T) { t.Fatal(err) } hresp, err := cli.HashKV(context.Background(), clus.Members[i].GRPCURL, 0) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if hv == 0 { hv = hresp.Hash continue @@ -421,9 +419,7 @@ func TestMaintenanceStatus(t *testing.T) { prevID, leaderFound := uint64(0), false for i := 0; i < 3; i++ { resp, err := cli.Status(context.TODO(), eps[i]) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) t.Logf("Response from %v: %v", i, resp) if resp.DbSizeQuota != storage.DefaultQuotaBytes { t.Errorf("unexpected backend default quota returned: %d, expected %d", resp.DbSizeQuota, storage.DefaultQuotaBytes) diff --git a/tests/integration/clientv3/snapshot/v3_snapshot_test.go b/tests/integration/clientv3/snapshot/v3_snapshot_test.go index 9e424514145c..3f5fc1c236fb 100644 --- a/tests/integration/clientv3/snapshot/v3_snapshot_test.go +++ b/tests/integration/clientv3/snapshot/v3_snapshot_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" "go.etcd.io/etcd/client/pkg/v3/fileutil" @@ -115,9 +116,7 @@ func createSnapshotFile(t *testing.T, cfg *embed.Config, kvs []kv) (version stri ctx, cancel := context.WithTimeout(context.Background(), testutil.RequestTimeout) _, err = cli.Put(ctx, kvs[i].k, kvs[i].v) cancel() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } dbPath = filepath.Join(t.TempDir(), fmt.Sprintf("snapshot%d.db", time.Now().Nanosecond())) diff --git a/tests/integration/clientv3/watch_test.go b/tests/integration/clientv3/watch_test.go index bc76c8187d81..8b4f4fb49fd7 100644 --- a/tests/integration/clientv3/watch_test.go +++ b/tests/integration/clientv3/watch_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "google.golang.org/grpc/metadata" mvccpb "go.etcd.io/etcd/api/v3/mvccpb" @@ -646,9 +647,7 @@ func TestWatchRequestProgress(t *testing.T) { } _, err := wc.Put(context.Background(), "/a", "1") - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) for _, rch := range watchChans { select { @@ -663,14 +662,10 @@ func TestWatchRequestProgress(t *testing.T) { // put a value not being watched to increment revision _, err = wc.Put(context.Background(), "x", "1") - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) err = wc.RequestProgress(context.Background()) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) // verify all watch channels receive a progress notify for _, rch := range watchChans { diff --git a/tests/integration/embed/embed_test.go b/tests/integration/embed/embed_test.go index 6b35bf57ebf9..ee2c7b085519 100644 --- a/tests/integration/embed/embed_test.go +++ b/tests/integration/embed/embed_test.go @@ -30,6 +30,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.etcd.io/etcd/client/pkg/v3/testutil" "go.etcd.io/etcd/client/pkg/v3/transport" @@ -158,9 +159,7 @@ func testEmbedEtcdGracefulStop(t *testing.T, secure bool) { } if secure { clientCfg.TLS, err = testTLSInfo.ClientConfig() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } cli, err := integration2.NewClient(t, clientCfg) if err != nil { diff --git a/tests/integration/grpc_test.go b/tests/integration/grpc_test.go index 7061ed61e63d..c7b02e640195 100644 --- a/tests/integration/grpc_test.go +++ b/tests/integration/grpc_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "google.golang.org/grpc" clientv3 "go.etcd.io/etcd/client/v3" @@ -121,9 +122,7 @@ func setupTLS(t *testing.T, useTLS bool, cfg integration.ClusterConfig) (integra if useTLS { cfg.ClientTLS = &integration.TestTLSInfo tlsConfig, err := integration.TestTLSInfo.ClientConfig() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) return cfg, tlsConfig } return cfg, nil diff --git a/tests/integration/member_test.go b/tests/integration/member_test.go index efd6598f684d..b012370ab2c4 100644 --- a/tests/integration/member_test.go +++ b/tests/integration/member_test.go @@ -58,9 +58,7 @@ func TestRestartMember(t *testing.T) { c.WaitMembersForLeader(t, membs) clusterMustProgress(t, membs) err := c.Members[i].Restart(t) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } c.WaitMembersForLeader(t, c.Members) clusterMustProgress(t, c.Members) diff --git a/tests/integration/snapshot/v3_snapshot_test.go b/tests/integration/snapshot/v3_snapshot_test.go index 0081e133addf..c1afac035cf8 100644 --- a/tests/integration/snapshot/v3_snapshot_test.go +++ b/tests/integration/snapshot/v3_snapshot_test.go @@ -24,6 +24,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest" @@ -91,9 +92,7 @@ func TestSnapshotV3RestoreSingle(t *testing.T) { for i := range kvs { var gresp *clientv3.GetResponse gresp, err = cli.Get(context.Background(), kvs[i].k) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if string(gresp.Kvs[0].Value) != kvs[i].v { t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, gresp.Kvs[0].Value) } @@ -121,16 +120,12 @@ func TestSnapshotV3RestoreMulti(t *testing.T) { for i := 0; i < clusterN; i++ { cli, err := integration2.NewClient(t, clientv3.Config{Endpoints: []string{cURLs[i].String()}}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer cli.Close() for i := range kvs { var gresp *clientv3.GetResponse gresp, err = cli.Get(context.Background(), kvs[i].k) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if string(gresp.Kvs[0].Value) != kvs[i].v { t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, gresp.Kvs[0].Value) } @@ -204,9 +199,7 @@ func createSnapshotFile(t *testing.T, kvs []kv) string { ctx, cancel := context.WithTimeout(context.Background(), testutil.RequestTimeout) _, err = cli.Put(ctx, kvs[i].k, kvs[i].v) cancel() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } sp := snapshot.NewV3(zaptest.NewLogger(t)) @@ -292,9 +285,7 @@ func newEmbedURLs(t testutil.TB, n int) (urls []url.URL) { defer l.Close() u, err := url.Parse(fmt.Sprintf("unix://%s", l.Addr())) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) urls[i] = *u } return urls diff --git a/tests/integration/v3_failover_test.go b/tests/integration/v3_failover_test.go index d71dd267b85f..49c029586c41 100644 --- a/tests/integration/v3_failover_test.go +++ b/tests/integration/v3_failover_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "google.golang.org/grpc" "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" @@ -56,9 +57,7 @@ func TestFailover(t *testing.T) { defer clus.Terminate(t) cc, err := integration2.TestTLSInfo.ClientConfig() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) // Create an etcd client before or after first server down t.Logf("Creating an etcd client [%s]", tc.name) cli, err := tc.testFunc(t, cc, clus) diff --git a/tests/integration/v3_grpc_test.go b/tests/integration/v3_grpc_test.go index 2cc4ab660327..8c69448c5641 100644 --- a/tests/integration/v3_grpc_test.go +++ b/tests/integration/v3_grpc_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -164,15 +165,11 @@ func TestV3HashKV(t *testing.T) { for i := 0; i < 10; i++ { resp, err := kvc.Put(context.Background(), &pb.PutRequest{Key: []byte("foo"), Value: []byte(fmt.Sprintf("bar%d", i))}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) rev := resp.Header.Revision hresp, err := mvc.HashKV(context.Background(), &pb.HashKVRequest{Revision: 0}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if rev != hresp.Header.Revision { t.Fatalf("Put rev %v != HashKV rev %v", rev, hresp.Header.Revision) } @@ -181,9 +178,7 @@ func TestV3HashKV(t *testing.T) { prevCompactRev := hresp.CompactRevision for i := 0; i < 10; i++ { hresp, err := mvc.HashKV(context.Background(), &pb.HashKVRequest{Revision: 0}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if rev != hresp.Header.Revision { t.Fatalf("Put rev %v != HashKV rev %v", rev, hresp.Header.Revision) } @@ -483,9 +478,7 @@ func TestV3TxnCmpHeaderRev(t *testing.T) { txn.Compare = append(txn.Compare, cmp) tresp, err := kvc.Txn(context.TODO(), txn) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) prev := <-revc if err := <-errCh; err != nil { @@ -604,9 +597,7 @@ func TestV3TxnRangeCompare(t *testing.T) { txn := &pb.TxnRequest{} txn.Compare = append(txn.Compare, &tt.cmp) tresp, err := kvc.Txn(context.TODO(), txn) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if tt.wSuccess != tresp.Succeeded { t.Errorf("#%d: expected %v, got %v", i, tt.wSuccess, tresp.Succeeded) } diff --git a/tests/integration/v3_leadership_test.go b/tests/integration/v3_leadership_test.go index aa1cd8ddc9c9..71640f825c60 100644 --- a/tests/integration/v3_leadership_test.go +++ b/tests/integration/v3_leadership_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" pb "go.etcd.io/etcd/api/v3/etcdserverpb" @@ -59,15 +60,11 @@ func testMoveLeader(t *testing.T, auto bool) { target := uint64(clus.Members[(oldLeadIdx+1)%3].Server.MemberID()) if auto { err := clus.Members[oldLeadIdx].Server.TryTransferLeadershipOnShutdown() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } else { mvc := integration.ToGRPC(clus.Client(oldLeadIdx)).Maintenance _, err := mvc.MoveLeader(context.TODO(), &pb.MoveLeaderRequest{TargetID: target}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } // wait until leader transitions have happened diff --git a/tests/integration/v3_lease_test.go b/tests/integration/v3_lease_test.go index d9d9a7423c9a..52c31df1675e 100644 --- a/tests/integration/v3_lease_test.go +++ b/tests/integration/v3_lease_test.go @@ -384,9 +384,7 @@ func TestV3LeaseCheckpoint(t *testing.T) { defer cancel() c := integration.ToGRPC(clus.RandClient()) lresp, err := c.Lease.LeaseGrant(ctx, &pb.LeaseGrantRequest{TTL: int64(tc.ttl.Seconds())}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) for i := 0; i < tc.leaderChanges; i++ { // wait for a checkpoint to occur @@ -467,9 +465,7 @@ func TestV3LeaseLeases(t *testing.T) { lresp, err := integration.ToGRPC(clus.RandClient()).Lease.LeaseGrant( ctx0, &pb.LeaseGrantRequest{TTL: 30}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if lresp.Error != "" { t.Fatal(lresp.Error) } @@ -528,9 +524,7 @@ func testLeaseStress(t *testing.T, stresser func(context.Context, pb.LeaseClient if useClusterClient { clusterClient, err := clus.ClusterClient(t) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) for i := 0; i < 300; i++ { go func() { errc <- stresser(ctx, integration.ToGRPC(clusterClient).Lease) }() } @@ -988,18 +982,14 @@ func TestV3LeaseRecoverKeyWithMutipleLease(t *testing.T) { var leaseIDs []int64 for i := 0; i < 2; i++ { lresp, err := lsc.LeaseGrant(context.TODO(), &pb.LeaseGrantRequest{TTL: fiveMinTTL}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) if lresp.Error != "" { t.Fatal(lresp.Error) } leaseIDs = append(leaseIDs, lresp.ID) _, err = kvc.Put(context.TODO(), &pb.PutRequest{Key: []byte("foo"), Value: []byte("bar"), Lease: lresp.ID}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } // restart server and ensure lease still exists diff --git a/tests/robustness/main_test.go b/tests/robustness/main_test.go index 63ba6b377638..d4403ab695f0 100644 --- a/tests/robustness/main_test.go +++ b/tests/robustness/main_test.go @@ -20,6 +20,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "go.uber.org/zap" "go.uber.org/zap/zaptest" "golang.org/x/sync/errgroup" @@ -49,14 +50,10 @@ func TestRobustnessExploratory(t *testing.T) { s.cluster.Logger = lg ctx := context.Background() c, err := e2e.NewEtcdProcessCluster(ctx, t, e2e.WithConfig(&s.cluster)) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer forcestopCluster(c) s.failpoint, err = failpoint.PickRandom(c, s.profile) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) t.Run(s.failpoint.Name(), func(t *testing.T) { testRobustness(ctx, t, lg, s, c) }) @@ -72,9 +69,7 @@ func TestRobustnessRegression(t *testing.T) { s.cluster.Logger = lg ctx := context.Background() c, err := e2e.NewEtcdProcessCluster(ctx, t, e2e.WithConfig(&s.cluster)) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer forcestopCluster(c) testRobustness(ctx, t, lg, s, c) }) @@ -92,9 +87,7 @@ func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s testSce }() r.Client = s.run(ctx, t, lg, c) persistedRequests, err := report.PersistedRequestsCluster(lg, c) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) failpointImpactingWatch := s.failpoint == failpoint.SleepBeforeSendWatchResponse if !failpointImpactingWatch { diff --git a/tests/robustness/model/deterministic_test.go b/tests/robustness/model/deterministic_test.go index 965eb2ecd056..5e7bc0f0585a 100644 --- a/tests/robustness/model/deterministic_test.go +++ b/tests/robustness/model/deterministic_test.go @@ -19,6 +19,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/require" "go.etcd.io/etcd/api/v3/mvccpb" ) @@ -35,9 +36,7 @@ func TestModelDeterministic(t *testing.T) { t.Errorf("Unexpected operation result, expect: %v, got: %v, operation: %s", !op.expectFailure, ok, DeterministicModel.DescribeOperation(op.req, op.resp.EtcdResponse)) var loadedState EtcdState err := json.Unmarshal([]byte(state.(string)), &loadedState) - if err != nil { - t.Fatalf("Failed to load state: %v", err) - } + require.NoErrorf(t, err, "Failed to load state") _, resp := loadedState.Step(op.req) t.Errorf("Response diff: %s", cmp.Diff(op.resp, resp)) break diff --git a/tests/robustness/model/non_deterministic_test.go b/tests/robustness/model/non_deterministic_test.go index ee9bb840b502..55187b44e500 100644 --- a/tests/robustness/model/non_deterministic_test.go +++ b/tests/robustness/model/non_deterministic_test.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.etcd.io/etcd/api/v3/mvccpb" ) @@ -335,9 +336,7 @@ func TestModelNonDeterministic(t *testing.T) { t.Errorf("Unexpected operation result, expect: %v, got: %v, operation: %s", !op.expectFailure, ok, NonDeterministicModel.DescribeOperation(op.req, op.resp)) var loadedState nonDeterministicState err := json.Unmarshal([]byte(state.(string)), &loadedState) - if err != nil { - t.Fatalf("Failed to load state: %v", err) - } + require.NoErrorf(t, err, "Failed to load state") for i, s := range loadedState { _, resp := s.Step(op.req) t.Errorf("For state %d, response diff: %s", i, cmp.Diff(op.resp, resp)) diff --git a/tests/robustness/validate/validate_test.go b/tests/robustness/validate/validate_test.go index 35d7da309601..7830c4794e85 100644 --- a/tests/robustness/validate/validate_test.go +++ b/tests/robustness/validate/validate_test.go @@ -22,6 +22,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" "go.etcd.io/etcd/tests/v3/framework/testutils" @@ -44,15 +45,11 @@ func TestDataReports(t *testing.T) { assert.NoError(t, err) persistedRequests, err := report.LoadClusterPersistedRequests(lg, path) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) visualize := ValidateAndReturnVisualize(t, zaptest.NewLogger(t), Config{}, reports, persistedRequests, 5*time.Minute) err = visualize(filepath.Join(path, "history.html")) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) }) } } diff --git a/tools/etcd-dump-logs/etcd-dump-log_test.go b/tools/etcd-dump-logs/etcd-dump-log_test.go index 4f8febe9a096..bd9b24d6bf47 100644 --- a/tools/etcd-dump-logs/etcd-dump-log_test.go +++ b/tools/etcd-dump-logs/etcd-dump-log_test.go @@ -23,6 +23,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" "go.etcd.io/etcd/api/v3/authpb" @@ -36,9 +37,7 @@ import ( func TestEtcdDumpLogEntryType(t *testing.T) { // directory where the command is binDir, err := os.Getwd() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) // TODO(ptabor): The test does not run by default from ./scripts/test.sh. dumpLogsBinary := path.Join(binDir + "/etcd-dump-logs") @@ -79,13 +78,9 @@ func TestEtcdDumpLogEntryType(t *testing.T) { t.Run(argtest.name, func(t *testing.T) { cmd := exec.Command(dumpLogsBinary, argtest.args...) actual, err := cmd.CombinedOutput() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) expected, err := os.ReadFile(path.Join(binDir, argtest.fileExpected)) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) assert.EqualValues(t, string(expected), string(actual)) // The output files contains a lot of trailing whitespaces... difficult to diagnose without printing them explicitly. @@ -99,21 +94,15 @@ func TestEtcdDumpLogEntryType(t *testing.T) { func mustCreateWALLog(t *testing.T, path string) { memberdir := filepath.Join(path, "member") err := os.Mkdir(memberdir, 0744) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) waldir := walDir(path) snapdir := snapDir(path) w, err := wal.Create(zaptest.NewLogger(t), waldir, nil) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) err = os.Mkdir(snapdir, 0744) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) ents := make([]raftpb.Entry, 0) @@ -125,9 +114,7 @@ func mustCreateWALLog(t *testing.T, path string) { // force commit newly appended entries err = w.Save(raftpb.HardState{}, ents) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) w.Close() }