diff --git a/tests/e2e/ctl_v3_auth_test.go b/tests/e2e/ctl_v3_auth_test.go index 6c252e9c202..0e199593137 100644 --- a/tests/e2e/ctl_v3_auth_test.go +++ b/tests/e2e/ctl_v3_auth_test.go @@ -131,44 +131,39 @@ 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) - } + err := ctlV3Put(cx, key, "val", "") + require.NoError(cx.t, err) } largeKey := "" for i := 0; i < 10; i++ { largeKey += "\xff" - if err := ctlV3Put(cx, largeKey, "val", ""); err != nil { - cx.t.Fatal(err) - } + err := ctlV3Put(cx, largeKey, "val", "") + require.NoError(cx.t, err) } // 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" @@ -180,24 +175,21 @@ func authTestFromKeyPerm(cx ctlCtx) { // 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) - } + err := ctlV3Put(cx, key, "val", "") + require.NoError(cx.t, err) } // 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 +201,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 +276,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) @@ -321,9 +310,8 @@ 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) @@ -340,9 +328,8 @@ func authTestEndpointHealth(cx ctlCtx) { // 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,38 +337,31 @@ 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) - } + err := ctlV3User(cx, []string{"add", "example.com", "--no-password"}, "User example.com created", []string{""}) + require.NoError(cx.t, err) } 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) + err := ctlV3User(cx, []string{"add", "example.com", "--interactive=false"}, "User example.com created", []string{""}) + require.NoError(cx.t, err) } + 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 = "", "" @@ -397,7 +377,7 @@ func certCNAndUsername(cx ctlCtx, noPassword bool) { // 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_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..90155ded93d 100644 --- a/tests/e2e/ctl_v3_make_mirror_test.go +++ b/tests/e2e/ctl_v3_make_mirror_test.go @@ -20,6 +20,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" "go.etcd.io/etcd/tests/v3/framework/e2e" ) @@ -100,26 +101,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_snapshot_test.go b/tests/e2e/ctl_v3_snapshot_test.go index 66f2dbf574e..3785aca3d83 100644 --- a/tests/e2e/ctl_v3_snapshot_test.go +++ b/tests/e2e/ctl_v3_snapshot_test.go @@ -85,9 +85,8 @@ func snapshotCorruptTest(cx ctlCtx) { if oerr != nil { cx.t.Fatal(oerr) } - if _, err := f.Write(make([]byte, 512)); err != nil { - cx.t.Fatal(err) - } + _, err := f.Write(make([]byte, 512)) + require.NoError(cx.t, err) f.Close() datadir := cx.t.TempDir() 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/etcd_release_upgrade_test.go b/tests/e2e/etcd_release_upgrade_test.go index afc73974980..9dd4ec2f9f8 100644 --- a/tests/e2e/etcd_release_upgrade_test.go +++ b/tests/e2e/etcd_release_upgrade_test.go @@ -21,6 +21,8 @@ import ( "testing" "time" + "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 +87,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,9 +146,8 @@ 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) - } + err := ctlV3Put(cx, kvs[i].key, kvs[i].val, "") + require.NoErrorf(cx.t, err, "#%d: ctlV3Put error", i) } for i := range epc.Procs { 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/v3_curl_auth_test.go b/tests/e2e/v3_curl_auth_test.go index 04f07b48013..ef164219ed2 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 (%v)") // 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 {