tests: wip errors.Is conversions

Signed-off-by: redwrasse <mail@redwrasse.io>
This commit is contained in:
redwrasse 2024-09-23 21:44:13 -07:00
parent fd83aba9b9
commit 5e63c25039
5 changed files with 12 additions and 8 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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 {