Skip to content

Commit

Permalink
tests: wip errors.Is conversions
Browse files Browse the repository at this point in the history
Signed-off-by: redwrasse <[email protected]>
  • Loading branch information
redwrasse committed Sep 24, 2024
1 parent fd83aba commit 5e63c25
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/clientv3/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"context"
"crypto/sha256"
"errors"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/clientv3/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package clientv3test

import (
"context"
"errors"
"fmt"
"testing"
"time"
Expand All @@ -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)
}

Expand Down
7 changes: 4 additions & 3 deletions tests/integration/clientv3/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package clientv3test

import (
"context"
"errors"
"testing"
"time"

Expand All @@ -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)
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/v3_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package integration
import (
"context"
"crypto/tls"
"errors"
"testing"
"time"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5e63c25

Please sign in to comment.