From 5e63c25039a62a32a7c7f1d73627a234538d95fe Mon Sep 17 00:00:00 2001 From: redwrasse Date: Mon, 23 Sep 2024 21:44:13 -0700 Subject: [PATCH] tests: wip errors.Is conversions Signed-off-by: redwrasse --- .../clientv3/connectivity/network_partition_test.go | 4 ++-- tests/integration/clientv3/maintenance_test.go | 3 ++- tests/integration/clientv3/txn_test.go | 3 ++- tests/integration/clientv3/user_test.go | 7 ++++--- tests/integration/v3_tls_test.go | 3 ++- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/integration/clientv3/connectivity/network_partition_test.go b/tests/integration/clientv3/connectivity/network_partition_test.go index b72b7aea288..b46804d3a8e 100644 --- a/tests/integration/clientv3/connectivity/network_partition_test.go +++ b/tests/integration/clientv3/connectivity/network_partition_test.go @@ -267,7 +267,7 @@ func testBalancerUnderNetworkPartitionWatch(t *testing.T, isolateLeader bool) { if len(ev.Events) != 0 { t.Fatal("expected no event") } - if err = ev.Err(); err != rpctypes.ErrNoLeader { + if err = ev.Err(); !errors.Is(err, rpctypes.ErrNoLeader) { t.Fatalf("expected %v, got %v", rpctypes.ErrNoLeader, err) } case <-time.After(integration2.RequestWaitTimeout): // enough time to detect leader lost @@ -313,7 +313,7 @@ func TestDropReadUnderNetworkPartition(t *testing.T) { ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second) _, err = kvc.Get(ctx, "a") cancel() - if err != rpctypes.ErrLeaderChanged { + if !errors.Is(err, rpctypes.ErrLeaderChanged) { t.Fatalf("expected %v, got %v", rpctypes.ErrLeaderChanged, err) } diff --git a/tests/integration/clientv3/maintenance_test.go b/tests/integration/clientv3/maintenance_test.go index 7dc912a3a2f..475fc9e18bd 100644 --- a/tests/integration/clientv3/maintenance_test.go +++ b/tests/integration/clientv3/maintenance_test.go @@ -18,6 +18,7 @@ import ( "bytes" "context" "crypto/sha256" + "errors" "fmt" "io" "math" @@ -135,7 +136,7 @@ func TestMaintenanceMoveLeader(t *testing.T) { cli := clus.Client(targetIdx) _, err := cli.MoveLeader(context.Background(), target) - if err != rpctypes.ErrNotLeader { + if !errors.Is(err, rpctypes.ErrNotLeader) { t.Fatalf("error expected %v, got %v", rpctypes.ErrNotLeader, err) } diff --git a/tests/integration/clientv3/txn_test.go b/tests/integration/clientv3/txn_test.go index 84a56146d99..d1517bda493 100644 --- a/tests/integration/clientv3/txn_test.go +++ b/tests/integration/clientv3/txn_test.go @@ -16,6 +16,7 @@ package clientv3test import ( "context" + "errors" "fmt" "testing" "time" @@ -36,7 +37,7 @@ func TestTxnError(t *testing.T) { ctx := context.TODO() _, err := kv.Txn(ctx).Then(clientv3.OpPut("foo", "bar1"), clientv3.OpPut("foo", "bar2")).Commit() - if err != rpctypes.ErrDuplicateKey { + if !errors.Is(err, rpctypes.ErrDuplicateKey) { t.Fatalf("expected %v, got %v", rpctypes.ErrDuplicateKey, err) } diff --git a/tests/integration/clientv3/user_test.go b/tests/integration/clientv3/user_test.go index 49b4c18ea45..c0126915d49 100644 --- a/tests/integration/clientv3/user_test.go +++ b/tests/integration/clientv3/user_test.go @@ -16,6 +16,7 @@ package clientv3test import ( "context" + "errors" "testing" "time" @@ -41,17 +42,17 @@ func TestUserError(t *testing.T) { } _, err = authapi.UserAdd(context.TODO(), "foo", "bar") - if err != rpctypes.ErrUserAlreadyExist { + if !errors.Is(err, rpctypes.ErrUserAlreadyExist) { t.Fatalf("expected %v, got %v", rpctypes.ErrUserAlreadyExist, err) } _, err = authapi.UserDelete(context.TODO(), "not-exist-user") - if err != rpctypes.ErrUserNotFound { + if !errors.Is(err, rpctypes.ErrUserNotFound) { t.Fatalf("expected %v, got %v", rpctypes.ErrUserNotFound, err) } _, err = authapi.UserGrantRole(context.TODO(), "foo", "test-role-does-not-exist") - if err != rpctypes.ErrRoleNotFound { + if !errors.Is(err, rpctypes.ErrRoleNotFound) { t.Fatalf("expected %v, got %v", rpctypes.ErrRoleNotFound, err) } } diff --git a/tests/integration/v3_tls_test.go b/tests/integration/v3_tls_test.go index a13ad5c0beb..fbdf2bb8b5e 100644 --- a/tests/integration/v3_tls_test.go +++ b/tests/integration/v3_tls_test.go @@ -17,6 +17,7 @@ package integration import ( "context" "crypto/tls" + "errors" "testing" "time" @@ -72,7 +73,7 @@ func testTLSCipherSuites(t *testing.T, valid bool) { if cli != nil { cli.Close() } - if !valid && cerr != context.DeadlineExceeded { + if !valid && !errors.Is(cerr, context.DeadlineExceeded) { t.Fatalf("expected %v with TLS handshake failure, got %v", context.DeadlineExceeded, cerr) } if valid && cerr != nil {