diff --git a/tests/e2e/ctl_v3_auth_test.go b/tests/e2e/ctl_v3_auth_test.go index 6c252e9c202..2fb4f0cffc0 100644 --- a/tests/e2e/ctl_v3_auth_test.go +++ b/tests/e2e/ctl_v3_auth_test.go @@ -131,73 +131,61 @@ func authTestCertCN(cx ctlCtx) { } func authTestFromKeyPerm(cx ctlCtx) { - if err := authEnable(cx); err != nil { - cx.t.Fatal(err) - } + err := authEnable(cx) + require.NoError(cx.t, err) cx.user, cx.pass = "root", "root" authSetupTestUser(cx) // grant keys after z to test-user cx.user, cx.pass = "root", "root" - if err := ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "z", "\x00", false}); err != nil { - cx.t.Fatal(err) - } + err = ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "z", "\x00", false}) + require.NoError(cx.t, err) // try the granted open ended permission cx.user, cx.pass = "test-user", "pass" for i := 0; i < 10; i++ { key := fmt.Sprintf("z%d", i) - if err := ctlV3Put(cx, key, "val", ""); err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, ctlV3Put(cx, key, "val", "")) } largeKey := "" for i := 0; i < 10; i++ { largeKey += "\xff" - if err := ctlV3Put(cx, largeKey, "val", ""); err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, ctlV3Put(cx, largeKey, "val", "")) } // try a non granted key - err := ctlV3PutFailPerm(cx, "x", "baz") + err = ctlV3PutFailPerm(cx, "x", "baz") require.ErrorContains(cx.t, err, "permission denied") // revoke the open ended permission cx.user, cx.pass = "root", "root" - if err := ctlV3RoleRevokePermission(cx, "test-role", "z", "", true); err != nil { - cx.t.Fatal(err) - } + err = ctlV3RoleRevokePermission(cx, "test-role", "z", "", true) + require.NoError(cx.t, err) // try the revoked open ended permission cx.user, cx.pass = "test-user", "pass" for i := 0; i < 10; i++ { key := fmt.Sprintf("z%d", i) - err := ctlV3PutFailPerm(cx, key, "val") - require.ErrorContains(cx.t, err, "permission denied") + require.ErrorContains(cx.t, ctlV3PutFailPerm(cx, key, "val"), "permission denied") } // grant the entire keys cx.user, cx.pass = "root", "root" - if err := ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "", "\x00", false}); err != nil { - cx.t.Fatal(err) - } + err = ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "", "\x00", false}) + require.NoError(cx.t, err) // try keys, of course it must be allowed because test-role has a permission of the entire keys cx.user, cx.pass = "test-user", "pass" for i := 0; i < 10; i++ { key := fmt.Sprintf("z%d", i) - if err := ctlV3Put(cx, key, "val", ""); err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, ctlV3Put(cx, key, "val", "")) } // revoke the entire keys cx.user, cx.pass = "root", "root" - if err := ctlV3RoleRevokePermission(cx, "test-role", "", "", true); err != nil { - cx.t.Fatal(err) - } + err = ctlV3RoleRevokePermission(cx, "test-role", "", "", true) + require.NoError(cx.t, err) // try the revoked entire key permission cx.user, cx.pass = "test-user", "pass" @@ -209,17 +197,15 @@ func authTestFromKeyPerm(cx ctlCtx) { } func authTestWatch(cx ctlCtx) { - if err := authEnable(cx); err != nil { - cx.t.Fatal(err) - } + err := authEnable(cx) + require.NoError(cx.t, err) cx.user, cx.pass = "root", "root" authSetupTestUser(cx) // grant a key range - if err := ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "key", "key4", false}); err != nil { - cx.t.Fatal(err) - } + err = ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "key", "key4", false}) + require.NoError(cx.t, err) tests := []struct { puts []kv @@ -286,9 +272,8 @@ func authTestWatch(cx ctlCtx) { func authTestSnapshot(cx ctlCtx) { maintenanceInitKeys(cx) - if err := authEnable(cx); err != nil { - cx.t.Fatal(err) - } + err := authEnable(cx) + require.NoError(cx.t, err) cx.user, cx.pass = "root", "root" authSetupTestUser(cx) @@ -298,20 +283,16 @@ func authTestSnapshot(cx ctlCtx) { // ordinary user cannot save a snapshot cx.user, cx.pass = "test-user", "pass" - if err := ctlV3SnapshotSave(cx, fpath); err == nil { - cx.t.Fatal("ordinary user should not be able to save a snapshot") - } + err = ctlV3SnapshotSave(cx, fpath) + require.Errorf(cx.t, err, "ordinary user should not be able to save a snapshot") // root can save a snapshot cx.user, cx.pass = "root", "root" - if err := ctlV3SnapshotSave(cx, fpath); err != nil { - cx.t.Fatalf("snapshotTest ctlV3SnapshotSave error (%v)", err) - } + err = ctlV3SnapshotSave(cx, fpath) + require.NoErrorf(cx.t, err, "snapshotTest ctlV3SnapshotSave error") st, err := getSnapshotStatus(cx, fpath) - if err != nil { - cx.t.Fatalf("snapshotTest getSnapshotStatus error (%v)", err) - } + require.NoErrorf(cx.t, err, "snapshotTest getSnapshotStatus error") if st.Revision != 4 { cx.t.Fatalf("expected 4, got %d", st.Revision) } @@ -321,28 +302,24 @@ func authTestSnapshot(cx ctlCtx) { } func authTestEndpointHealth(cx ctlCtx) { - if err := authEnable(cx); err != nil { - cx.t.Fatal(err) - } + err := authEnable(cx) + require.NoError(cx.t, err) cx.user, cx.pass = "root", "root" authSetupTestUser(cx) - if err := ctlV3EndpointHealth(cx); err != nil { - cx.t.Fatalf("endpointStatusTest ctlV3EndpointHealth error (%v)", err) - } + err = ctlV3EndpointHealth(cx) + require.NoErrorf(cx.t, err, "endpointStatusTest ctlV3EndpointHealth error") // health checking with an ordinary user "succeeds" since permission denial goes through consensus cx.user, cx.pass = "test-user", "pass" - if err := ctlV3EndpointHealth(cx); err != nil { - cx.t.Fatalf("endpointStatusTest ctlV3EndpointHealth error (%v)", err) - } + err = ctlV3EndpointHealth(cx) + require.NoErrorf(cx.t, err, "endpointStatusTest ctlV3EndpointHealth error") // succeed if permissions granted for ordinary user cx.user, cx.pass = "root", "root" - if err := ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "health", "", false}); err != nil { - cx.t.Fatal(err) - } + err = ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "health", "", false}) + require.NoError(cx.t, err) cx.user, cx.pass = "test-user", "pass" if err := ctlV3EndpointHealth(cx); err != nil { cx.t.Fatalf("endpointStatusTest ctlV3EndpointHealth error (%v)", err) @@ -350,54 +327,43 @@ func authTestEndpointHealth(cx ctlCtx) { } func certCNAndUsername(cx ctlCtx, noPassword bool) { - if err := authEnable(cx); err != nil { - cx.t.Fatal(err) - } + err := authEnable(cx) + require.NoError(cx.t, err) cx.user, cx.pass = "root", "root" authSetupTestUser(cx) if noPassword { - if err := ctlV3User(cx, []string{"add", "example.com", "--no-password"}, "User example.com created", []string{""}); err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, ctlV3User(cx, []string{"add", "example.com", "--no-password"}, "User example.com created", []string{""})) } else { - if err := ctlV3User(cx, []string{"add", "example.com", "--interactive=false"}, "User example.com created", []string{""}); err != nil { - cx.t.Fatal(err) - } - } - if err := e2e.SpawnWithExpectWithEnv(append(cx.PrefixArgs(), "role", "add", "test-role-cn"), cx.envMap, expect.ExpectedResponse{Value: "Role test-role-cn created"}); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3User(cx, []string{"grant-role", "example.com", "test-role-cn"}, "Role test-role-cn is granted to user example.com", nil); err != nil { - cx.t.Fatal(err) + require.NoError(cx.t, ctlV3User(cx, []string{"add", "example.com", "--interactive=false"}, "User example.com created", []string{""})) } + err = e2e.SpawnWithExpectWithEnv(append(cx.PrefixArgs(), "role", "add", "test-role-cn"), cx.envMap, expect.ExpectedResponse{Value: "Role test-role-cn created"}) + require.NoError(cx.t, err) + err = ctlV3User(cx, []string{"grant-role", "example.com", "test-role-cn"}, "Role test-role-cn is granted to user example.com", nil) + require.NoError(cx.t, err) // grant a new key for CN based user - if err := ctlV3RoleGrantPermission(cx, "test-role-cn", grantingPerm{true, true, "hoo", "", false}); err != nil { - cx.t.Fatal(err) - } + err = ctlV3RoleGrantPermission(cx, "test-role-cn", grantingPerm{true, true, "hoo", "", false}) + require.NoError(cx.t, err) // grant a new key for username based user - if err := ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "bar", "", false}); err != nil { - cx.t.Fatal(err) - } + err = ctlV3RoleGrantPermission(cx, "test-role", grantingPerm{true, true, "bar", "", false}) + require.NoError(cx.t, err) // try a granted key for CN based user cx.user, cx.pass = "", "" - if err := ctlV3Put(cx, "hoo", "bar", ""); err != nil { - cx.t.Error(err) - } + err = ctlV3Put(cx, "hoo", "bar", "") + require.NoError(cx.t, err) // try a granted key for username based user cx.user, cx.pass = "test-user", "pass" - if err := ctlV3Put(cx, "bar", "bar", ""); err != nil { - cx.t.Error(err) - } + err = ctlV3Put(cx, "bar", "bar", "") + require.NoError(cx.t, err) // try a non-granted key for both of them cx.user, cx.pass = "", "" - err := ctlV3PutFailPerm(cx, "baz", "bar") + err = ctlV3PutFailPerm(cx, "baz", "bar") require.ErrorContains(cx.t, err, "permission denied") cx.user, cx.pass = "test-user", "pass" diff --git a/tests/e2e/ctl_v3_defrag_test.go b/tests/e2e/ctl_v3_defrag_test.go index 479ba1a284a..ea08576f463 100644 --- a/tests/e2e/ctl_v3_defrag_test.go +++ b/tests/e2e/ctl_v3_defrag_test.go @@ -17,6 +17,8 @@ package e2e import ( "testing" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/pkg/v3/expect" "go.etcd.io/etcd/tests/v3/framework/e2e" ) @@ -28,9 +30,8 @@ func TestCtlV3DefragOffline(t *testing.T) { func maintenanceInitKeys(cx ctlCtx) { var kvs = []kv{{"key", "val1"}, {"key", "val2"}, {"key", "val3"}} for i := range kvs { - if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil { - cx.t.Fatal(err) - } + err := ctlV3Put(cx, kvs[i].key, kvs[i].val, "") + require.NoError(cx.t, err) } } diff --git a/tests/e2e/ctl_v3_elect_test.go b/tests/e2e/ctl_v3_elect_test.go index 386a5f7dbdb..57890efc47d 100644 --- a/tests/e2e/ctl_v3_elect_test.go +++ b/tests/e2e/ctl_v3_elect_test.go @@ -35,9 +35,7 @@ func testElect(cx ctlCtx) { name := "a" holder, ch, err := ctlV3Elect(cx, name, "p1", false) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) l1 := "" select { @@ -51,9 +49,7 @@ func testElect(cx ctlCtx) { // blocked process that won't win the election blocked, ch, err := ctlV3Elect(cx, name, "p2", true) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) select { case <-time.After(100 * time.Millisecond): case <-ch: @@ -62,9 +58,7 @@ func testElect(cx ctlCtx) { // overlap with a blocker that will win the election blockAcquire, ch, err := ctlV3Elect(cx, name, "p2", false) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) defer func(blockAcquire *expect.ExpectProcess) { err = blockAcquire.Stop() require.NoError(cx.t, err) @@ -78,9 +72,8 @@ func testElect(cx ctlCtx) { } // kill blocked process with clean shutdown - if err = blocked.Signal(os.Interrupt); err != nil { - cx.t.Fatal(err) - } + err = blocked.Signal(os.Interrupt) + require.NoError(cx.t, err) err = e2e.CloseWithTimeout(blocked, time.Second) if err != nil { // due to being blocked, this can potentially get killed and thus exit non-zero sometimes @@ -88,12 +81,10 @@ func testElect(cx ctlCtx) { } // kill the holder with clean shutdown - if err = holder.Signal(os.Interrupt); err != nil { - cx.t.Fatal(err) - } - if err = e2e.CloseWithTimeout(holder, time.Second); err != nil { - cx.t.Fatal(err) - } + err = holder.Signal(os.Interrupt) + require.NoError(cx.t, err) + err = e2e.CloseWithTimeout(holder, time.Second) + require.NoError(cx.t, err) // blockAcquire should win the election select { diff --git a/tests/e2e/ctl_v3_grpc_test.go b/tests/e2e/ctl_v3_grpc_test.go index 4cc66099e09..9f11d04775f 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" @@ -135,9 +136,7 @@ func TestAuthority(t *testing.T) { assert.NoError(t, err) for i := 0; i < 100; i++ { err = client.Put(ctx, "foo", "bar", config.PutOptions{}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } testutils.ExecuteWithTimeout(t, 5*time.Second, func() { @@ -166,9 +165,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.Truef(t, strings.HasSuffix(line, expectLine), "Got %q expected suffix %q", line, expectLine) diff --git a/tests/e2e/ctl_v3_kv_test.go b/tests/e2e/ctl_v3_kv_test.go index 719efc464a4..7c1f0f35dff 100644 --- a/tests/e2e/ctl_v3_kv_test.go +++ b/tests/e2e/ctl_v3_kv_test.go @@ -62,9 +62,8 @@ func testGetRevokedCRL(cx ctlCtx) { // test accept cx.epc.Cfg.Client.RevokeCerts = false - if err := ctlV3Put(cx, "k", "v", ""); err != nil { - cx.t.Fatal(err) - } + err = ctlV3Put(cx, "k", "v", "") + require.NoError(cx.t, err) } func putTest(cx ctlCtx) { @@ -83,18 +82,14 @@ func putTest(cx ctlCtx) { } func putTestIgnoreValue(cx ctlCtx) { - if err := ctlV3Put(cx, "foo", "bar", ""); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Get(cx, []string{"foo"}, kv{"foo", "bar"}); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Put(cx, "foo", "", "", "--ignore-value"); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Get(cx, []string{"foo"}, kv{"foo", "bar"}); err != nil { - cx.t.Fatal(err) - } + err := ctlV3Put(cx, "foo", "bar", "") + require.NoError(cx.t, err) + err = ctlV3Get(cx, []string{"foo"}, kv{"foo", "bar"}) + require.NoError(cx.t, err) + err = ctlV3Put(cx, "foo", "", "", "--ignore-value") + require.NoError(cx.t, err) + err = ctlV3Get(cx, []string{"foo"}, kv{"foo", "bar"}) + require.NoError(cx.t, err) } func putTestIgnoreLease(cx ctlCtx) { @@ -159,9 +154,8 @@ func getTest(cx ctlCtx) { } func getFormatTest(cx ctlCtx) { - if err := ctlV3Put(cx, "abc", "123", ""); err != nil { - cx.t.Fatal(err) - } + err := ctlV3Put(cx, "abc", "123", "") + require.NoError(cx.t, err) tests := []struct { format string @@ -251,13 +245,11 @@ func getMinMaxCreateModRevTest(cx ctlCtx) { } func getKeysOnlyTest(cx ctlCtx) { - if err := ctlV3Put(cx, "key", "val", ""); err != nil { - cx.t.Fatal(err) - } + err := ctlV3Put(cx, "key", "val", "") + require.NoError(cx.t, err) cmdArgs := append(cx.PrefixArgs(), []string{"get", "--keys-only", "key"}...) - if err := e2e.SpawnWithExpectWithEnv(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "key"}); err != nil { - cx.t.Fatal(err) - } + err = e2e.SpawnWithExpectWithEnv(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "key"}) + require.NoError(cx.t, err) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -269,33 +261,25 @@ func getKeysOnlyTest(cx ctlCtx) { func getCountOnlyTest(cx ctlCtx) { cmdArgs := append(cx.PrefixArgs(), []string{"get", "--count-only", "key", "--prefix", "--write-out=fields"}...) - if err := e2e.SpawnWithExpects(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "\"Count\" : 0"}); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Put(cx, "key", "val", ""); err != nil { - cx.t.Fatal(err) - } + err := e2e.SpawnWithExpects(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "\"Count\" : 0"}) + require.NoError(cx.t, err) + err = ctlV3Put(cx, "key", "val", "") + require.NoError(cx.t, err) cmdArgs = append(cx.PrefixArgs(), []string{"get", "--count-only", "key", "--prefix", "--write-out=fields"}...) - if err := e2e.SpawnWithExpects(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "\"Count\" : 1"}); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Put(cx, "key1", "val", ""); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Put(cx, "key1", "val", ""); err != nil { - cx.t.Fatal(err) - } + err = e2e.SpawnWithExpects(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "\"Count\" : 1"}) + require.NoError(cx.t, err) + err = ctlV3Put(cx, "key1", "val", "") + require.NoError(cx.t, err) + err = ctlV3Put(cx, "key1", "val", "") + require.NoError(cx.t, err) cmdArgs = append(cx.PrefixArgs(), []string{"get", "--count-only", "key", "--prefix", "--write-out=fields"}...) - if err := e2e.SpawnWithExpects(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "\"Count\" : 2"}); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Put(cx, "key2", "val", ""); err != nil { - cx.t.Fatal(err) - } + err = e2e.SpawnWithExpects(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "\"Count\" : 2"}) + require.NoError(cx.t, err) + err = ctlV3Put(cx, "key2", "val", "") + require.NoError(cx.t, err) cmdArgs = append(cx.PrefixArgs(), []string{"get", "--count-only", "key", "--prefix", "--write-out=fields"}...) - if err := e2e.SpawnWithExpects(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "\"Count\" : 3"}); err != nil { - cx.t.Fatal(err) - } + err = e2e.SpawnWithExpects(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "\"Count\" : 3"}) + require.NoError(cx.t, err) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() diff --git a/tests/e2e/ctl_v3_lock_test.go b/tests/e2e/ctl_v3_lock_test.go index 326c0b7e48a..03d5ef2147d 100644 --- a/tests/e2e/ctl_v3_lock_test.go +++ b/tests/e2e/ctl_v3_lock_test.go @@ -40,9 +40,7 @@ func testLock(cx ctlCtx) { name := "a" holder, ch, err := ctlV3Lock(cx, name) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) l1 := "" select { @@ -56,9 +54,7 @@ func testLock(cx ctlCtx) { // blocked process that won't acquire the lock blocked, ch, err := ctlV3Lock(cx, name) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) select { case <-time.After(100 * time.Millisecond): case <-ch: @@ -67,9 +63,7 @@ func testLock(cx ctlCtx) { // overlap with a blocker that will acquire the lock blockAcquire, ch, err := ctlV3Lock(cx, name) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) defer func(blockAcquire *expect.ExpectProcess) { err = blockAcquire.Stop() require.NoError(cx.t, err) @@ -83,9 +77,8 @@ func testLock(cx ctlCtx) { } // kill blocked process with clean shutdown - if err = blocked.Signal(os.Interrupt); err != nil { - cx.t.Fatal(err) - } + err = blocked.Signal(os.Interrupt) + require.NoError(cx.t, err) err = e2e.CloseWithTimeout(blocked, time.Second) if err != nil { // due to being blocked, this can potentially get killed and thus exit non-zero sometimes @@ -93,12 +86,10 @@ func testLock(cx ctlCtx) { } // kill the holder with clean shutdown - if err = holder.Signal(os.Interrupt); err != nil { - cx.t.Fatal(err) - } - if err = e2e.CloseWithTimeout(holder, 200*time.Millisecond+time.Second); err != nil { - cx.t.Fatal(err) - } + err = holder.Signal(os.Interrupt) + require.NoError(cx.t, err) + err = e2e.CloseWithTimeout(holder, 200*time.Millisecond+time.Second) + require.NoError(cx.t, err) // blockAcquire should acquire the lock select { @@ -114,15 +105,14 @@ func testLock(cx ctlCtx) { func testLockWithCmd(cx ctlCtx) { // exec command with zero exit code echoCmd := []string{"echo"} - if err := ctlV3LockWithCmd(cx, echoCmd, expect.ExpectedResponse{Value: ""}); err != nil { - cx.t.Fatal(err) - } + err := ctlV3LockWithCmd(cx, echoCmd, expect.ExpectedResponse{Value: ""}) + require.NoError(cx.t, err) // exec command with non-zero exit code code := 3 awkCmd := []string{"awk", fmt.Sprintf("BEGIN{exit %d}", code)} expect := expect.ExpectedResponse{Value: fmt.Sprintf("Error: exit status %d", code)} - err := ctlV3LockWithCmd(cx, awkCmd, expect) + err = ctlV3LockWithCmd(cx, awkCmd, expect) require.ErrorContains(cx.t, err, expect.Value) } diff --git a/tests/e2e/ctl_v3_make_mirror_test.go b/tests/e2e/ctl_v3_make_mirror_test.go index 28491c29ae0..80c414e6aa6 100644 --- a/tests/e2e/ctl_v3_make_mirror_test.go +++ b/tests/e2e/ctl_v3_make_mirror_test.go @@ -20,6 +20,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/tests/v3/framework/e2e" ) @@ -100,26 +102,19 @@ func testMirrorCommand(cx ctlCtx, flags []string, sourcekvs []kv, destkvs []kvEx cmdArgs = append(cmdArgs, flags...) cmdArgs = append(cmdArgs, fmt.Sprintf("localhost:%d", mirrorcfg.BasePort)) proc, err := e2e.SpawnCmd(cmdArgs, cx.envMap) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) defer func() { err = proc.Stop() - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) }() for i := range sourcekvs { - if err = ctlV3Put(cx, sourcekvs[i].key, sourcekvs[i].val, ""); err != nil { - cx.t.Fatal(err) - } - } - if err = ctlV3Get(cx, []string{srcprefix, "--prefix"}, sourcekvs...); err != nil { - cx.t.Fatal(err) + err = ctlV3Put(cx, sourcekvs[i].key, sourcekvs[i].val, "") + require.NoError(cx.t, err) } + err = ctlV3Get(cx, []string{srcprefix, "--prefix"}, sourcekvs...) + require.NoError(cx.t, err) - if err = ctlV3Watch(mirrorctx, []string{destprefix, "--rev", "1", "--prefix"}, destkvs...); err != nil { - cx.t.Fatal(err) - } + err = ctlV3Watch(mirrorctx, []string{destprefix, "--rev", "1", "--prefix"}, destkvs...) + require.NoError(cx.t, err) } diff --git a/tests/e2e/ctl_v3_member_test.go b/tests/e2e/ctl_v3_member_test.go index e10836eae3a..d779c8171d3 100644 --- a/tests/e2e/ctl_v3_member_test.go +++ b/tests/e2e/ctl_v3_member_test.go @@ -253,16 +253,14 @@ func memberListWithHexTest(cx ctlCtx) { func memberAddTest(cx ctlCtx) { peerURL := fmt.Sprintf("http://localhost:%d", e2e.EtcdProcessBasePort+11) - if err := ctlV3MemberAdd(cx, peerURL, false); err != nil { - cx.t.Fatal(err) - } + err := ctlV3MemberAdd(cx, peerURL, false) + require.NoError(cx.t, err) } func memberAddAsLearnerTest(cx ctlCtx) { peerURL := fmt.Sprintf("http://localhost:%d", e2e.EtcdProcessBasePort+11) - if err := ctlV3MemberAdd(cx, peerURL, true); err != nil { - cx.t.Fatal(err) - } + err := ctlV3MemberAdd(cx, peerURL, true) + require.NoError(cx.t, err) } func ctlV3MemberAdd(cx ctlCtx, peerURL string, isLearner bool) error { @@ -277,15 +275,12 @@ func ctlV3MemberAdd(cx ctlCtx, peerURL string, isLearner bool) error { func memberUpdateTest(cx ctlCtx) { mr, err := getMemberList(cx, false) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) peerURL := fmt.Sprintf("http://localhost:%d", e2e.EtcdProcessBasePort+11) memberID := fmt.Sprintf("%x", mr.Members[0].ID) - if err = ctlV3MemberUpdate(cx, memberID, peerURL); err != nil { - cx.t.Fatal(err) - } + err = ctlV3MemberUpdate(cx, memberID, peerURL) + require.NoError(cx.t, err) } func ctlV3MemberUpdate(cx ctlCtx, memberID, peerURL string) error { diff --git a/tests/e2e/ctl_v3_move_leader_test.go b/tests/e2e/ctl_v3_move_leader_test.go index 02d008e3fa5..cc3e8077443 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/ctl_v3_snapshot_test.go b/tests/e2e/ctl_v3_snapshot_test.go index 66f2dbf574e..7e86ccf6507 100644 --- a/tests/e2e/ctl_v3_snapshot_test.go +++ b/tests/e2e/ctl_v3_snapshot_test.go @@ -82,12 +82,9 @@ func snapshotCorruptTest(cx ctlCtx) { // corrupt file f, oerr := os.OpenFile(fpath, os.O_WRONLY, 0) - if oerr != nil { - cx.t.Fatal(oerr) - } - if _, err := f.Write(make([]byte, 512)); err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, oerr) + _, err := f.Write(make([]byte, 512)) + require.NoError(cx.t, err) f.Close() datadir := cx.t.TempDir() @@ -129,9 +126,7 @@ func snapshotStatusBeforeRestoreTest(cx ctlCtx) { fpath), cx.envMap, expect.ExpectedResponse{Value: "added member"}) - if serr != nil { - cx.t.Fatal(serr) - } + require.NoError(cx.t, serr) } func ctlV3SnapshotSave(cx ctlCtx, fpath string) error { @@ -204,17 +199,15 @@ func testIssue6361(t *testing.T) { fpath := filepath.Join(t.TempDir(), "test.snapshot") t.Log("etcdctl saving snapshot...") - if err = e2e.SpawnWithExpects(append(prefixArgs, "snapshot", "save", fpath), + err = e2e.SpawnWithExpects(append(prefixArgs, "snapshot", "save", fpath), nil, expect.ExpectedResponse{Value: fmt.Sprintf("Snapshot saved at %s", fpath)}, - ); err != nil { - t.Fatal(err) - } + ) + require.NoError(t, err) t.Log("Stopping the original server...") - if err = epc.Procs[0].Stop(); err != nil { - t.Fatal(err) - } + err = epc.Procs[0].Stop() + require.NoError(t, err) newDataDir := filepath.Join(t.TempDir(), "test.data") t.Log("etcdctl restoring the snapshot...") @@ -226,9 +219,7 @@ func testIssue6361(t *testing.T) { "--initial-advertise-peer-urls", epc.Procs[0].Config().PeerURL.String(), "--data-dir", newDataDir}, expect.ExpectedResponse{Value: "added member"}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) t.Log("(Re)starting the etcd member using the restored snapshot...") epc.Procs[0].Config().DataDirPath = newDataDir @@ -237,9 +228,8 @@ func testIssue6361(t *testing.T) { epc.Procs[0].Config().Args[i+1] = newDataDir } } - if err = epc.Procs[0].Restart(context.TODO()); err != nil { - t.Fatal(err) - } + err = epc.Procs[0].Restart(context.TODO()) + require.NoError(t, err) t.Log("Ensuring the restored member has the correct data...") for i := range kvs { @@ -251,9 +241,7 @@ func testIssue6361(t *testing.T) { clientURL := fmt.Sprintf("http://localhost:%d", e2e.EtcdProcessBasePort+30) peerURL := fmt.Sprintf("http://localhost:%d", e2e.EtcdProcessBasePort+31) err = e2e.SpawnWithExpect(append(prefixArgs, "member", "add", "newmember", fmt.Sprintf("--peer-urls=%s", peerURL)), expect.ExpectedResponse{Value: " added to cluster "}) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) newDataDir2 := t.TempDir() defer os.RemoveAll(newDataDir2) @@ -268,12 +256,9 @@ func testIssue6361(t *testing.T) { "--listen-client-urls", clientURL, "--advertise-client-urls", clientURL, "--listen-peer-urls", peerURL, "--initial-advertise-peer-urls", peerURL, "--initial-cluster", initialCluster2, "--initial-cluster-state", "existing", "--data-dir", newDataDir2}, nil) - if err != nil { - t.Fatal(err) - } - if _, err = nepc.Expect("ready to serve client requests"); err != nil { - t.Fatal(err) - } + require.NoError(t, err) + _, err = nepc.Expect("ready to serve client requests") + require.NoError(t, err) prefixArgs = []string{e2e.BinPath.Etcdctl, "--endpoints", clientURL, "--dial-timeout", dialTimeout.String()} @@ -284,9 +269,8 @@ func testIssue6361(t *testing.T) { } t.Log("Stopping the second member") - if err = nepc.Stop(); err != nil { - t.Fatal(err) - } + err = nepc.Stop() + require.NoError(t, err) t.Log("Test logic done") } diff --git a/tests/e2e/ctl_v3_test.go b/tests/e2e/ctl_v3_test.go index 30449d06097..8bba195431b 100644 --- a/tests/e2e/ctl_v3_test.go +++ b/tests/e2e/ctl_v3_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "go.etcd.io/etcd/api/v3/version" "go.etcd.io/etcd/client/pkg/v3/testutil" @@ -113,9 +114,8 @@ func TestCtlV3DialWithHTTPScheme(t *testing.T) { func dialWithSchemeTest(cx ctlCtx) { cmdArgs := append(cx.prefixArgs(cx.epc.EndpointsGRPC()), "put", "foo", "bar") - if err := e2e.SpawnWithExpectWithEnv(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "OK"}); err != nil { - cx.t.Fatal(err) - } + err := e2e.SpawnWithExpectWithEnv(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: "OK"}) + require.NoError(cx.t, err) } type ctlCtx struct { diff --git a/tests/e2e/discovery_test.go b/tests/e2e/discovery_test.go index 60c85415768..92b948e6c08 100644 --- a/tests/e2e/discovery_test.go +++ b/tests/e2e/discovery_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/client/pkg/v3/testutil" "go.etcd.io/etcd/client/pkg/v3/transport" @@ -59,9 +61,8 @@ func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) { dcc := MustNewHTTPClient(t, dc.EndpointsHTTP(), nil) dkapi := client.NewKeysAPI(dcc) ctx, cancel := context.WithTimeout(context.Background(), integration.RequestTimeout) - if _, err = dkapi.Create(ctx, "/_config/size", fmt.Sprintf("%d", size)); err != nil { - t.Fatal(err) - } + _, err = dkapi.Create(ctx, "/_config/size", fmt.Sprintf("%d", size)) + require.NoError(t, err) cancel() c, err := e2e.NewEtcdProcessCluster(context.TODO(), t, @@ -76,12 +77,10 @@ func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) { defer c.Close() kubectl := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(c.EndpointsGRPC(), ",")} - if err := e2e.SpawnWithExpect(append(kubectl, "put", "key", "value"), expect.ExpectedResponse{Value: "OK"}); err != nil { - t.Fatal(err) - } - if err := e2e.SpawnWithExpect(append(kubectl, "get", "key"), expect.ExpectedResponse{Value: "value"}); err != nil { - t.Fatal(err) - } + err = e2e.SpawnWithExpect(append(kubectl, "put", "key", "value"), expect.ExpectedResponse{Value: "OK"}) + require.NoError(t, err) + err = e2e.SpawnWithExpect(append(kubectl, "get", "key"), expect.ExpectedResponse{Value: "value"}) + require.NoError(t, err) } func MustNewHTTPClient(t testutil.TB, eps []string, tls *transport.TLSInfo) client.Client { @@ -91,17 +90,13 @@ func MustNewHTTPClient(t testutil.TB, eps []string, tls *transport.TLSInfo) clie } cfg := client.Config{Transport: mustNewTransport(t, cfgtls), Endpoints: eps} c, err := client.New(cfg) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) return c } func mustNewTransport(t testutil.TB, tlsInfo transport.TLSInfo) *http.Transport { // tick in integration test is short, so 1s dial timeout could play well. tr, err := transport.NewTimeoutTransport(tlsInfo, time.Second, rafthttp.ConnReadTimeout, rafthttp.ConnWriteTimeout) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) return tr } diff --git a/tests/e2e/discovery_v3_test.go b/tests/e2e/discovery_v3_test.go index b74666fb8a0..7345c4dd931 100644 --- a/tests/e2e/discovery_v3_test.go +++ b/tests/e2e/discovery_v3_test.go @@ -21,6 +21,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/pkg/v3/expect" "go.etcd.io/etcd/tests/v3/framework/e2e" ) @@ -77,12 +79,10 @@ func testClusterUsingV3Discovery(t *testing.T, discoveryClusterSize, targetClust // step 4: sanity test on the etcd cluster etcdctl := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsGRPC(), ",")} - if err := e2e.SpawnWithExpect(append(etcdctl, "put", "key", "value"), expect.ExpectedResponse{Value: "OK"}); err != nil { - t.Fatal(err) - } - if err := e2e.SpawnWithExpect(append(etcdctl, "get", "key"), expect.ExpectedResponse{Value: "value"}); err != nil { - t.Fatal(err) - } + err = e2e.SpawnWithExpect(append(etcdctl, "put", "key", "value"), expect.ExpectedResponse{Value: "OK"}) + require.NoError(t, err) + err = e2e.SpawnWithExpect(append(etcdctl, "get", "key"), expect.ExpectedResponse{Value: "value"}) + require.NoError(t, err) } func bootstrapEtcdClusterUsingV3Discovery(t *testing.T, discoveryEndpoints []string, discoveryToken string, clusterSize int, clientTLSType e2e.ClientConnType, isClientAutoTLS bool) (*e2e.EtcdProcessCluster, error) { diff --git a/tests/e2e/etcd_config_test.go b/tests/e2e/etcd_config_test.go index ec8bc32a60b..d4133d387f3 100644 --- a/tests/e2e/etcd_config_test.go +++ b/tests/e2e/etcd_config_test.go @@ -39,15 +39,11 @@ func TestEtcdExampleConfig(t *testing.T) { e2e.SkipInShortMode(t) proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--config-file", exampleConfigFile}, nil) - if err != nil { - t.Fatal(err) - } - if err = e2e.WaitReadyExpectProc(context.TODO(), proc, e2e.EtcdServerReadyLines); err != nil { - t.Fatal(err) - } - if err = proc.Stop(); err != nil { - t.Fatal(err) - } + require.NoError(t, err) + err = e2e.WaitReadyExpectProc(context.TODO(), proc, e2e.EtcdServerReadyLines) + require.NoError(t, err) + err = proc.Stop() + require.NoError(t, err) } func TestEtcdMultiPeer(t *testing.T) { @@ -81,9 +77,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 } @@ -109,15 +103,11 @@ func TestEtcdUnixPeers(t *testing.T) { }, nil, ) defer os.Remove("etcd.unix:1") - if err != nil { - t.Fatal(err) - } - if err = e2e.WaitReadyExpectProc(context.TODO(), proc, e2e.EtcdServerReadyLines); err != nil { - t.Fatal(err) - } - if err = proc.Stop(); err != nil { - t.Fatal(err) - } + require.NoError(t, err) + err = e2e.WaitReadyExpectProc(context.TODO(), proc, e2e.EtcdServerReadyLines) + require.NoError(t, err) + err = proc.Stop() + require.NoError(t, err) } // TestEtcdListenMetricsURLsWithMissingClientTLSInfo checks that the HTTPs listen metrics URL @@ -158,19 +148,14 @@ func TestEtcdListenMetricsURLsWithMissingClientTLSInfo(t *testing.T) { } proc, err := e2e.SpawnCmd(commonArgs, nil) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer func() { - if err := proc.Stop(); err != nil { - t.Error(err) - } + assert.NoError(t, proc.Stop()) _ = proc.Close() }() - if err := e2e.WaitReadyExpectProc(context.TODO(), proc, []string{embed.ErrMissingClientTLSInfoForMetricsURL.Error()}); err != nil { - t.Fatal(err) - } + err = e2e.WaitReadyExpectProc(context.TODO(), proc, []string{embed.ErrMissingClientTLSInfoForMetricsURL.Error()}) + require.NoError(t, err) } // TestEtcdPeerCNAuth checks that the inter peer auth based on CN of cert is working correctly. @@ -233,9 +218,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 } @@ -322,9 +305,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 } @@ -397,9 +378,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 } @@ -505,9 +484,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 } @@ -554,9 +531,7 @@ func TestGrpcproxyAndCommonName(t *testing.T) { } }() - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) } func TestGrpcproxyAndListenCipherSuite(t *testing.T) { @@ -589,12 +564,9 @@ 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) - } - if err = pw.Stop(); err != nil { - t.Fatal(err) - } + require.NoError(t, err) + err = pw.Stop() + require.NoError(t, err) }) } } @@ -603,15 +575,11 @@ func TestBootstrapDefragFlag(t *testing.T) { e2e.SkipInShortMode(t) proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--experimental-bootstrap-defrag-threshold-megabytes", "1000"}, nil) - if err != nil { - t.Fatal(err) - } - if err = e2e.WaitReadyExpectProc(context.TODO(), proc, []string{"Skipping defragmentation"}); err != nil { - t.Fatal(err) - } - if err = proc.Stop(); err != nil { - t.Fatal(err) - } + require.NoError(t, err) + err = e2e.WaitReadyExpectProc(context.TODO(), proc, []string{"Skipping defragmentation"}) + require.NoError(t, err) + err = proc.Stop() + require.NoError(t, err) // wait for the process to exit, otherwise test will have leaked goroutine if err := proc.Close(); err != nil { diff --git a/tests/e2e/etcd_release_upgrade_test.go b/tests/e2e/etcd_release_upgrade_test.go index afc73974980..d718b83e713 100644 --- a/tests/e2e/etcd_release_upgrade_test.go +++ b/tests/e2e/etcd_release_upgrade_test.go @@ -21,6 +21,9 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/api/v3/version" "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/pkg/v3/expect" @@ -85,9 +88,8 @@ func TestReleaseUpgrade(t *testing.T) { t.Logf("Testing reads after node restarts: %v", i) for j := range kvs { - if err = ctlV3Get(cx, []string{kvs[j].key}, []kv{kvs[j]}...); err != nil { - cx.t.Fatalf("#%d-%d: ctlV3Get error (%v)", i, j, err) - } + err = ctlV3Get(cx, []string{kvs[j].key}, []kv{kvs[j]}...) + require.NoErrorf(cx.t, err, "#%d-%d: ctlV3Get error", i, j) } t.Logf("Tested reads after node restarts: %v", i) } @@ -145,15 +147,11 @@ func TestReleaseUpgradeWithRestart(t *testing.T) { kvs = append(kvs, kv{key: fmt.Sprintf("foo%d", i), val: "bar"}) } for i := range kvs { - if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil { - cx.t.Fatalf("#%d: ctlV3Put error (%v)", i, err) - } + require.NoErrorf(cx.t, ctlV3Put(cx, kvs[i].key, kvs[i].val, ""), "#%d: ctlV3Put error", i) } for i := range epc.Procs { - if err := epc.Procs[i].Stop(); err != nil { - t.Fatalf("#%d: error closing etcd process (%v)", i, err) - } + require.NoErrorf(t, epc.Procs[i].Stop(), "#%d: error closing etcd process", i) } var wg sync.WaitGroup @@ -162,15 +160,12 @@ func TestReleaseUpgradeWithRestart(t *testing.T) { go func(i int) { epc.Procs[i].Config().ExecPath = e2e.BinPath.Etcd epc.Procs[i].Config().KeepDataDir = true - if err := epc.Procs[i].Restart(context.TODO()); err != nil { - t.Errorf("error restarting etcd process (%v)", err) - } + assert.NoErrorf(t, epc.Procs[i].Restart(context.TODO()), "error restarting etcd process") wg.Done() }(i) } wg.Wait() - if err := ctlV3Get(cx, []string{kvs[0].key}, []kv{kvs[0]}...); err != nil { - t.Fatal(err) - } + err = ctlV3Get(cx, []string{kvs[0].key}, []kv{kvs[0]}...) + require.NoError(t, err) } diff --git a/tests/e2e/gateway_test.go b/tests/e2e/gateway_test.go index aefe3d4a713..4a0a94d895d 100644 --- a/tests/e2e/gateway_test.go +++ b/tests/e2e/gateway_test.go @@ -19,6 +19,8 @@ import ( "strings" "testing" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/pkg/v3/expect" "go.etcd.io/etcd/tests/v3/framework/e2e" ) @@ -29,9 +31,7 @@ var ( func TestGateway(t *testing.T) { ec, err := e2e.NewEtcdProcessCluster(context.TODO(), t) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer ec.Stop() eps := strings.Join(ec.EndpointsGRPC(), ",") @@ -50,12 +50,8 @@ func TestGateway(t *testing.T) { func startGateway(t *testing.T, endpoints string) *expect.ExpectProcess { p, err := expect.NewExpect(e2e.BinPath.Etcd, "gateway", "--endpoints="+endpoints, "start") - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) _, err = p.Expect("ready to proxy client requests") - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) return p } diff --git a/tests/e2e/http_health_check_test.go b/tests/e2e/http_health_check_test.go index 8aa2694344f..c2d425a2b22 100644 --- a/tests/e2e/http_health_check_test.go +++ b/tests/e2e/http_health_check_test.go @@ -367,9 +367,7 @@ func triggerNoSpaceAlarm(ctx context.Context, t *testing.T, clus *e2e.EtcdProces etcdctl := clus.Etcdctl() for { if err := etcdctl.Put(ctx, "foo", buf, config.PutOptions{}); err != nil { - if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") { - t.Fatal(err) - } + require.ErrorContains(t, err, "etcdserver: mvcc: database space exceeded") break } } diff --git a/tests/e2e/metrics_test.go b/tests/e2e/metrics_test.go index 1ed85f5bbfa..b9a13dc4436 100644 --- a/tests/e2e/metrics_test.go +++ b/tests/e2e/metrics_test.go @@ -20,6 +20,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "go.etcd.io/etcd/api/v3/version" "go.etcd.io/etcd/pkg/v3/expect" "go.etcd.io/etcd/tests/v3/framework/config" @@ -53,9 +55,8 @@ func TestV3LearnerMetricApplyFromSnapshotTest(t *testing.T) { } func metricsTest(cx ctlCtx) { - if err := ctlV3Put(cx, "k", "v", ""); err != nil { - cx.t.Fatal(err) - } + err := ctlV3Put(cx, "k", "v", "") + require.NoError(cx.t, err) i := 0 for _, test := range []struct { @@ -70,18 +71,14 @@ func metricsTest(cx ctlCtx) { {"/health", `{"health":"true","reason":""}`}, } { i++ - if err := ctlV3Put(cx, fmt.Sprintf("%d", i), "v", ""); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Del(cx, []string{fmt.Sprintf("%d", i)}, 1); err != nil { - cx.t.Fatal(err) - } - if err := ctlV3Watch(cx, []string{"k", "--rev", "1"}, []kvExec{{key: "k", val: "v"}}...); err != nil { - cx.t.Fatal(err) - } - if err := e2e.CURLGet(cx.epc, e2e.CURLReq{Endpoint: test.endpoint, Expected: expect.ExpectedResponse{Value: test.expected}}); err != nil { - cx.t.Fatalf("failed get with curl (%v)", err) - } + err := ctlV3Put(cx, fmt.Sprintf("%d", i), "v", "") + require.NoError(cx.t, err) + err = ctlV3Del(cx, []string{fmt.Sprintf("%d", i)}, 1) + require.NoError(cx.t, err) + err = ctlV3Watch(cx, []string{"k", "--rev", "1"}, []kvExec{{key: "k", val: "v"}}...) + require.NoError(cx.t, err) + err = e2e.CURLGet(cx.epc, e2e.CURLReq{Endpoint: test.endpoint, Expected: expect.ExpectedResponse{Value: test.expected}}) + require.NoErrorf(cx.t, err, "failed get with curl") } } @@ -89,17 +86,15 @@ func learnerMetricRecoverTest(cx ctlCtx) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - if _, err := cx.epc.StartNewProc(ctx, nil, cx.t, true /* addAsLearner */); err != nil { - cx.t.Fatal(err) - } + _, err := cx.epc.StartNewProc(ctx, nil, cx.t, true /* addAsLearner */) + require.NoError(cx.t, err) expectLearnerMetrics(cx) triggerSnapshot(ctx, cx) // Restart cluster - if err := cx.epc.Restart(ctx); err != nil { - cx.t.Fatal(err) - } + err = cx.epc.Restart(ctx) + require.NoError(cx.t, err) expectLearnerMetrics(cx) } @@ -109,25 +104,21 @@ func learnerMetricApplyFromSnapshotTest(cx ctlCtx) { // Add learner but do not start it _, learnerCfg, err := cx.epc.AddMember(ctx, nil, cx.t, true /* addAsLearner */) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) triggerSnapshot(ctx, cx) // Start the learner - if err = cx.epc.StartNewProcFromConfig(ctx, cx.t, learnerCfg); err != nil { - cx.t.Fatal(err) - } + err = cx.epc.StartNewProcFromConfig(ctx, cx.t, learnerCfg) + require.NoError(cx.t, err) expectLearnerMetrics(cx) } func triggerSnapshot(ctx context.Context, cx ctlCtx) { etcdctl := cx.epc.Procs[0].Etcdctl() for i := 0; i < int(cx.epc.Cfg.ServerConfig.SnapshotCount); i++ { - if err := etcdctl.Put(ctx, "k", "v", config.PutOptions{}); err != nil { - cx.t.Fatal(err) - } + err := etcdctl.Put(ctx, "k", "v", config.PutOptions{}) + require.NoError(cx.t, err) } } @@ -141,7 +132,6 @@ func expectLearnerMetric(cx ctlCtx, procIdx int, expectMetric string) { defer cancel() args := e2e.CURLPrefixArgsCluster(cx.epc.Cfg, cx.epc.Procs[procIdx], "GET", e2e.CURLReq{Endpoint: "/metrics"}) - if err := e2e.SpawnWithExpectsContext(ctx, args, nil, expect.ExpectedResponse{Value: expectMetric}); err != nil { - cx.t.Fatal(err) - } + err := e2e.SpawnWithExpectsContext(ctx, args, nil, expect.ExpectedResponse{Value: expectMetric}) + require.NoError(cx.t, err) } diff --git a/tests/e2e/utl_migrate_test.go b/tests/e2e/utl_migrate_test.go index a58d69a24c7..22b9f90f510 100644 --- a/tests/e2e/utl_migrate_test.go +++ b/tests/e2e/utl_migrate_test.go @@ -140,15 +140,13 @@ func TestEtctlutlMigrate(t *testing.T) { t.Log("Write keys to ensure wal snapshot is created and all v3.5 fields are set...") for i := 0; i < 10; i++ { - if err = e2e.SpawnWithExpect(append(prefixArgs, "put", fmt.Sprintf("%d", i), "value"), expect.ExpectedResponse{Value: "OK"}); err != nil { - t.Fatal(err) - } + err = e2e.SpawnWithExpect(append(prefixArgs, "put", fmt.Sprintf("%d", i), "value"), expect.ExpectedResponse{Value: "OK"}) + require.NoError(t, err) } t.Log("Stopping the server...") - if err = epc.Procs[0].Stop(); err != nil { - t.Fatal(err) - } + err = epc.Procs[0].Stop() + require.NoError(t, err) t.Log("etcdutl migrate...") memberDataDir := epc.Procs[0].Config().DataDirPath @@ -157,12 +155,10 @@ func TestEtctlutlMigrate(t *testing.T) { args = append(args, "--force") } err = e2e.SpawnWithExpect(args, expect.ExpectedResponse{Value: tc.expectLogsSubString}) - if err != nil { - if tc.expectLogsSubString != "" { - require.ErrorContains(t, err, tc.expectLogsSubString) - } else { - t.Fatal(err) - } + if err != nil && tc.expectLogsSubString != "" { + require.ErrorContains(t, err, tc.expectLogsSubString) + } else { + require.NoError(t, err) } t.Log("etcdutl migrate...") diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index a36a2269b85..a145e6a26db 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" @@ -241,13 +242,9 @@ func filterSnapshotFiles(path string) bool { func assertSnapshotsMatch(t testing.TB, firstDataDir, secondDataDir string, patch func([]byte) []byte) { lg := zaptest.NewLogger(t) firstFiles, err := fileutil.ListFiles(firstDataDir, filterSnapshotFiles) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) secondFiles, err := fileutil.ListFiles(secondDataDir, filterSnapshotFiles) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) assert.NotEmpty(t, firstFiles) assert.NotEmpty(t, secondFiles) assert.Equal(t, len(firstFiles), len(secondFiles)) @@ -255,13 +252,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/e2e/v3_curl_auth_test.go b/tests/e2e/v3_curl_auth_test.go index 04f07b48013..a367be5bc8d 100644 --- a/tests/e2e/v3_curl_auth_test.go +++ b/tests/e2e/v3_curl_auth_test.go @@ -68,49 +68,45 @@ func testCurlV3Auth(cx ctlCtx) { user, err := json.Marshal(&pb.AuthUserAddRequest{Name: usernames[i], Password: pwds[i], Options: options[i]}) assert.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/add", Value: string(user), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3Auth failed to add user %v (%v)", usernames[i], err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3Auth failed to add user %v", usernames[i]) } // create root role rolereq, err := json.Marshal(&pb.AuthRoleAddRequest{Name: "root"}) assert.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/role/add", Value: string(rolereq), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3Auth failed to create role (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3Auth failed to create role") //grant root role for i := 0; i < len(usernames); i++ { grantroleroot, merr := json.Marshal(&pb.AuthUserGrantRoleRequest{User: usernames[i], Role: "root"}) assert.NoError(cx.t, merr) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/grant", Value: string(grantroleroot), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3Auth failed to grant role (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3Auth failed to grant role") } // enable auth - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/enable", Value: "{}", Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3Auth failed to enable auth (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3Auth failed to enable auth") for i := 0; i < len(usernames); i++ { // put "bar[i]" into "foo[i]" @@ -118,13 +114,12 @@ func testCurlV3Auth(cx ctlCtx) { assert.NoError(cx.t, err) // fail put no auth - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/kv/put", Value: string(putreq), Expected: expect.ExpectedResponse{Value: "etcdserver: user name is empty"}, - }); err != nil { - cx.t.Fatalf("testCurlV3Auth failed to put without token (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3Auth failed to put without token") // auth request authreq, err := json.Marshal(&pb.AuthenticateRequest{Name: usernames[i], Password: pwds[i]}) @@ -157,14 +152,13 @@ func testCurlV3Auth(cx ctlCtx) { authHeader = "Authorization: " + token // put with auth - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/kv/put", Value: string(putreq), Header: authHeader, Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3Auth failed to auth put with user (%v) (%v)", usernames[i], err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3Auth failed to auth put with user (%v)", usernames[i]) } } @@ -176,25 +170,23 @@ func testCurlV3AuthUserBasicOperations(cx ctlCtx) { user, err := json.Marshal(&pb.AuthUserAddRequest{Name: usernames[i], Password: "123"}) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/add", Value: string(user), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthUserBasicOperations failed to add user %v (%v)", usernames[i], err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthUserBasicOperations failed to add user %v", usernames[i]) } // change password user, err := json.Marshal(&pb.AuthUserChangePasswordRequest{Name: "user1", Password: "456"}) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/changepw", Value: string(user), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthUserBasicOperations failed to change user's password(%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthUserBasicOperations failed to change user's password") // get users usernames = []string{"user1", "userX"} @@ -205,13 +197,12 @@ func testCurlV3AuthUserBasicOperations(cx ctlCtx) { }) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/get", Value: string(user), Expected: expect.ExpectedResponse{Value: expectedResponse[i]}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthUserBasicOperations failed to get user %v (%v)", usernames[i], err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthUserBasicOperations failed to get user %v", usernames[i]) } // delete users @@ -222,13 +213,12 @@ func testCurlV3AuthUserBasicOperations(cx ctlCtx) { Name: usernames[i], }) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/delete", Value: string(user), Expected: expect.ExpectedResponse{Value: expectedResponse[i]}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthUserBasicOperations failed to delete user %v (%v)", usernames[i], err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthUserBasicOperations failed to delete user %v", usernames[i]) } // list users @@ -258,25 +248,23 @@ func testCurlV3AuthUserGrantRevokeRoles(cx ctlCtx) { user, err := json.Marshal(&pb.AuthUserAddRequest{Name: username, Password: "123"}) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/add", Value: string(user), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthUserGrantRevokeRoles failed to add user %v (%v)", username, err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthUserGrantRevokeRoles failed to add user %v", username) // create role role, err := json.Marshal(&pb.AuthRoleAddRequest{Name: rolename}) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/role/add", Value: string(role), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthUserGrantRevokeRoles failed to add role %v (%v)", rolename, err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthUserGrantRevokeRoles failed to add role %v", rolename) // grant role to user grantRoleReq, err := json.Marshal(&pb.AuthUserGrantRoleRequest{ @@ -285,13 +273,12 @@ func testCurlV3AuthUserGrantRevokeRoles(cx ctlCtx) { }) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/grant", Value: string(grantRoleReq), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthUserGrantRevokeRoles failed to grant role to user (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthUserGrantRevokeRoles failed to grant role to user") // revoke role from user revokeRoleReq, err := json.Marshal(&pb.AuthUserRevokeRoleRequest{ @@ -300,13 +287,12 @@ func testCurlV3AuthUserGrantRevokeRoles(cx ctlCtx) { }) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/user/revoke", Value: string(revokeRoleReq), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthUserGrantRevokeRoles failed to revoke role from user (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthUserGrantRevokeRoles failed to revoke role from user") } func testCurlV3AuthRoleBasicOperations(cx ctlCtx) { @@ -317,13 +303,12 @@ func testCurlV3AuthRoleBasicOperations(cx ctlCtx) { role, err := json.Marshal(&pb.AuthRoleAddRequest{Name: rolenames[i]}) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/role/add", Value: string(role), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthRoleBasicOperations failed to add role %v (%v)", rolenames[i], err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthRoleBasicOperations failed to add role %v", rolenames[i]) } // get roles @@ -334,13 +319,12 @@ func testCurlV3AuthRoleBasicOperations(cx ctlCtx) { Role: rolenames[i], }) require.NoError(cx.t, err) - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/role/get", Value: string(role), Expected: expect.ExpectedResponse{Value: expectedResponse[i]}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthRoleBasicOperations failed to get role %v (%v)", rolenames[i], err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthRoleBasicOperations failed to get role %v", rolenames[i]) } // delete roles @@ -351,13 +335,12 @@ func testCurlV3AuthRoleBasicOperations(cx ctlCtx) { Role: rolenames[i], }) require.NoError(cx.t, err) - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/role/delete", Value: string(role), Expected: expect.ExpectedResponse{Value: expectedResponse[i]}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthRoleBasicOperations failed to delete role %v (%v)", rolenames[i], err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthRoleBasicOperations failed to delete role %v", rolenames[i]) } // list roles @@ -386,13 +369,12 @@ func testCurlV3AuthRoleManagePermission(cx ctlCtx) { role, err := json.Marshal(&pb.AuthRoleAddRequest{Name: rolename}) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/role/add", Value: string(role), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthRoleManagePermission failed to add role %v (%v)", rolename, err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthRoleManagePermission failed to add role %v", rolename) // grant permission grantPermissionReq, err := json.Marshal(&pb.AuthRoleGrantPermissionRequest{ @@ -404,13 +386,12 @@ func testCurlV3AuthRoleManagePermission(cx ctlCtx) { }) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/role/grant", Value: string(grantPermissionReq), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthRoleManagePermission failed to grant permission to role %v (%v)", rolename, err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthRoleManagePermission failed to grant permission to role %v", rolename) // revoke permission revokePermissionReq, err := json.Marshal(&pb.AuthRoleRevokePermissionRequest{ @@ -419,40 +400,36 @@ func testCurlV3AuthRoleManagePermission(cx ctlCtx) { }) require.NoError(cx.t, err) - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/role/revoke", Value: string(revokePermissionReq), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthRoleManagePermission failed to revoke permission from role %v (%v)", rolename, err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthRoleManagePermission failed to revoke permission from role %v", rolename) } func testCurlV3AuthEnableDisableStatus(cx ctlCtx) { // enable auth - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/enable", Value: "{}", Expected: expect.ExpectedResponse{Value: "etcdserver: root user does not exist"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthEnableDisableStatus failed to enable auth (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthEnableDisableStatus failed to enable auth") // disable auth - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/disable", Value: "{}", Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthEnableDisableStatus failed to disable auth (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthEnableDisableStatus failed to disable auth") // auth status - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/auth/status", Value: "{}", Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3AuthEnableDisableStatus failed to get auth status (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3AuthEnableDisableStatus failed to get auth status") } diff --git a/tests/e2e/v3_curl_cluster_test.go b/tests/e2e/v3_curl_cluster_test.go index 688f8dcaca0..8bfa7786504 100644 --- a/tests/e2e/v3_curl_cluster_test.go +++ b/tests/e2e/v3_curl_cluster_test.go @@ -42,13 +42,12 @@ func testCurlV3ClusterOperations(cx ctlCtx) { addMemberReq, err := json.Marshal(&pb.MemberAddRequest{PeerURLs: []string{peerURL}, IsLearner: true}) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/cluster/member/add", Value: string(addMemberReq), Expected: expect.ExpectedResponse{Value: peerURL}, - }); err != nil { - cx.t.Fatalf("testCurlV3ClusterOperations failed to add member (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3ClusterOperations failed to add member") // list members and get the new member's ID cx.t.Log("Listing members after adding a member") @@ -76,33 +75,30 @@ func testCurlV3ClusterOperations(cx ctlCtx) { updateMemberReq, err := json.Marshal(&pb.MemberUpdateRequest{ID: newMemberID, PeerURLs: []string{updatedPeerURL}}) require.NoError(cx.t, err) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/cluster/member/update", Value: string(updateMemberReq), Expected: expect.ExpectedResponse{Value: updatedPeerURL}, - }); err != nil { - cx.t.Fatalf("testCurlV3ClusterOperations failed to update member (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3ClusterOperations failed to update member") // promote member cx.t.Logf("Promoting the member %d", newMemberID) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/cluster/member/promote", Value: fmt.Sprintf(`{"ID": %d}`, newMemberID), Expected: expect.ExpectedResponse{Value: "etcdserver: can only promote a learner member which is in sync with leader"}, - }); err != nil { - cx.t.Fatalf("testCurlV3ClusterOperations failed to promote member (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3ClusterOperations failed to promote member") // remove member cx.t.Logf("Removing the member %d", newMemberID) - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/cluster/member/remove", Value: fmt.Sprintf(`{"ID": %d}`, newMemberID), Expected: expect.ExpectedResponse{Value: "members"}, - }); err != nil { - cx.t.Fatalf("testCurlV3ClusterOperations failed to remove member (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3ClusterOperations failed to remove member") // list members again after deleting a member cx.t.Log("Listing members again after deleting a member") diff --git a/tests/e2e/v3_curl_election_test.go b/tests/e2e/v3_curl_election_test.go index 01c7194ed3b..c38c79e6e8f 100644 --- a/tests/e2e/v3_curl_election_test.go +++ b/tests/e2e/v3_curl_election_test.go @@ -40,33 +40,24 @@ func testCurlV3Campaign(cx ctlCtx) { Name: []byte("/election-prefix"), Value: []byte("v1"), }) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) cargs := e2e.CURLPrefixArgsCluster(cx.epc.Cfg, cx.epc.Procs[rand.Intn(cx.epc.Cfg.ClusterSize)], "POST", e2e.CURLReq{ Endpoint: "/v3/election/campaign", Value: string(cdata), }) lines, err := e2e.SpawnWithExpectLines(context.TODO(), cargs, cx.envMap, expect.ExpectedResponse{Value: `"leader":{"name":"`}) - if err != nil { - cx.t.Fatalf("failed post campaign request (%v)", err) - } + require.NoErrorf(cx.t, err, "failed post campaign request") if len(lines) != 1 { cx.t.Fatalf("len(lines) expected 1, got %+v", lines) } var cresp campaignResponse - if err = json.Unmarshal([]byte(lines[0]), &cresp); err != nil { - cx.t.Fatalf("failed to unmarshal campaign response %v", err) - } + err = json.Unmarshal([]byte(lines[0]), &cresp) + require.NoErrorf(cx.t, err, "failed to unmarshal campaign response") ndata, err := base64.StdEncoding.DecodeString(cresp.Leader.Name) - if err != nil { - cx.t.Fatalf("failed to decode leader key %v", err) - } + require.NoErrorf(cx.t, err, "failed to decode leader key") kdata, err := base64.StdEncoding.DecodeString(cresp.Leader.Key) - if err != nil { - cx.t.Fatalf("failed to decode leader key %v", err) - } + require.NoErrorf(cx.t, err, "failed to decode leader key") // observe observeReq, err := json.Marshal(&epb.LeaderRequest{ @@ -100,16 +91,13 @@ func testCurlV3Campaign(cx ctlCtx) { }, Value: []byte("v2"), }) - if err != nil { - cx.t.Fatal(err) - } - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + require.NoError(cx.t, err) + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/election/proclaim", Value: string(pdata), Expected: expect.ExpectedResponse{Value: `"revision":`}, - }); err != nil { - cx.t.Fatalf("failed post proclaim request (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "failed post proclaim request") } func TestCurlV3ProclaimMissiongLeaderKeyNoTLS(t *testing.T) { @@ -118,16 +106,13 @@ func TestCurlV3ProclaimMissiongLeaderKeyNoTLS(t *testing.T) { func testCurlV3ProclaimMissiongLeaderKey(cx ctlCtx) { pdata, err := json.Marshal(&epb.ProclaimRequest{Value: []byte("v2")}) - if err != nil { - cx.t.Fatal(err) - } - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + require.NoError(cx.t, err) + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/election/proclaim", Value: string(pdata), Expected: expect.ExpectedResponse{Value: `"message":"\"leader\" field must be provided"`}, - }); err != nil { - cx.t.Fatalf("failed post proclaim request (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "failed post proclaim request") } func TestCurlV3ResignMissiongLeaderKeyNoTLS(t *testing.T) { @@ -135,13 +120,12 @@ func TestCurlV3ResignMissiongLeaderKeyNoTLS(t *testing.T) { } func testCurlV3ResignMissiongLeaderKey(cx ctlCtx) { - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/election/resign", Value: `{}`, Expected: expect.ExpectedResponse{Value: `"message":"\"leader\" field must be provided"`}, - }); err != nil { - cx.t.Fatalf("failed post resign request (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "failed post resign request") } func TestCurlV3ElectionLeader(t *testing.T) { @@ -149,13 +133,12 @@ func TestCurlV3ElectionLeader(t *testing.T) { } func testCurlV3ElectionLeader(cx ctlCtx) { - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/election/leader", Value: `{"name": "aGVsbG8="}`, // base64 encoded string "hello" Expected: expect.ExpectedResponse{Value: `election: no leader`}, - }); err != nil { - cx.t.Fatalf("testCurlV3ElectionLeader failed to get leader (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3ElectionLeader failed to get leader") } // to manually decode; JSON marshals integer fields with diff --git a/tests/e2e/v3_curl_lease_test.go b/tests/e2e/v3_curl_lease_test.go index 67ef64e2240..af71bfa698f 100644 --- a/tests/e2e/v3_curl_lease_test.go +++ b/tests/e2e/v3_curl_lease_test.go @@ -18,6 +18,8 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + pb "go.etcd.io/etcd/api/v3/etcdserverpb" "go.etcd.io/etcd/tests/v3/framework/e2e" ) @@ -66,9 +68,8 @@ func testCurlV3LeaseGrant(cx ctlCtx) { expected: `"grantedTTL"`, }, } - if err := CURLWithExpected(cx, tests); err != nil { - cx.t.Fatalf("testCurlV3LeaseGrant: %v", err) - } + err := CURLWithExpected(cx, tests) + require.NoErrorf(cx.t, err, "testCurlV3LeaseGrant") } func testCurlV3LeaseRevoke(cx ctlCtx) { @@ -86,9 +87,8 @@ func testCurlV3LeaseRevoke(cx ctlCtx) { expected: `"revision":"`, }, } - if err := CURLWithExpected(cx, tests); err != nil { - cx.t.Fatalf("testCurlV3LeaseRevoke: %v", err) - } + err := CURLWithExpected(cx, tests) + require.NoErrorf(cx.t, err, "testCurlV3LeaseRevoke") } func testCurlV3LeaseLeases(cx ctlCtx) { @@ -106,9 +106,8 @@ func testCurlV3LeaseLeases(cx ctlCtx) { expected: gwLeaseIDExpected(leaseID), }, } - if err := CURLWithExpected(cx, tests); err != nil { - cx.t.Fatalf("testCurlV3LeaseGrant: %v", err) - } + err := CURLWithExpected(cx, tests) + require.NoErrorf(cx.t, err, "testCurlV3LeaseGrant") } func testCurlV3LeaseKeepAlive(cx ctlCtx) { @@ -126,9 +125,8 @@ func testCurlV3LeaseKeepAlive(cx ctlCtx) { expected: gwLeaseIDExpected(leaseID), }, } - if err := CURLWithExpected(cx, tests); err != nil { - cx.t.Fatalf("testCurlV3LeaseGrant: %v", err) - } + err := CURLWithExpected(cx, tests) + require.NoErrorf(cx.t, err, "testCurlV3LeaseGrant") } func gwLeaseIDExpected(leaseID int64) string { @@ -138,44 +136,34 @@ func gwLeaseIDExpected(leaseID int64) string { func gwLeaseTTLWithKeys(cx ctlCtx, leaseID int64) string { d := &pb.LeaseTimeToLiveRequest{ID: leaseID, Keys: true} s, err := e2e.DataMarshal(d) - if err != nil { - cx.t.Fatalf("gwLeaseTTLWithKeys: error (%v)", err) - } + require.NoErrorf(cx.t, err, "gwLeaseTTLWithKeys: error") return s } func gwLeaseKeepAlive(cx ctlCtx, leaseID int64) string { d := &pb.LeaseKeepAliveRequest{ID: leaseID} s, err := e2e.DataMarshal(d) - if err != nil { - cx.t.Fatalf("gwLeaseKeepAlive: Marshal error (%v)", err) - } + require.NoErrorf(cx.t, err, "gwLeaseKeepAlive: Marshal error") return s } func gwLeaseGrant(cx ctlCtx, leaseID int64, ttl int64) string { d := &pb.LeaseGrantRequest{ID: leaseID, TTL: ttl} s, err := e2e.DataMarshal(d) - if err != nil { - cx.t.Fatalf("gwLeaseGrant: Marshal error (%v)", err) - } + require.NoErrorf(cx.t, err, "gwLeaseGrant: Marshal error") return s } func gwLeaseRevoke(cx ctlCtx, leaseID int64) string { d := &pb.LeaseRevokeRequest{ID: leaseID} s, err := e2e.DataMarshal(d) - if err != nil { - cx.t.Fatalf("gwLeaseRevoke: Marshal error (%v)", err) - } + require.NoErrorf(cx.t, err, "gwLeaseRevoke: Marshal error") return s } func gwKVPutLease(cx ctlCtx, k string, v string, leaseID int64) string { d := pb.PutRequest{Key: []byte(k), Value: []byte(v), Lease: leaseID} s, err := e2e.DataMarshal(d) - if err != nil { - cx.t.Fatalf("gwKVPutLease: Marshal error (%v)", err) - } + require.NoErrorf(cx.t, err, "gwKVPutLease: Marshal error") return s } diff --git a/tests/e2e/v3_curl_lock_test.go b/tests/e2e/v3_curl_lock_test.go index 9b7e481b6c4..6f38350b2a4 100644 --- a/tests/e2e/v3_curl_lock_test.go +++ b/tests/e2e/v3_curl_lock_test.go @@ -46,11 +46,10 @@ func testCurlV3LockOperations(cx ctlCtx) { require.True(cx.t, ok) // unlock - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{ + err = e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/lock/unlock", Value: fmt.Sprintf(`{"key": "%v"}`, key), Expected: expect.ExpectedResponse{Value: "revision"}, - }); err != nil { - cx.t.Fatalf("testCurlV3LockOperations failed to execute unlock (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "testCurlV3LockOperations failed to execute unlock") } diff --git a/tests/e2e/v3_curl_maintenance_test.go b/tests/e2e/v3_curl_maintenance_test.go index de8b837f60e..73504d1de96 100644 --- a/tests/e2e/v3_curl_maintenance_test.go +++ b/tests/e2e/v3_curl_maintenance_test.go @@ -30,12 +30,11 @@ func TestCurlV3MaintenanceAlarmMissiongAlarm(t *testing.T) { } func testCurlV3MaintenanceAlarmMissiongAlarm(cx ctlCtx) { - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/maintenance/alarm", Value: `{"action": "ACTIVATE"}`, - }); err != nil { - cx.t.Fatalf("failed post maintenance alarm (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "failed post maintenance alarm") } func TestCurlV3MaintenanceStatus(t *testing.T) { @@ -67,15 +66,14 @@ func TestCurlV3MaintenanceDefragment(t *testing.T) { } func testCurlV3MaintenanceDefragment(cx ctlCtx) { - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/maintenance/defragment", Value: "{}", Expected: expect.ExpectedResponse{ Value: "{}", }, - }); err != nil { - cx.t.Fatalf("failed post maintenance defragment request: (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "failed post maintenance defragment request") } func TestCurlV3MaintenanceHash(t *testing.T) { @@ -125,15 +123,14 @@ func TestCurlV3MaintenanceSnapshot(t *testing.T) { } func testCurlV3MaintenanceSnapshot(cx ctlCtx) { - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/maintenance/snapshot", Value: "{}", Expected: expect.ExpectedResponse{ Value: `"result":{"blob":`, }, - }); err != nil { - cx.t.Fatalf("failed post maintenance snapshot request: (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "failed post maintenance snapshot request") } func TestCurlV3MaintenanceMoveleader(t *testing.T) { @@ -141,15 +138,14 @@ func TestCurlV3MaintenanceMoveleader(t *testing.T) { } func testCurlV3MaintenanceMoveleader(cx ctlCtx) { - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/maintenance/transfer-leadership", Value: `{"targetID": 123}`, Expected: expect.ExpectedResponse{ Value: `"message":"etcdserver: bad leader transferee"`, }, - }); err != nil { - cx.t.Fatalf("failed post maintenance moveleader request: (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "failed post maintenance moveleader request") } func TestCurlV3MaintenanceDowngrade(t *testing.T) { @@ -157,13 +153,12 @@ func TestCurlV3MaintenanceDowngrade(t *testing.T) { } func testCurlV3MaintenanceDowngrade(cx ctlCtx) { - if err := e2e.CURLPost(cx.epc, e2e.CURLReq{ + err := e2e.CURLPost(cx.epc, e2e.CURLReq{ Endpoint: "/v3/maintenance/downgrade", Value: `{"action": 0, "version": "3.0"}`, Expected: expect.ExpectedResponse{ Value: `"message":"etcdserver: invalid downgrade target version"`, }, - }); err != nil { - cx.t.Fatalf("failed post maintenance downgrade request: (%v)", err) - } + }) + require.NoErrorf(cx.t, err, "failed post maintenance downgrade request") } diff --git a/tests/e2e/v3_curl_maxstream_test.go b/tests/e2e/v3_curl_maxstream_test.go index bdf5a2712e7..f51015c244e 100644 --- a/tests/e2e/v3_curl_maxstream_test.go +++ b/tests/e2e/v3_curl_maxstream_test.go @@ -45,9 +45,7 @@ func TestCurlV3_MaxStreams_BelowLimit_NoTLS_Medium(t *testing.T) { func TestCurlV3_MaxStreamsNoTLS_BelowLimit_Large(t *testing.T) { f, err := setRLimit(10240) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) defer f() testCurlV3MaxStream(t, false, withCfg(*e2e.NewConfigNoTLS()), withMaxConcurrentStreams(1000), withTestTimeout(200*time.Second)) } @@ -92,9 +90,7 @@ func testCurlV3MaxStream(t *testing.T, reachLimit bool, opts ...ctlOption) { // Step 2: create the cluster t.Log("Creating an etcd cluster") epc, err := e2e.NewEtcdProcessCluster(context.TODO(), t, e2e.WithConfig(&cx.cfg)) - if err != nil { - t.Fatalf("Failed to start etcd cluster: %v", err) - } + require.NoErrorf(t, err, "Failed to start etcd cluster") cx.epc = epc cx.dataDir = epc.Procs[0].Config().DataDirPath @@ -147,9 +143,7 @@ func submitConcurrentWatch(cx ctlCtx, number int, wgDone *sync.WaitGroup, closeC Key: []byte("foo"), }, }) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) var wgSchedule sync.WaitGroup @@ -194,9 +188,8 @@ func submitConcurrentWatch(cx ctlCtx, number int, wgDone *sync.WaitGroup, closeC go func(i int) { defer wgDone.Done() - if err := createWatchConnection(); err != nil { - cx.t.Fatalf("testCurlV3MaxStream watch failed: %d, error: %v", i, err) - } + err := createWatchConnection() + require.NoErrorf(cx.t, err, "testCurlV3MaxStream watch failed: %d", i) }(i) } @@ -209,9 +202,7 @@ func submitRangeAfterConcurrentWatch(cx ctlCtx, expectedValue string) { rangeData, err := json.Marshal(&pb.RangeRequest{ Key: []byte("foo"), }) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) cx.t.Log("Submitting range request...") if err := e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/kv/range", Value: string(rangeData), Expected: expect.ExpectedResponse{Value: expectedValue}, Timeout: 5}); err != nil { diff --git a/tests/e2e/v3_curl_watch_test.go b/tests/e2e/v3_curl_watch_test.go index 90dce89baa7..303578f1655 100644 --- a/tests/e2e/v3_curl_watch_test.go +++ b/tests/e2e/v3_curl_watch_test.go @@ -32,23 +32,18 @@ func TestCurlV3Watch(t *testing.T) { func testCurlV3Watch(cx ctlCtx) { // store "bar" into "foo" putreq, err := json.Marshal(&pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")}) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) // watch for first update to "foo" wcr := &pb.WatchCreateRequest{Key: []byte("foo"), StartRevision: 1} wreq, err := json.Marshal(wcr) - if err != nil { - cx.t.Fatal(err) - } + require.NoError(cx.t, err) // marshaling the grpc to json gives: // "{"RequestUnion":{"CreateRequest":{"key":"Zm9v","start_revision":1}}}" // but the gprc-gateway expects a different format.. wstr := `{"create_request" : ` + string(wreq) + "}" - if err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/kv/put", Value: string(putreq), Expected: expect.ExpectedResponse{Value: "revision"}}); err != nil { - cx.t.Fatalf("failed testCurlV3Watch put with curl (%v)", err) - } + err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/kv/put", Value: string(putreq), Expected: expect.ExpectedResponse{Value: "revision"}}) + require.NoErrorf(cx.t, err, "failed testCurlV3Watch put with curl") // expects "bar", timeout after 2 seconds since stream waits forever err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: "/v3/watch", Value: wstr, Expected: expect.ExpectedResponse{Value: `"YmFy"`}, Timeout: 2}) require.ErrorContains(cx.t, err, "unexpected exit code") diff --git a/tests/e2e/v3_lease_no_proxy_test.go b/tests/e2e/v3_lease_no_proxy_test.go index d7f44f1e4fc..9a81f112b1d 100644 --- a/tests/e2e/v3_lease_no_proxy_test.go +++ b/tests/e2e/v3_lease_no_proxy_test.go @@ -65,9 +65,8 @@ func testLeaseRevokeIssue(t *testing.T, clusterSize int, connectToOneFollower bo ) require.NoError(t, err) defer func() { - if errC := epc.Close(); errC != nil { - t.Fatalf("error closing etcd processes (%v)", errC) - } + errC := epc.Close() + require.NoErrorf(t, errC, "error closing etcd processes") }() leaderIdx := epc.WaitLeader(t) diff --git a/tests/e2e/zap_logging_test.go b/tests/e2e/zap_logging_test.go index d2598fad5b9..7cb9101c064 100644 --- a/tests/e2e/zap_logging_test.go +++ b/tests/e2e/zap_logging_test.go @@ -32,14 +32,11 @@ func TestServerJsonLogging(t *testing.T) { e2e.WithClusterSize(1), e2e.WithLogLevel("debug"), ) - if err != nil { - t.Fatalf("could not start etcd process cluster (%v)", err) - } + require.NoErrorf(t, err, "could not start etcd process cluster") logs := epc.Procs[0].Logs() time.Sleep(time.Second) - if err = epc.Close(); err != nil { - t.Fatalf("error closing etcd processes (%v)", err) - } + err = epc.Close() + require.NoErrorf(t, err, "error closing etcd processes") var entry logEntry lines := logs.Lines() if len(lines) == 0 {