diff --git a/client/internal/v2/README.md b/client/internal/v2/README.md index 9ec7d86ecaae..ff070c72db22 100644 --- a/client/internal/v2/README.md +++ b/client/internal/v2/README.md @@ -88,11 +88,12 @@ if err != nil { kapi := client.NewKeysAPI(c) resp, err := kapi.Set(ctx, "test", "bar", nil) if err != nil { - if err == context.Canceled { + var cerr *client.ClusterError + if errors.Is(err, context.Canceled) { // ctx is canceled by another routine - } else if err == context.DeadlineExceeded { + } else if errors.Is(err, context.DeadlineExceeded) { // ctx is attached with a deadline and it exceeded - } else if cerr, ok := err.(*client.ClusterError); ok { + } else if errors.As(err, &cerr) { // process (cerr.Errors) } else { // bad cluster endpoints, which are not etcd servers diff --git a/client/pkg/fileutil/preallocate_darwin.go b/client/pkg/fileutil/preallocate_darwin.go index 795199592342..441fe9eb11cd 100644 --- a/client/pkg/fileutil/preallocate_darwin.go +++ b/client/pkg/fileutil/preallocate_darwin.go @@ -40,7 +40,7 @@ func preallocFixed(f *os.File, sizeInBytes int64) error { Length: sizeInBytes, } err := unix.FcntlFstore(f.Fd(), unix.F_PREALLOCATE, fstore) - if err == nil || err == unix.ENOTSUP { + if err == nil || errors.Is(err, unix.ENOTSUP) { return nil } diff --git a/client/v3/client.go b/client/v3/client.go index 6b7b5632fedd..29c2feebbec2 100644 --- a/client/v3/client.go +++ b/client/v3/client.go @@ -220,7 +220,7 @@ func (c *Client) autoSync() { ctx, cancel := context.WithTimeout(c.ctx, 5*time.Second) err := c.Sync(ctx) cancel() - if err != nil && err != c.ctx.Err() { + if err != nil && !errors.Is(err, c.ctx.Err()) { c.lg.Info("Auto sync endpoints failed.", zap.Error(err)) } } diff --git a/client/v3/retry_interceptor.go b/client/v3/retry_interceptor.go index b15a40bf6fd4..34fb87a60da5 100644 --- a/client/v3/retry_interceptor.go +++ b/client/v3/retry_interceptor.go @@ -146,14 +146,14 @@ func (c *Client) streamClientInterceptor(optFuncs ...retryOption) grpc.StreamCli // shouldRefreshToken checks whether there's a need to refresh the token based on the error and callOptions, // and returns a boolean value. func (c *Client) shouldRefreshToken(err error, callOpts *options) bool { - if rpctypes.Error(err) == rpctypes.ErrUserEmpty { + if errors.Is(rpctypes.Error(err), rpctypes.ErrUserEmpty) { // refresh the token when username, password is present but the server returns ErrUserEmpty // which is possible when the client token is cleared somehow return c.authTokenBundle != nil // equal to c.Username != "" && c.Password != "" } return callOpts.retryAuth && - (rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken || rpctypes.Error(err) == rpctypes.ErrAuthOldRevision) + (errors.Is(rpctypes.Error(err), rpctypes.ErrInvalidAuthToken) || errors.Is(rpctypes.Error(err), rpctypes.ErrAuthOldRevision)) } func (c *Client) refreshToken(ctx context.Context) error { @@ -254,7 +254,7 @@ func (s *serverStreamingRetryingStream) receiveMsgAndIndicateRetry(m any) (bool, wasGood := s.receivedGood s.mu.RUnlock() err := s.getStream().RecvMsg(m) - if err == nil || err == io.EOF { + if err == nil || errors.Is(err, io.EOF) { s.mu.Lock() s.receivedGood = true s.mu.Unlock() diff --git a/contrib/raftexample/kvstore.go b/contrib/raftexample/kvstore.go index 11bbf1fc6e72..b319677cadad 100644 --- a/contrib/raftexample/kvstore.go +++ b/contrib/raftexample/kvstore.go @@ -18,7 +18,6 @@ import ( "bytes" "encoding/gob" "encoding/json" - "errors" "log" "strings" "sync" @@ -114,7 +113,7 @@ func (s *kvstore) getSnapshot() ([]byte, error) { func (s *kvstore) loadSnapshot() (*raftpb.Snapshot, error) { snapshot, err := s.snapshotter.Load() - if errors.Is(err, snap.ErrNoSnapshot) { + if err == snap.ErrNoSnapshot { return nil, nil } if err != nil { diff --git a/contrib/raftexample/raft.go b/contrib/raftexample/raft.go index fac1a099ac50..18b5354dd328 100644 --- a/contrib/raftexample/raft.go +++ b/contrib/raftexample/raft.go @@ -16,7 +16,6 @@ package main import ( "context" - "errors" "fmt" "log" "net/http" @@ -393,7 +392,7 @@ func (rc *raftNode) maybeTriggerSnapshot(applyDoneC <-chan struct{}) { compactIndex = rc.appliedIndex - snapshotCatchUpEntriesN } if err := rc.raftStorage.Compact(compactIndex); err != nil { - if !errors.Is(err, raft.ErrCompacted) { + if err != raft.ErrCompacted { panic(err) } } else { diff --git a/etcdctl/ctlv3/command/auth_command.go b/etcdctl/ctlv3/command/auth_command.go index 13ccda44d16c..0e443450013d 100644 --- a/etcdctl/ctlv3/command/auth_command.go +++ b/etcdctl/ctlv3/command/auth_command.go @@ -15,7 +15,6 @@ package command import ( - "errors" "fmt" "github.com/spf13/cobra" @@ -83,7 +82,7 @@ func authEnableCommandFunc(cmd *cobra.Command, args []string) { if _, err = cli.AuthEnable(ctx); err == nil { break } - if errors.Is(err, rpctypes.ErrRootRoleNotExist) { + if err == rpctypes.ErrRootRoleNotExist { if _, err = cli.RoleAdd(ctx, "root"); err != nil { break } diff --git a/etcdctl/ctlv3/command/watch_command_test.go b/etcdctl/ctlv3/command/watch_command_test.go index ad4668606ecd..2292deadcbba 100644 --- a/etcdctl/ctlv3/command/watch_command_test.go +++ b/etcdctl/ctlv3/command/watch_command_test.go @@ -15,7 +15,6 @@ package command import ( - "errors" "reflect" "testing" ) @@ -535,7 +534,7 @@ func Test_parseWatchArgs(t *testing.T) { } for i, ts := range tt { watchArgs, execArgs, err := parseWatchArgs(ts.osArgs, ts.commandArgs, ts.envKey, ts.envRange, ts.interactive) - if !errors.Is(err, ts.err) { + if err != ts.err { t.Fatalf("#%d: error expected %v, got %v", i, ts.err, err) } if !reflect.DeepEqual(watchArgs, ts.watchArgs) { diff --git a/pkg/ioutil/readcloser_test.go b/pkg/ioutil/readcloser_test.go index 381a797f7aff..6d13bdcec024 100644 --- a/pkg/ioutil/readcloser_test.go +++ b/pkg/ioutil/readcloser_test.go @@ -16,7 +16,6 @@ package ioutil import ( "bytes" - "errors" "io" "testing" ) @@ -29,7 +28,7 @@ func (rc *readerNilCloser) Close() error { return nil } func TestExactReadCloserExpectEOF(t *testing.T) { buf := bytes.NewBuffer(make([]byte, 10)) rc := NewExactReadCloser(&readerNilCloser{buf}, 1) - if _, err := rc.Read(make([]byte, 10)); !errors.Is(err, ErrExpectEOF) { + if _, err := rc.Read(make([]byte, 10)); err != ErrExpectEOF { t.Fatalf("expected %v, got %v", ErrExpectEOF, err) } } @@ -41,7 +40,7 @@ func TestExactReadCloserShort(t *testing.T) { if _, err := rc.Read(make([]byte, 10)); err != nil { t.Fatalf("Read expected nil err, got %v", err) } - if err := rc.Close(); !errors.Is(err, ErrShortRead) { + if err := rc.Close(); err != ErrShortRead { t.Fatalf("Close expected %v, got %v", ErrShortRead, err) } } diff --git a/server/auth/jwt_test.go b/server/auth/jwt_test.go index 7d211ebf3b02..27369092dd34 100644 --- a/server/auth/jwt_test.go +++ b/server/auth/jwt_test.go @@ -16,7 +16,6 @@ package auth import ( "context" - "errors" "fmt" "testing" "time" @@ -140,7 +139,7 @@ func testJWTInfo(t *testing.T, opts map[string]string) { } _, aerr := verify.assign(ctx, "abc", 123) - if !errors.Is(aerr, ErrVerifyOnly) { + if aerr != ErrVerifyOnly { t.Fatalf("unexpected error when attempting to sign with public key: %v", aerr) } diff --git a/server/auth/store_test.go b/server/auth/store_test.go index 4e1d0c4aac57..a05102f652f8 100644 --- a/server/auth/store_test.go +++ b/server/auth/store_test.go @@ -165,13 +165,13 @@ func TestUserAdd(t *testing.T) { if err == nil { t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err) } - if !errors.Is(err, ErrUserAlreadyExist) { + if err != ErrUserAlreadyExist { t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err) } ua = &pb.AuthUserAddRequest{Name: "", Options: &authpb.UserAddOptions{NoPassword: false}} _, err = as.UserAdd(ua) // add a user with empty name - if !errors.Is(err, ErrUserEmpty) { + if err != ErrUserEmpty { t.Fatal(err) } @@ -227,7 +227,7 @@ func TestCheckPassword(t *testing.T) { if err == nil { t.Fatalf("expected %v, got %v", ErrAuthFailed, err) } - if !errors.Is(err, ErrAuthFailed) { + if err != ErrAuthFailed { t.Fatalf("expected %v, got %v", ErrAuthFailed, err) } @@ -242,7 +242,7 @@ func TestCheckPassword(t *testing.T) { if err == nil { t.Fatalf("expected %v, got %v", ErrAuthFailed, err) } - if !errors.Is(err, ErrAuthFailed) { + if err != ErrAuthFailed { t.Fatalf("expected %v, got %v", ErrAuthFailed, err) } } @@ -264,7 +264,7 @@ func TestUserDelete(t *testing.T) { if err == nil { t.Fatalf("expected %v, got %v", ErrUserNotFound, err) } - if !errors.Is(err, ErrUserNotFound) { + if err != ErrUserNotFound { t.Fatalf("expected %v, got %v", ErrUserNotFound, err) } @@ -288,7 +288,7 @@ func TestUserDeleteAndPermCache(t *testing.T) { // delete a non-existing user _, err = as.UserDelete(ud) - if !errors.Is(err, ErrUserNotFound) { + if err != ErrUserNotFound { t.Fatalf("expected %v, got %v", ErrUserNotFound, err) } @@ -336,7 +336,7 @@ func TestUserChangePassword(t *testing.T) { if err == nil { t.Fatalf("expected %v, got %v", ErrUserNotFound, err) } - if !errors.Is(err, ErrUserNotFound) { + if err != ErrUserNotFound { t.Fatalf("expected %v, got %v", ErrUserNotFound, err) } @@ -359,7 +359,7 @@ func TestRoleAdd(t *testing.T) { // add a role with empty name _, err = as.RoleAdd(&pb.AuthRoleAddRequest{Name: ""}) - if !errors.Is(err, ErrRoleEmpty) { + if err != ErrRoleEmpty { t.Fatal(err) } } @@ -379,7 +379,7 @@ func TestUserGrant(t *testing.T) { if err == nil { t.Errorf("expected %v, got %v", ErrUserNotFound, err) } - if !errors.Is(err, ErrUserNotFound) { + if err != ErrUserNotFound { t.Errorf("expected %v, got %v", ErrUserNotFound, err) } } @@ -455,7 +455,7 @@ func TestIsOpPermitted(t *testing.T) { as.rangePermCacheMu.Lock() delete(as.rangePermCache, "foo") as.rangePermCacheMu.Unlock() - if err := as.isOpPermitted("foo", as.Revision(), perm.Key, perm.RangeEnd, perm.PermType); !errors.Is(err, ErrPermissionDenied) { + if err := as.isOpPermitted("foo", as.Revision(), perm.Key, perm.RangeEnd, perm.PermType); err != ErrPermissionDenied { t.Fatal(err) } @@ -545,7 +545,7 @@ func TestRoleGrantPermission(t *testing.T) { Name: "role-test-1", }) - if !errors.Is(err, ErrPermissionNotGiven) { + if err != ErrPermissionNotGiven { t.Error(err) } @@ -887,13 +887,13 @@ func TestAuthInfoFromCtx(t *testing.T) { ctx = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "Invalid Token"})) _, err = as.AuthInfoFromCtx(ctx) - if !errors.Is(err, ErrInvalidAuthToken) { + if err != ErrInvalidAuthToken { t.Errorf("expected %v, got %v", ErrInvalidAuthToken, err) } ctx = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "Invalid.Token"})) _, err = as.AuthInfoFromCtx(ctx) - if !errors.Is(err, ErrInvalidAuthToken) { + if err != ErrInvalidAuthToken { t.Errorf("expected %v, got %v", ErrInvalidAuthToken, err) } @@ -914,14 +914,14 @@ func TestAuthDisable(t *testing.T) { as.AuthDisable() ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy") _, err := as.Authenticate(ctx, "foo", "bar") - if !errors.Is(err, ErrAuthNotEnabled) { + if err != ErrAuthNotEnabled { t.Errorf("expected %v, got %v", ErrAuthNotEnabled, err) } // Disabling disabled auth to make sure it can return safely if store is already disabled. as.AuthDisable() _, err = as.Authenticate(ctx, "foo", "bar") - if !errors.Is(err, ErrAuthNotEnabled) { + if err != ErrAuthNotEnabled { t.Errorf("expected %v, got %v", ErrAuthNotEnabled, err) } } @@ -980,19 +980,19 @@ func TestIsAdminPermitted(t *testing.T) { // invalid user err = as.IsAdminPermitted(&AuthInfo{Username: "rooti", Revision: 1}) - if !errors.Is(err, ErrUserNotFound) { + if err != ErrUserNotFound { t.Errorf("expected %v, got %v", ErrUserNotFound, err) } // empty user err = as.IsAdminPermitted(&AuthInfo{Username: "", Revision: 1}) - if !errors.Is(err, ErrUserEmpty) { + if err != ErrUserEmpty { t.Errorf("expected %v, got %v", ErrUserEmpty, err) } // non-admin user err = as.IsAdminPermitted(&AuthInfo{Username: "foo", Revision: 1}) - if !errors.Is(err, ErrPermissionDenied) { + if err != ErrPermissionDenied { t.Errorf("expected %v, got %v", ErrPermissionDenied, err) } @@ -1013,13 +1013,13 @@ func TestRecoverFromSnapshot(t *testing.T) { if err == nil { t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err) } - if !errors.Is(err, ErrUserAlreadyExist) { + if err != ErrUserAlreadyExist { t.Fatalf("expected %v, got %v", ErrUserAlreadyExist, err) } ua = &pb.AuthUserAddRequest{Name: "", Options: &authpb.UserAddOptions{NoPassword: false}} _, err = as.UserAdd(ua) // add a user with empty name - if !errors.Is(err, ErrUserEmpty) { + if err != ErrUserEmpty { t.Fatal(err) } @@ -1195,7 +1195,7 @@ func TestUserNoPasswordAdd(t *testing.T) { ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy") _, err = as.Authenticate(ctx, username, "") - if !errors.Is(err, ErrAuthFailed) { + if err != ErrAuthFailed { t.Fatalf("expected %v, got %v", ErrAuthFailed, err) } } @@ -1237,7 +1237,7 @@ func TestUserChangePasswordWithOldLog(t *testing.T) { if err == nil { t.Fatalf("expected %v, got %v", ErrUserNotFound, err) } - if !errors.Is(err, ErrUserNotFound) { + if err != ErrUserNotFound { t.Fatalf("expected %v, got %v", ErrUserNotFound, err) } } diff --git a/server/embed/etcd_test.go b/server/embed/etcd_test.go index 206cbb737b49..e22b6d3544a2 100644 --- a/server/embed/etcd_test.go +++ b/server/embed/etcd_test.go @@ -15,7 +15,6 @@ package embed import ( - "errors" "net/url" "testing" @@ -33,7 +32,7 @@ func TestEmptyClientTLSInfo_createMetricsListener(t *testing.T) { Scheme: "https", Host: "localhost:8080", } - if _, err := e.createMetricsListener(murl); !errors.Is(err, ErrMissingClientTLSInfoForMetricsURL) { + if _, err := e.createMetricsListener(murl); err != ErrMissingClientTLSInfoForMetricsURL { t.Fatalf("expected error %v, got %v", ErrMissingClientTLSInfoForMetricsURL, err) } } diff --git a/server/embed/serve_test.go b/server/embed/serve_test.go index 6150beeecf13..3e23c9ee9afe 100644 --- a/server/embed/serve_test.go +++ b/server/embed/serve_test.go @@ -15,7 +15,6 @@ package embed import ( - "errors" "fmt" "net/url" "os" @@ -44,7 +43,7 @@ func TestStartEtcdWrongToken(t *testing.T) { cfg.Dir = tdir cfg.AuthToken = "wrong-token" - if _, err := StartEtcd(cfg); !errors.Is(err, auth.ErrInvalidAuthOpts) { + if _, err := StartEtcd(cfg); err != auth.ErrInvalidAuthOpts { t.Fatalf("expected %v, got %v", auth.ErrInvalidAuthOpts, err) } } diff --git a/server/etcdmain/config_test.go b/server/etcdmain/config_test.go index f002102897ae..21ceaafb0e52 100644 --- a/server/etcdmain/config_test.go +++ b/server/etcdmain/config_test.go @@ -15,7 +15,6 @@ package etcdmain import ( - "errors" "flag" "fmt" "net/url" @@ -225,7 +224,7 @@ func TestConfigParsingConflictClusteringFlags(t *testing.T) { for i, tt := range conflictArgs { cfg := newConfig() - if err := cfg.parse(tt); !errors.Is(err, embed.ErrConflictBootstrapFlags) { + if err := cfg.parse(tt); err != embed.ErrConflictBootstrapFlags { t.Errorf("%d: err = %v, want %v", i, err, embed.ErrConflictBootstrapFlags) } } @@ -268,7 +267,7 @@ func TestConfigFileConflictClusteringFlags(t *testing.T) { args := []string{fmt.Sprintf("--config-file=%s", tmpfile.Name())} cfg := newConfig() - if err := cfg.parse(args); !errors.Is(err, embed.ErrConflictBootstrapFlags) { + if err := cfg.parse(args); err != embed.ErrConflictBootstrapFlags { t.Errorf("%d: err = %v, want %v", i, err, embed.ErrConflictBootstrapFlags) } } @@ -311,7 +310,7 @@ func TestConfigParsingMissedAdvertiseClientURLsFlag(t *testing.T) { for i, tt := range tests { cfg := newConfig() - if err := cfg.parse(tt.args); !errors.Is(err, tt.werr) { + if err := cfg.parse(tt.args); err != tt.werr { t.Errorf("%d: err = %v, want %v", i, err, tt.werr) } } diff --git a/server/etcdserver/api/membership/cluster_test.go b/server/etcdserver/api/membership/cluster_test.go index c07093878c9e..e5eb210c887a 100644 --- a/server/etcdserver/api/membership/cluster_test.go +++ b/server/etcdserver/api/membership/cluster_test.go @@ -16,7 +16,6 @@ package membership import ( "encoding/json" - "errors" "fmt" "path" "reflect" @@ -459,7 +458,7 @@ func TestClusterValidateConfigurationChangeV2(t *testing.T) { } for i, tt := range tests { err := cl.ValidateConfigurationChange(tt.cc) - if !errors.Is(err, tt.werr) { + if err != tt.werr { t.Errorf("#%d: validateConfigurationChange error = %v, want %v", i, err, tt.werr) } } diff --git a/server/etcdserver/api/rafthttp/msg_codec_test.go b/server/etcdserver/api/rafthttp/msg_codec_test.go index cde7916fc1b6..9b14b45095e9 100644 --- a/server/etcdserver/api/rafthttp/msg_codec_test.go +++ b/server/etcdserver/api/rafthttp/msg_codec_test.go @@ -16,7 +16,6 @@ package rafthttp import ( "bytes" - "errors" "reflect" "testing" @@ -78,13 +77,13 @@ func TestMessage(t *testing.T) { for i, tt := range tests { b := &bytes.Buffer{} enc := &messageEncoder{w: b} - if err := enc.encode(&tt.msg); !errors.Is(err, tt.encodeErr) { + if err := enc.encode(&tt.msg); err != tt.encodeErr { t.Errorf("#%d: encode message error expected %v, got %v", i, tt.encodeErr, err) continue } dec := &messageDecoder{r: b} m, err := dec.decode() - if !errors.Is(err, tt.decodeErr) { + if err != tt.decodeErr { t.Errorf("#%d: decode message error expected %v, got %v", i, tt.decodeErr, err) continue } diff --git a/server/etcdserver/api/rafthttp/pipeline.go b/server/etcdserver/api/rafthttp/pipeline.go index 0790b58d03be..50b8c8dd3f1a 100644 --- a/server/etcdserver/api/rafthttp/pipeline.go +++ b/server/etcdserver/api/rafthttp/pipeline.go @@ -165,7 +165,7 @@ func (p *pipeline) post(data []byte) (err error) { p.picker.unreachable(u) // errMemberRemoved is a critical error since a removed member should // always be stopped. So we use reportCriticalError to report it to errorc. - if errors.Is(err, errMemberRemoved) { + if err == errMemberRemoved { reportCriticalError(err, p.errorc) } return err diff --git a/server/etcdserver/api/rafthttp/snapshot_sender.go b/server/etcdserver/api/rafthttp/snapshot_sender.go index 07971cbbddcc..1f0253f14654 100644 --- a/server/etcdserver/api/rafthttp/snapshot_sender.go +++ b/server/etcdserver/api/rafthttp/snapshot_sender.go @@ -17,7 +17,6 @@ package rafthttp import ( "bytes" "context" - "errors" "io" "net/http" "time" @@ -111,7 +110,7 @@ func (s *snapshotSender) send(merged snap.Message) { // errMemberRemoved is a critical error since a removed member should // always be stopped. So we use reportCriticalError to report it to errorc. - if errors.Is(err, errMemberRemoved) { + if err == errMemberRemoved { reportCriticalError(err, s.errorc) } diff --git a/server/etcdserver/api/rafthttp/stream.go b/server/etcdserver/api/rafthttp/stream.go index ed91b27bd78f..63ffe8fdcbe9 100644 --- a/server/etcdserver/api/rafthttp/stream.go +++ b/server/etcdserver/api/rafthttp/stream.go @@ -16,7 +16,6 @@ package rafthttp import ( "context" - "errors" "fmt" "io" "net/http" @@ -404,7 +403,7 @@ func (cr *streamReader) run() { for { rc, err := cr.dial(t) if err != nil { - if !errors.Is(err, errUnsupportedStreamType) { + if err != errUnsupportedStreamType { cr.status.deactivate(failureType{source: t.String(), action: "dial"}, err.Error()) } } else { @@ -429,7 +428,7 @@ func (cr *streamReader) run() { } switch { // all data is read out - case errors.Is(err, io.EOF): + case err == io.EOF: // connection is closed by the remote case transport.IsClosedConnError(err): default: diff --git a/server/etcdserver/api/rafthttp/stream_test.go b/server/etcdserver/api/rafthttp/stream_test.go index 428010286d9c..5ff4265e568e 100644 --- a/server/etcdserver/api/rafthttp/stream_test.go +++ b/server/etcdserver/api/rafthttp/stream_test.go @@ -256,7 +256,7 @@ func TestStreamReaderDialDetectUnsupport(t *testing.T) { } _, err := sr.dial(typ) - if !errors.Is(err, errUnsupportedStreamType) { + if err != errUnsupportedStreamType { t.Errorf("#%d: error = %v, want %v", i, err, errUnsupportedStreamType) } } diff --git a/server/etcdserver/api/snap/snapshotter_test.go b/server/etcdserver/api/snap/snapshotter_test.go index cad3059fb181..02ce02b4a133 100644 --- a/server/etcdserver/api/snap/snapshotter_test.go +++ b/server/etcdserver/api/snap/snapshotter_test.go @@ -15,7 +15,6 @@ package snap import ( - "errors" "fmt" "hash/crc32" "os" @@ -81,7 +80,7 @@ func TestBadCRC(t *testing.T) { crcTable = crc32.MakeTable(crc32.Koopman) _, err = Read(zaptest.NewLogger(t), filepath.Join(dir, fmt.Sprintf("%016x-%016x.snap", 1, 1))) - if err == nil || !errors.Is(err, ErrCRCMismatch) { + if err == nil || err != ErrCRCMismatch { t.Errorf("err = %v, want %v", err, ErrCRCMismatch) } } @@ -222,7 +221,7 @@ func TestNoSnapshot(t *testing.T) { defer os.RemoveAll(dir) ss := New(zaptest.NewLogger(t), dir) _, err = ss.Load() - if !errors.Is(err, ErrNoSnapshot) { + if err != ErrNoSnapshot { t.Errorf("err = %v, want %v", err, ErrNoSnapshot) } } @@ -241,7 +240,7 @@ func TestEmptySnapshot(t *testing.T) { } _, err = Read(zaptest.NewLogger(t), filepath.Join(dir, "1.snap")) - if !errors.Is(err, ErrEmptySnapshot) { + if err != ErrEmptySnapshot { t.Errorf("err = %v, want %v", err, ErrEmptySnapshot) } } @@ -263,7 +262,7 @@ func TestAllSnapshotBroken(t *testing.T) { ss := New(zaptest.NewLogger(t), dir) _, err = ss.Load() - if !errors.Is(err, ErrNoSnapshot) { + if err != ErrNoSnapshot { t.Errorf("err = %v, want %v", err, ErrNoSnapshot) } } diff --git a/server/etcdserver/api/v2discovery/discovery.go b/server/etcdserver/api/v2discovery/discovery.go index 039c8da7d527..5993d4458ec1 100644 --- a/server/etcdserver/api/v2discovery/discovery.go +++ b/server/etcdserver/api/v2discovery/discovery.go @@ -187,7 +187,7 @@ func (d *discovery) joinCluster(config string) (string, error) { func (d *discovery) getCluster() (string, error) { nodes, size, index, err := d.checkCluster() if err != nil { - if errors.Is(err, ErrFullCluster) { + if err == ErrFullCluster { return nodesToCluster(nodes, size) } return "", err @@ -227,7 +227,7 @@ func (d *discovery) checkCluster() ([]*client.Node, uint64, uint64, error) { if eerr, ok := err.(*client.Error); ok && eerr.Code == client.ErrorCodeKeyNotFound { return nil, 0, 0, ErrSizeNotFound } - if errors.Is(err, client.ErrInvalidJSON) { + if err == client.ErrInvalidJSON { return nil, 0, 0, ErrBadDiscoveryEndpoint } if ce, ok := err.(*client.ClusterError); ok { diff --git a/server/etcdserver/api/v2discovery/discovery_test.go b/server/etcdserver/api/v2discovery/discovery_test.go index 3b59517f9998..91dbfd72aac0 100644 --- a/server/etcdserver/api/v2discovery/discovery_test.go +++ b/server/etcdserver/api/v2discovery/discovery_test.go @@ -212,7 +212,7 @@ func TestCheckCluster(t *testing.T) { } }() ns, size, index, err := d.checkCluster() - if !errors.Is(err, tt.werr) { + if err != tt.werr { t.Errorf("#%d: err = %v, want %v", i, err, tt.werr) } if reflect.DeepEqual(ns, tt.nodes) { @@ -336,7 +336,7 @@ func TestCreateSelf(t *testing.T) { for i, tt := range tests { d := newTestDiscovery(t, "1000", 1, tt.c) - if err := d.createSelf(""); !errors.Is(err, tt.werr) { + if err := d.createSelf(""); err != tt.werr { t.Errorf("#%d: err = %v, want %v", i, err, nil) } } @@ -383,7 +383,7 @@ func TestNodesToCluster(t *testing.T) { for i, tt := range tests { cluster, err := nodesToCluster(tt.nodes, tt.size) - if !errors.Is(err, tt.werr) { + if err != tt.werr { t.Errorf("#%d: err = %v, want %v", i, err, tt.werr) } if !reflect.DeepEqual(cluster, tt.wcluster) { @@ -435,7 +435,7 @@ func TestRetryFailure(t *testing.T) { fc.Advance(time.Second * (0x1 << i)) } }() - if _, _, _, err := d.checkCluster(); !errors.Is(err, ErrTooManyRetries) { + if _, _, _, err := d.checkCluster(); err != ErrTooManyRetries { t.Errorf("err = %v, want %v", err, ErrTooManyRetries) } } diff --git a/server/etcdserver/api/v3discovery/discovery_test.go b/server/etcdserver/api/v3discovery/discovery_test.go index 89b4d3cbbef0..10d63e6486dc 100644 --- a/server/etcdserver/api/v3discovery/discovery_test.go +++ b/server/etcdserver/api/v3discovery/discovery_test.go @@ -91,7 +91,7 @@ func TestGetClusterSize(t *testing.T) { clusterToken: "fakeToken", } - if cs, err := d.getClusterSize(); !errors.Is(err, tc.expectedErr) { + if cs, err := d.getClusterSize(); err != tc.expectedErr { t.Errorf("Unexpected error, expected: %v got: %v", tc.expectedErr, err) } else { if err == nil && cs != tc.expectedSize { @@ -387,7 +387,7 @@ func TestCheckCluster(t *testing.T) { } clsInfo, _, _, err := d.checkCluster() - if !errors.Is(err, tc.expectedError) { + if err != tc.expectedError { t.Errorf("Unexpected error, expected: %v, got: %v", tc.expectedError, err) } @@ -724,7 +724,7 @@ func TestGetInitClusterStr(t *testing.T) { } retStr, err := clsInfo.getInitClusterStr(tc.clusterSize) - if !errors.Is(err, tc.expectedError) { + if err != tc.expectedError { t.Errorf("Unexpected error, expected: %v, got: %v", tc.expectedError, err) } diff --git a/server/etcdserver/api/v3rpc/lease.go b/server/etcdserver/api/v3rpc/lease.go index 19c5973bd81b..86f35113cd99 100644 --- a/server/etcdserver/api/v3rpc/lease.go +++ b/server/etcdserver/api/v3rpc/lease.go @@ -16,7 +16,6 @@ package v3rpc import ( "context" - "errors" "io" "go.uber.org/zap" @@ -62,10 +61,10 @@ func (ls *LeaseServer) LeaseRevoke(ctx context.Context, rr *pb.LeaseRevokeReques func (ls *LeaseServer) LeaseTimeToLive(ctx context.Context, rr *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { resp, err := ls.le.LeaseTimeToLive(ctx, rr) - if err != nil && !errors.Is(err, lease.ErrLeaseNotFound) { + if err != nil && err != lease.ErrLeaseNotFound { return nil, togRPCError(err) } - if errors.Is(err, lease.ErrLeaseNotFound) { + if err == lease.ErrLeaseNotFound { resp = &pb.LeaseTimeToLiveResponse{ Header: &pb.ResponseHeader{}, ID: rr.ID, @@ -81,7 +80,7 @@ func (ls *LeaseServer) LeaseLeases(ctx context.Context, rr *pb.LeaseLeasesReques if err != nil && err != lease.ErrLeaseNotFound { return nil, togRPCError(err) } - if errors.Is(err, lease.ErrLeaseNotFound) { + if err == lease.ErrLeaseNotFound { resp = &pb.LeaseLeasesResponse{ Header: &pb.ResponseHeader{}, Leases: []*pb.LeaseStatus{}, @@ -101,7 +100,7 @@ func (ls *LeaseServer) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) (err case <-stream.Context().Done(): // the only server-side cancellation is noleader for now. err = stream.Context().Err() - if errors.Is(err, context.Canceled) { + if err == context.Canceled { err = rpctypes.ErrGRPCNoLeader } } @@ -111,7 +110,7 @@ func (ls *LeaseServer) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) (err func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) error { for { req, err := stream.Recv() - if errors.Is(err, io.EOF) { + if err == io.EOF { return nil } if err != nil { @@ -134,7 +133,7 @@ func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) erro ls.hdr.fill(resp.Header) ttl, err := ls.le.LeaseRenew(stream.Context(), lease.LeaseID(req.ID)) - if errors.Is(err, lease.ErrLeaseNotFound) { + if err == lease.ErrLeaseNotFound { err = nil ttl = 0 } diff --git a/server/etcdserver/api/v3rpc/util.go b/server/etcdserver/api/v3rpc/util.go index 2354b0cb2431..a31e6cbeccac 100644 --- a/server/etcdserver/api/v3rpc/util.go +++ b/server/etcdserver/api/v3rpc/util.go @@ -16,7 +16,6 @@ package v3rpc import ( "context" - errorspkg "errors" "strings" "google.golang.org/grpc/codes" @@ -96,7 +95,7 @@ var toGRPCErrorMap = map[error]error{ func togRPCError(err error) error { // let gRPC server convert to codes.Canceled, codes.DeadlineExceeded - if errorspkg.Is(err, context.Canceled) || errorspkg.Is(err, context.DeadlineExceeded) { + if err == context.Canceled || err == context.DeadlineExceeded { return err } grpcErr, ok := toGRPCErrorMap[err] diff --git a/server/etcdserver/api/v3rpc/util_test.go b/server/etcdserver/api/v3rpc/util_test.go index 8bd569301c4b..ed686021d2b9 100644 --- a/server/etcdserver/api/v3rpc/util_test.go +++ b/server/etcdserver/api/v3rpc/util_test.go @@ -38,7 +38,7 @@ func TestGRPCError(t *testing.T) { {err: errors.New("foo"), exp: status.Error(codes.Unknown, "foo")}, } for i := range tt { - if err := togRPCError(tt[i].err); !errors.Is(err, tt[i].exp) { + if err := togRPCError(tt[i].err); err != tt[i].exp { if _, ok := status.FromError(err); ok { if err.Error() == tt[i].exp.Error() { continue diff --git a/server/etcdserver/api/v3rpc/watch.go b/server/etcdserver/api/v3rpc/watch.go index abb465e21d71..6e72b1ceb894 100644 --- a/server/etcdserver/api/v3rpc/watch.go +++ b/server/etcdserver/api/v3rpc/watch.go @@ -16,7 +16,6 @@ package v3rpc import ( "context" - "errors" "io" "math/rand" "sync" @@ -212,13 +211,13 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) { // revisited. select { case err = <-errc: - if errors.Is(err, context.Canceled) { + if err == context.Canceled { err = rpctypes.ErrGRPCWatchCanceled } close(sws.ctrlStream) case <-stream.Context().Done(): err = stream.Context().Err() - if errors.Is(err, context.Canceled) { + if err == context.Canceled { err = rpctypes.ErrGRPCWatchCanceled } } @@ -242,7 +241,7 @@ func (sws *serverWatchStream) isWatchPermitted(wcr *pb.WatchCreateRequest) error func (sws *serverWatchStream) recvLoop() error { for { req, err := sws.gRPCStream.Recv() - if errors.Is(err, io.EOF) { + if err == io.EOF { return nil } if err != nil { @@ -281,7 +280,7 @@ func (sws *serverWatchStream) recvLoop() error { case auth.ErrUserEmpty: cancelReason = rpctypes.ErrGRPCUserEmpty.Error() default: - if !errors.Is(err, auth.ErrPermissionDenied) { + if err != auth.ErrPermissionDenied { sws.lg.Error("unexpected error code", zap.Error(err)) } cancelReason = rpctypes.ErrGRPCPermissionDenied.Error() diff --git a/server/etcdserver/api/v3rpc/watch_test.go b/server/etcdserver/api/v3rpc/watch_test.go index e7868ddf8d25..bd3f4943b2ed 100644 --- a/server/etcdserver/api/v3rpc/watch_test.go +++ b/server/etcdserver/api/v3rpc/watch_test.go @@ -16,7 +16,6 @@ package v3rpc import ( "bytes" - "errors" "math" "testing" @@ -70,7 +69,7 @@ func TestSendFragment(t *testing.T) { return nil } err := sendFragments(tt[i].wr, tt[i].maxRequestBytes, testSend) - if !errors.Is(err, tt[i].werr) { + if err != tt[i].werr { t.Errorf("#%d: expected error %v, got %v", i, tt[i].werr, err) } got := len(fragmentedResp) diff --git a/server/etcdserver/apply/apply_auth_test.go b/server/etcdserver/apply/apply_auth_test.go index e7445a10aa95..6516f41b52f2 100644 --- a/server/etcdserver/apply/apply_auth_test.go +++ b/server/etcdserver/apply/apply_auth_test.go @@ -16,7 +16,6 @@ package apply import ( "context" - "errors" "testing" "time" @@ -388,8 +387,8 @@ func TestAuthApplierV3_AdminPermission(t *testing.T) { tc.request.Header = &pb.RequestHeader{Username: userReadOnly} } result := authApplier.Apply(ctx, tc.request, dummyApplyFunc) - require.Equal(t, errors.Is(result.Err, auth.ErrPermissionDenied), tc.adminPermissionNeeded, - "Admin permission needed: got %v, expect: %v", errors.Is(result.Err, auth.ErrPermissionDenied), tc.adminPermissionNeeded) + require.Equal(t, result.Err == auth.ErrPermissionDenied, tc.adminPermissionNeeded, + "Admin permission needed: got %v, expect: %v", result.Err == auth.ErrPermissionDenied, tc.adminPermissionNeeded) }) } } diff --git a/server/etcdserver/server_test.go b/server/etcdserver/server_test.go index e26d6412722f..858aa32a076c 100644 --- a/server/etcdserver/server_test.go +++ b/server/etcdserver/server_test.go @@ -17,7 +17,6 @@ package etcdserver import ( "context" "encoding/json" - errorspkg "errors" "fmt" "math" "net/http" @@ -389,7 +388,7 @@ func TestApplyConfChangeError(t *testing.T) { cluster: cl, } _, err := srv.applyConfChange(tt.cc, nil, true) - if !errorspkg.Is(err, tt.werr) { + if err != tt.werr { t.Errorf("#%d: applyConfChange error = %v, want %v", i, err, tt.werr) } cc := raftpb.ConfChange{Type: tt.cc.Type, NodeID: raft.None, Context: tt.cc.Context} @@ -1534,7 +1533,7 @@ func TestWaitAppliedIndex(t *testing.T) { err := s.waitAppliedIndex() - if !errorspkg.Is(err, tc.ExpectedError) { + if err != tc.ExpectedError { t.Errorf("Unexpected error, want (%v), got (%v)", tc.ExpectedError, err) } }) diff --git a/server/lease/leasehttp/http.go b/server/lease/leasehttp/http.go index 9592b63cb97b..5837ac40b172 100644 --- a/server/lease/leasehttp/http.go +++ b/server/lease/leasehttp/http.go @@ -75,7 +75,7 @@ func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } ttl, rerr := h.l.Renew(lease.LeaseID(lreq.ID)) if rerr != nil { - if errors.Is(rerr, lease.ErrLeaseNotFound) { + if rerr == lease.ErrLeaseNotFound { http.Error(w, rerr.Error(), http.StatusNotFound) return } diff --git a/server/lease/lessor_test.go b/server/lease/lessor_test.go index f46e2b399495..0d32300abafb 100644 --- a/server/lease/lessor_test.go +++ b/server/lease/lessor_test.go @@ -16,7 +16,6 @@ package lease import ( "context" - "errors" "fmt" "os" "path/filepath" @@ -455,7 +454,7 @@ func TestLessorExpire(t *testing.T) { donec := make(chan struct{}, 1) go func() { // expired lease cannot be renewed - if _, err := le.Renew(l.ID); !errors.Is(err, ErrLeaseNotFound) { + if _, err := le.Renew(l.ID); err != ErrLeaseNotFound { t.Errorf("unexpected renew") } donec <- struct{}{} @@ -508,7 +507,7 @@ func TestLessorExpireAndDemote(t *testing.T) { donec := make(chan struct{}, 1) go func() { // expired lease cannot be renewed - if _, err := le.Renew(l.ID); !errors.Is(err, ErrNotPrimary) { + if _, err := le.Renew(l.ID); err != ErrNotPrimary { t.Errorf("unexpected renew: %v", err) } donec <- struct{}{} @@ -540,7 +539,7 @@ func TestLessorMaxTTL(t *testing.T) { defer le.Stop() _, err := le.Grant(1, MaxLeaseTTL+1) - if !errors.Is(err, ErrLeaseTTLTooLarge) { + if err != ErrLeaseTTLTooLarge { t.Fatalf("grant unexpectedly succeeded") } } diff --git a/server/proxy/grpcproxy/lease.go b/server/proxy/grpcproxy/lease.go index dc42dc5a0d88..fdc936ca9295 100644 --- a/server/proxy/grpcproxy/lease.go +++ b/server/proxy/grpcproxy/lease.go @@ -16,7 +16,6 @@ package grpcproxy import ( "context" - "errors" "io" "sync" "sync/atomic" @@ -246,7 +245,7 @@ type leaseProxyStream struct { func (lps *leaseProxyStream) recvLoop() error { for { rr, err := lps.stream.Recv() - if errors.Is(err, io.EOF) { + if err == io.EOF { return nil } if err != nil { diff --git a/server/proxy/grpcproxy/maintenance.go b/server/proxy/grpcproxy/maintenance.go index 553b66c4b73b..50ecf67ffa06 100644 --- a/server/proxy/grpcproxy/maintenance.go +++ b/server/proxy/grpcproxy/maintenance.go @@ -16,7 +16,6 @@ package grpcproxy import ( "context" - "errors" "io" pb "go.etcd.io/etcd/api/v3/etcdserverpb" @@ -51,7 +50,7 @@ func (mp *maintenanceProxy) Snapshot(sr *pb.SnapshotRequest, stream pb.Maintenan for { rr, err := sc.Recv() if err != nil { - if errors.Is(err, io.EOF) { + if err == io.EOF { return nil } return err diff --git a/server/storage/mvcc/index_test.go b/server/storage/mvcc/index_test.go index 64c5ecd407e9..5973ecbe4bed 100644 --- a/server/storage/mvcc/index_test.go +++ b/server/storage/mvcc/index_test.go @@ -15,7 +15,6 @@ package mvcc import ( - "errors" "reflect" "testing" @@ -47,7 +46,7 @@ func TestIndexGet(t *testing.T) { } for i, tt := range tests { rev, created, ver, err := ti.Get([]byte("foo"), tt.rev) - if !errors.Is(err, tt.werr) { + if err != tt.werr { t.Errorf("#%d: err = %v, want %v", i, err, tt.werr) } if rev != tt.wrev { @@ -131,11 +130,11 @@ func TestIndexTombstone(t *testing.T) { } _, _, _, err = ti.Get([]byte("foo"), 2) - if !errors.Is(err, ErrRevisionNotFound) { + if err != ErrRevisionNotFound { t.Errorf("get error = %v, want ErrRevisionNotFound", err) } err = ti.Tombstone([]byte("foo"), Revision{Main: 3}) - if !errors.Is(err, ErrRevisionNotFound) { + if err != ErrRevisionNotFound { t.Errorf("tombstone error = %v, want %v", err, ErrRevisionNotFound) } } diff --git a/server/storage/mvcc/key_index_test.go b/server/storage/mvcc/key_index_test.go index 273f06e3402b..63436428cbd3 100644 --- a/server/storage/mvcc/key_index_test.go +++ b/server/storage/mvcc/key_index_test.go @@ -15,7 +15,6 @@ package mvcc import ( - "errors" "reflect" "testing" @@ -74,7 +73,7 @@ func TestKeyIndexGet(t *testing.T) { for i, tt := range tests { mod, creat, ver, err := ki.get(zaptest.NewLogger(t), tt.rev) - if !errors.Is(err, tt.werr) { + if err != tt.werr { t.Errorf("#%d: err = %v, want %v", i, err, tt.werr) } if mod != tt.wmod { @@ -214,7 +213,7 @@ func TestKeyIndexTombstone(t *testing.T) { } err = ki.tombstone(zaptest.NewLogger(t), 16, 0) - if !errors.Is(err, ErrRevisionNotFound) { + if err != ErrRevisionNotFound { t.Errorf("tombstone error = %v, want %v", err, ErrRevisionNotFound) } } diff --git a/server/storage/mvcc/kv_test.go b/server/storage/mvcc/kv_test.go index 0a3a2ad736f3..9b8243c334c6 100644 --- a/server/storage/mvcc/kv_test.go +++ b/server/storage/mvcc/kv_test.go @@ -16,7 +16,6 @@ package mvcc import ( "context" - "errors" "fmt" "os" "reflect" @@ -204,7 +203,7 @@ func testKVRangeBadRev(t *testing.T, f rangeFunc) { } for i, tt := range tests { _, err := f(s, []byte("foo"), []byte("foo3"), RangeOptions{Rev: tt.rev}) - if !errors.Is(err, tt.werr) { + if err != tt.werr { t.Errorf("#%d: error = %v, want %v", i, err, tt.werr) } } @@ -627,7 +626,7 @@ func TestKVCompactBad(t *testing.T) { } for i, tt := range tests { _, err := s.Compact(traceutil.TODO(), tt.rev) - if !errors.Is(err, tt.werr) { + if err != tt.werr { t.Errorf("#%d: compact error = %v, want %v", i, err, tt.werr) } } diff --git a/server/storage/mvcc/kvstore_test.go b/server/storage/mvcc/kvstore_test.go index ed14cdebd68d..0523dcde983f 100644 --- a/server/storage/mvcc/kvstore_test.go +++ b/server/storage/mvcc/kvstore_test.go @@ -19,7 +19,6 @@ import ( "context" "crypto/rand" "encoding/binary" - "errors" "fmt" "math" mrand "math/rand" @@ -519,7 +518,7 @@ func TestRestoreContinueUnfinishedCompaction(t *testing.T) { // wait for scheduled compaction to be finished time.Sleep(100 * time.Millisecond) - if _, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: 1}); !errors.Is(err, ErrCompacted) { + if _, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: 1}); err != ErrCompacted { t.Errorf("range on compacted rev error = %v, want %v", err, ErrCompacted) } // check the key in backend is deleted diff --git a/server/storage/mvcc/watcher_test.go b/server/storage/mvcc/watcher_test.go index a53253a08c02..41bbb5108753 100644 --- a/server/storage/mvcc/watcher_test.go +++ b/server/storage/mvcc/watcher_test.go @@ -16,7 +16,6 @@ package mvcc import ( "bytes" - "errors" "fmt" "os" "reflect" @@ -109,7 +108,7 @@ func TestWatcherRequestsCustomID(t *testing.T) { for i, tcase := range tt { id, err := w.Watch(tcase.givenID, []byte("foo"), nil, 0) if tcase.expectedErr != nil || err != nil { - if !errors.Is(err, tcase.expectedErr) { + if err != tcase.expectedErr { t.Errorf("expected get error %q in test case %q, got %q", tcase.expectedErr, i, err) } } else if tcase.expectedID != id { @@ -202,10 +201,10 @@ func TestWatcherWatchWrongRange(t *testing.T) { w := s.NewWatchStream() defer w.Close() - if _, err := w.Watch(0, []byte("foa"), []byte("foa"), 1); !errors.Is(err, ErrEmptyWatcherRange) { + if _, err := w.Watch(0, []byte("foa"), []byte("foa"), 1); err != ErrEmptyWatcherRange { t.Fatalf("key == end range given; expected ErrEmptyWatcherRange, got %+v", err) } - if _, err := w.Watch(0, []byte("fob"), []byte("foa"), 1); !errors.Is(err, ErrEmptyWatcherRange) { + if _, err := w.Watch(0, []byte("fob"), []byte("foa"), 1); err != ErrEmptyWatcherRange { t.Fatalf("key > end range given; expected ErrEmptyWatcherRange, got %+v", err) } // watch request with 'WithFromKey' has empty-byte range end @@ -279,7 +278,7 @@ func TestWatchStreamCancelWatcherByID(t *testing.T) { for i, tt := range tests { gerr := w.Cancel(tt.cancelID) - if !errors.Is(gerr, tt.werr) { + if gerr != tt.werr { t.Errorf("#%d: err = %v, want %v", i, gerr, tt.werr) } } diff --git a/server/storage/schema/actions_test.go b/server/storage/schema/actions_test.go index d3cb812c11e9..4e61a0dac9a7 100644 --- a/server/storage/schema/actions_test.go +++ b/server/storage/schema/actions_test.go @@ -15,7 +15,6 @@ package schema import ( - "errors" "fmt" "testing" "time" @@ -136,7 +135,7 @@ func TestActionListRevert(t *testing.T) { UnsafeCreateMetaBucket(tx) err := tc.actions.unsafeExecute(lg, tx) - if !errors.Is(err, tc.expectError) { + if err != tc.expectError { t.Errorf("Unexpected error or lack thereof, expected: %v, got: %v", tc.expectError, err) } assertBucketState(t, tx, Meta, tc.expectState) diff --git a/server/storage/schema/migration_test.go b/server/storage/schema/migration_test.go index 9ebe80dcb059..fccf20296899 100644 --- a/server/storage/schema/migration_test.go +++ b/server/storage/schema/migration_test.go @@ -15,7 +15,6 @@ package schema import ( - "errors" "fmt" "testing" "time" @@ -179,7 +178,7 @@ func TestMigrationStepExecute(t *testing.T) { step := newMigrationStep(tc.currentVersion, tc.isUpgrade, tc.changes) err := step.unsafeExecute(lg, tx) - if !errors.Is(err, tc.expectError) { + if err != tc.expectError { t.Errorf("Unexpected error or lack thereof, expected: %v, got: %v", tc.expectError, err) } v := UnsafeReadStorageVersion(tx) diff --git a/server/storage/wal/decoder.go b/server/storage/wal/decoder.go index 01ffbd52bd94..0f47b72fd3ee 100644 --- a/server/storage/wal/decoder.go +++ b/server/storage/wal/decoder.go @@ -16,7 +16,6 @@ package wal import ( "encoding/binary" - "errors" "fmt" "hash" "io" @@ -115,7 +114,7 @@ func (d *decoder) decodeRecord(rec *walpb.Record) error { if _, err = io.ReadFull(fileBufReader, data); err != nil { // ReadFull returns io.EOF only if no bytes were read // the decoder should treat this as an ErrUnexpectedEOF instead. - if errors.Is(err, io.EOF) { + if err == io.EOF { err = io.ErrUnexpectedEOF } return err diff --git a/server/storage/wal/repair_test.go b/server/storage/wal/repair_test.go index a1abdcac38d9..38e3641bd7b3 100644 --- a/server/storage/wal/repair_test.go +++ b/server/storage/wal/repair_test.go @@ -15,7 +15,6 @@ package wal import ( - "errors" "fmt" "io" "os" @@ -203,7 +202,7 @@ func TestRepairFailDeleteDir(t *testing.T) { t.Fatal(err) } _, _, _, err = w.ReadAll() - if !errors.Is(err, io.ErrUnexpectedEOF) { + if err != io.ErrUnexpectedEOF { t.Fatalf("err = %v, want error %v", err, io.ErrUnexpectedEOF) } w.Close() diff --git a/server/storage/wal/wal_test.go b/server/storage/wal/wal_test.go index c739ddf0a558..ed3a8893df55 100644 --- a/server/storage/wal/wal_test.go +++ b/server/storage/wal/wal_test.go @@ -101,7 +101,7 @@ func TestCreateFailFromPollutedDir(t *testing.T) { os.WriteFile(filepath.Join(p, "test.wal"), []byte("data"), os.ModeTemporary) _, err := Create(zaptest.NewLogger(t), p, []byte("data")) - if !errors.Is(err, os.ErrExist) { + if err != os.ErrExist { t.Fatalf("expected %v, got %v", os.ErrExist, err) } } @@ -152,7 +152,7 @@ func TestNewForInitedDir(t *testing.T) { p := t.TempDir() os.Create(filepath.Join(p, walName(0, 0))) - if _, err := Create(zaptest.NewLogger(t), p, nil); err == nil || !errors.Is(err, os.ErrExist) { + if _, err := Create(zaptest.NewLogger(t), p, nil); err == nil || err != os.ErrExist { t.Errorf("err = %v, want %v", err, os.ErrExist) } } @@ -663,7 +663,7 @@ func TestOpenWithMaxIndex(t *testing.T) { defer w2.Close() _, _, _, err = w2.ReadAll() - if !errors.Is(err, ErrSliceOutOfRange) { + if err != ErrSliceOutOfRange { t.Fatalf("err = %v, want ErrSliceOutOfRange", err) } } @@ -964,7 +964,7 @@ func TestReadAllFail(t *testing.T) { f.Close() // try to read without opening the WAL _, _, _, err = f.ReadAll() - if err == nil || !errors.Is(err, ErrDecoderNotFound) { + if err == nil || err != ErrDecoderNotFound { t.Fatalf("err = %v, want ErrDecoderNotFound", err) } } diff --git a/tests/e2e/ctl_v3_member_test.go b/tests/e2e/ctl_v3_member_test.go index 08faf7419028..bd045e5f63b4 100644 --- a/tests/e2e/ctl_v3_member_test.go +++ b/tests/e2e/ctl_v3_member_test.go @@ -17,7 +17,6 @@ package e2e import ( "context" "encoding/json" - "errors" "fmt" "io" "reflect" @@ -194,7 +193,7 @@ func getMemberList(cx ctlCtx, serializable bool) (etcdserverpb.MemberListRespons resp := etcdserverpb.MemberListResponse{} dec := json.NewDecoder(strings.NewReader(txt)) - if err := dec.Decode(&resp); errors.Is(err, io.EOF) { + if err := dec.Decode(&resp); err == io.EOF { return etcdserverpb.MemberListResponse{}, err } return resp, nil @@ -222,7 +221,7 @@ func memberListWithHexTest(cx ctlCtx) { } hexResp := etcdserverpb.MemberListResponse{} dec := json.NewDecoder(strings.NewReader(txt)) - if err := dec.Decode(&hexResp); errors.Is(err, io.EOF) { + if err := dec.Decode(&hexResp); err == io.EOF { cx.t.Fatalf("memberListWithHexTest error (%v)", err) } num := len(resp.Members) diff --git a/tests/e2e/ctl_v3_snapshot_test.go b/tests/e2e/ctl_v3_snapshot_test.go index b9ef782ffcfc..bb3f1f06fe05 100644 --- a/tests/e2e/ctl_v3_snapshot_test.go +++ b/tests/e2e/ctl_v3_snapshot_test.go @@ -17,7 +17,6 @@ package e2e import ( "context" "encoding/json" - "errors" "fmt" "io" "os" @@ -157,7 +156,7 @@ func getSnapshotStatus(cx ctlCtx, fpath string) (snapshot.Status, error) { resp := snapshot.Status{} dec := json.NewDecoder(strings.NewReader(txt)) - if err := dec.Decode(&resp); errors.Is(err, io.EOF) { + if err := dec.Decode(&resp); err == io.EOF { return snapshot.Status{}, err } return resp, nil diff --git a/tests/integration/clientv3/concurrency/example_mutex_test.go b/tests/integration/clientv3/concurrency/example_mutex_test.go index eba8c543f2c7..c3b593aed9b7 100644 --- a/tests/integration/clientv3/concurrency/example_mutex_test.go +++ b/tests/integration/clientv3/concurrency/example_mutex_test.go @@ -16,7 +16,6 @@ package concurrency_test import ( "context" - "errors" "fmt" "log" @@ -65,7 +64,7 @@ func ExampleMutex_TryLock() { if err = m2.TryLock(context.TODO()); err == nil { log.Fatal("should not acquire lock") } - if errors.Is(err, concurrency.ErrLocked) { + if err == concurrency.ErrLocked { fmt.Println("cannot acquire lock for s2, as already locked in another session") } diff --git a/tests/integration/clientv3/connectivity/black_hole_test.go b/tests/integration/clientv3/connectivity/black_hole_test.go index e1fc1c57b971..c0e16aefe1de 100644 --- a/tests/integration/clientv3/connectivity/black_hole_test.go +++ b/tests/integration/clientv3/connectivity/black_hole_test.go @@ -18,7 +18,6 @@ package connectivity_test import ( "context" - "errors" "testing" "time" @@ -114,7 +113,7 @@ func TestBalancerUnderBlackholeKeepAliveWatch(t *testing.T) { func TestBalancerUnderBlackholeNoKeepAlivePut(t *testing.T) { testBalancerUnderBlackholeNoKeepAlive(t, func(cli *clientv3.Client, ctx context.Context) error { _, err := cli.Put(ctx, "foo", "bar") - if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) { + if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout { return errExpected } return err @@ -124,7 +123,7 @@ func TestBalancerUnderBlackholeNoKeepAlivePut(t *testing.T) { func TestBalancerUnderBlackholeNoKeepAliveDelete(t *testing.T) { testBalancerUnderBlackholeNoKeepAlive(t, func(cli *clientv3.Client, ctx context.Context) error { _, err := cli.Delete(ctx, "foo") - if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) { + if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout { return errExpected } return err @@ -137,7 +136,7 @@ func TestBalancerUnderBlackholeNoKeepAliveTxn(t *testing.T) { If(clientv3.Compare(clientv3.Version("foo"), "=", 0)). Then(clientv3.OpPut("foo", "bar")). Else(clientv3.OpPut("foo", "baz")).Commit() - if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) { + if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout { return errExpected } return err @@ -147,7 +146,7 @@ func TestBalancerUnderBlackholeNoKeepAliveTxn(t *testing.T) { func TestBalancerUnderBlackholeNoKeepAliveLinearizableGet(t *testing.T) { testBalancerUnderBlackholeNoKeepAlive(t, func(cli *clientv3.Client, ctx context.Context) error { _, err := cli.Get(ctx, "a") - if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) { + if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout { return errExpected } return err @@ -208,7 +207,7 @@ func testBalancerUnderBlackholeNoKeepAlive(t *testing.T, op func(*clientv3.Clien cancel() if err == nil { break - } else if errors.Is(err, errExpected) { + } else if err == errExpected { t.Logf("#%d: current error %v", i, err) } else { t.Errorf("#%d: failed with error %v", i, err) diff --git a/tests/integration/clientv3/connectivity/network_partition_test.go b/tests/integration/clientv3/connectivity/network_partition_test.go index 6c99c32d04c1..b72b7aea2886 100644 --- a/tests/integration/clientv3/connectivity/network_partition_test.go +++ b/tests/integration/clientv3/connectivity/network_partition_test.go @@ -35,7 +35,7 @@ var errExpected = errors.New("expected error") func isErrorExpected(err error) bool { return clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || - errors.Is(err, rpctypes.ErrTimeout) || errors.Is(err, rpctypes.ErrTimeoutDueToLeaderFail) + err == rpctypes.ErrTimeout || err == rpctypes.ErrTimeoutDueToLeaderFail } // TestBalancerUnderNetworkPartitionPut tests when one member becomes isolated, @@ -145,7 +145,7 @@ func testBalancerUnderNetworkPartition(t *testing.T, op func(*clientv3.Client, c if err == nil { break } - if !errors.Is(err, errExpected) { + if err != errExpected { t.Errorf("#%d: expected '%v', got '%v'", i, errExpected, err) } // give enough time for endpoint switch @@ -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(); !errors.Is(err, rpctypes.ErrNoLeader) { + if err = ev.Err(); 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 !errors.Is(err, rpctypes.ErrLeaderChanged) { + if err != rpctypes.ErrLeaderChanged { t.Fatalf("expected %v, got %v", rpctypes.ErrLeaderChanged, err) } @@ -322,7 +322,7 @@ func TestDropReadUnderNetworkPartition(t *testing.T) { _, err = kvc.Get(ctx, "a") cancel() if err != nil { - if errors.Is(err, rpctypes.ErrTimeout) { + if err == rpctypes.ErrTimeout { <-time.After(time.Second) i++ continue diff --git a/tests/integration/clientv3/connectivity/server_shutdown_test.go b/tests/integration/clientv3/connectivity/server_shutdown_test.go index 3afc8eb4c01e..a75efa0f8fec 100644 --- a/tests/integration/clientv3/connectivity/server_shutdown_test.go +++ b/tests/integration/clientv3/connectivity/server_shutdown_test.go @@ -17,7 +17,6 @@ package connectivity_test import ( "bytes" "context" - "errors" "fmt" "testing" "time" @@ -102,7 +101,7 @@ func TestBalancerUnderServerShutdownWatch(t *testing.T) { if err == nil { break } - if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || errors.Is(err, rpctypes.ErrTimeout) || errors.Is(err, rpctypes.ErrTimeoutDueToLeaderFail) { + if clientv3test.IsClientTimeout(err) || clientv3test.IsServerCtxTimeout(err) || err == rpctypes.ErrTimeout || err == rpctypes.ErrTimeoutDueToLeaderFail { continue } t.Fatal(err) diff --git a/tests/integration/clientv3/experimental/recipes/v3_double_barrier_test.go b/tests/integration/clientv3/experimental/recipes/v3_double_barrier_test.go index f4fbfcb2457c..120e4bed8afb 100644 --- a/tests/integration/clientv3/experimental/recipes/v3_double_barrier_test.go +++ b/tests/integration/clientv3/experimental/recipes/v3_double_barrier_test.go @@ -16,7 +16,6 @@ package recipes_test import ( "context" - "errors" "sync" "testing" "time" @@ -150,7 +149,7 @@ func TestDoubleBarrierTooManyClients(t *testing.T) { // no any other client can enter the barrier. wgEntered.Wait() t.Log("Try to enter into double barrier") - if err = b.Enter(); !errors.Is(err, recipe.ErrTooManyClients) { + if err = b.Enter(); err != recipe.ErrTooManyClients { t.Errorf("Unexcepted error, expected: ErrTooManyClients, got: %v", err) } diff --git a/tests/integration/clientv3/experimental/recipes/v3_lock_test.go b/tests/integration/clientv3/experimental/recipes/v3_lock_test.go index 1fcbc46e1442..79f616620327 100644 --- a/tests/integration/clientv3/experimental/recipes/v3_lock_test.go +++ b/tests/integration/clientv3/experimental/recipes/v3_lock_test.go @@ -16,7 +16,6 @@ package recipes_test import ( "context" - "errors" "fmt" "math/rand" "sync" @@ -140,7 +139,7 @@ func testMutexTryLock(t *testing.T, lockers int, chooseClient func() *clientv3.C case <-ctx.Done(): t.Errorf("Thread: %v, Context failed: %v", i, err) } - } else if errors.Is(err, concurrency.ErrLocked) { + } else if err == concurrency.ErrLocked { select { case notlockedC <- m: case <-ctx.Done(): diff --git a/tests/integration/clientv3/lease/leasing_test.go b/tests/integration/clientv3/lease/leasing_test.go index 40113d0aa132..2164e8f5b188 100644 --- a/tests/integration/clientv3/lease/leasing_test.go +++ b/tests/integration/clientv3/lease/leasing_test.go @@ -16,7 +16,6 @@ package lease_test import ( "context" - "errors" "fmt" "math/rand" "reflect" @@ -896,7 +895,7 @@ func TestLeasingTxnCancel(t *testing.T) { time.Sleep(100 * time.Millisecond) cancel() }() - if _, err := lkv2.Txn(ctx).Then(clientv3.OpPut("k", "v")).Commit(); !errors.Is(err, context.Canceled) { + if _, err := lkv2.Txn(ctx).Then(clientv3.OpPut("k", "v")).Commit(); err != context.Canceled { t.Fatalf("expected %v, got %v", context.Canceled, err) } } @@ -2018,7 +2017,7 @@ func TestLeasingSessionExpireCancel(t *testing.T) { select { case err := <-errc: - if !errors.Is(err, ctx.Err()) { + if err != ctx.Err() { t.Errorf("#%d: expected %v of server unavailable, got %v", i, ctx.Err(), err) } case <-time.After(5 * time.Second): @@ -2049,7 +2048,7 @@ func waitForExpireAck(t *testing.T, kv clientv3.KV) { ctx, cancel := context.WithTimeout(context.TODO(), time.Second) _, err := kv.Get(ctx, "abc") cancel() - if errors.Is(err, ctx.Err()) { + if err == ctx.Err() { return } else if err != nil { t.Logf("current error: %v", err) diff --git a/tests/integration/clientv3/maintenance_test.go b/tests/integration/clientv3/maintenance_test.go index 3de3d389cffa..7dc912a3a2f7 100644 --- a/tests/integration/clientv3/maintenance_test.go +++ b/tests/integration/clientv3/maintenance_test.go @@ -18,7 +18,6 @@ import ( "bytes" "context" "crypto/sha256" - "errors" "fmt" "io" "math" @@ -136,7 +135,7 @@ func TestMaintenanceMoveLeader(t *testing.T) { cli := clus.Client(targetIdx) _, err := cli.MoveLeader(context.Background(), target) - if !errors.Is(err, rpctypes.ErrNotLeader) { + if err != rpctypes.ErrNotLeader { t.Fatalf("error expected %v, got %v", rpctypes.ErrNotLeader, err) } @@ -187,7 +186,7 @@ func TestMaintenanceSnapshotCancel(t *testing.T) { cancel() _, err = io.Copy(io.Discard, rc1) - if !errors.Is(err, context.Canceled) { + if err != context.Canceled { t.Errorf("expected %v, got %v", context.Canceled, err) } } diff --git a/tests/integration/clientv3/ordering_kv_test.go b/tests/integration/clientv3/ordering_kv_test.go index 1d667b44dac9..c539199ff6a7 100644 --- a/tests/integration/clientv3/ordering_kv_test.go +++ b/tests/integration/clientv3/ordering_kv_test.go @@ -89,7 +89,7 @@ func TestDetectKvOrderViolation(t *testing.T) { t.Logf("Quering m2 after restart") v, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable()) t.Logf("Quering m2 returned: v:%v err:%v ", v, err) - if !errors.Is(err, errOrderViolation) { + if err != errOrderViolation { t.Fatalf("expected %v, got err:%v v:%v", errOrderViolation, err, v) } } @@ -155,7 +155,7 @@ func TestDetectTxnOrderViolation(t *testing.T) { cli.SetEndpoints(clus.Members[2].GRPCURL) time.Sleep(2 * time.Second) // FIXME: Figure out how pause SetEndpoints sufficiently that this is not needed _, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable()) - if !errors.Is(err, errOrderViolation) { + if err != errOrderViolation { t.Fatalf("expected %v, got %v", errOrderViolation, err) } orderingTxn = orderingKv.Txn(ctx) @@ -164,7 +164,7 @@ func TestDetectTxnOrderViolation(t *testing.T) { ).Then( clientv3.OpGet("foo", clientv3.WithSerializable()), ).Commit() - if !errors.Is(err, errOrderViolation) { + if err != errOrderViolation { t.Fatalf("expected %v, got %v", errOrderViolation, err) } } diff --git a/tests/integration/clientv3/ordering_util_test.go b/tests/integration/clientv3/ordering_util_test.go index 6313957bf3f9..ebac39981a9d 100644 --- a/tests/integration/clientv3/ordering_util_test.go +++ b/tests/integration/clientv3/ordering_util_test.go @@ -16,7 +16,6 @@ package clientv3test import ( "context" - "errors" "testing" "time" @@ -79,7 +78,7 @@ func TestEndpointSwitchResolvesViolation(t *testing.T) { cli.SetEndpoints(clus.Members[2].GRPCURL) time.Sleep(1 * time.Second) // give enough time for the operation _, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable()) - if !errors.Is(err, ordering.ErrNoGreaterRev) { + if err != ordering.ErrNoGreaterRev { t.Fatal("While speaking to partitioned leader, we should get ErrNoGreaterRev error") } @@ -157,7 +156,7 @@ func TestUnresolvableOrderViolation(t *testing.T) { time.Sleep(1 * time.Second) // give enough time for operation _, err = OrderingKv.Get(ctx, "foo", clientv3.WithSerializable()) - if !errors.Is(err, ordering.ErrNoGreaterRev) { + if err != ordering.ErrNoGreaterRev { t.Fatalf("expected %v, got %v", ordering.ErrNoGreaterRev, err) } } diff --git a/tests/integration/clientv3/txn_test.go b/tests/integration/clientv3/txn_test.go index 221247d2f7af..84a56146d99c 100644 --- a/tests/integration/clientv3/txn_test.go +++ b/tests/integration/clientv3/txn_test.go @@ -16,7 +16,6 @@ package clientv3test import ( "context" - "errors" "fmt" "testing" "time" @@ -37,7 +36,7 @@ func TestTxnError(t *testing.T) { ctx := context.TODO() _, err := kv.Txn(ctx).Then(clientv3.OpPut("foo", "bar1"), clientv3.OpPut("foo", "bar2")).Commit() - if !errors.Is(err, rpctypes.ErrDuplicateKey) { + if err != rpctypes.ErrDuplicateKey { t.Fatalf("expected %v, got %v", rpctypes.ErrDuplicateKey, err) } @@ -46,7 +45,7 @@ func TestTxnError(t *testing.T) { ops[i] = clientv3.OpPut(fmt.Sprintf("foo%d", i), "") } _, err = kv.Txn(ctx).Then(ops...).Commit() - if !errors.Is(err, rpctypes.ErrTooManyOps) { + if err != rpctypes.ErrTooManyOps { t.Fatalf("expected %v, got %v", rpctypes.ErrTooManyOps, err) } } diff --git a/tests/integration/clientv3/user_test.go b/tests/integration/clientv3/user_test.go index 7ed13e7ed445..49b4c18ea45a 100644 --- a/tests/integration/clientv3/user_test.go +++ b/tests/integration/clientv3/user_test.go @@ -16,7 +16,6 @@ package clientv3test import ( "context" - "errors" "testing" "time" @@ -42,17 +41,17 @@ func TestUserError(t *testing.T) { } _, err = authapi.UserAdd(context.TODO(), "foo", "bar") - if !errors.Is(err, rpctypes.ErrUserAlreadyExist) { + if err != rpctypes.ErrUserAlreadyExist { t.Fatalf("expected %v, got %v", rpctypes.ErrUserAlreadyExist, err) } _, err = authapi.UserDelete(context.TODO(), "not-exist-user") - if !errors.Is(err, rpctypes.ErrUserNotFound) { + if err != rpctypes.ErrUserNotFound { t.Fatalf("expected %v, got %v", rpctypes.ErrUserNotFound, err) } _, err = authapi.UserGrantRole(context.TODO(), "foo", "test-role-does-not-exist") - if !errors.Is(err, rpctypes.ErrRoleNotFound) { + if err != rpctypes.ErrRoleNotFound { t.Fatalf("expected %v, got %v", rpctypes.ErrRoleNotFound, err) } } @@ -117,7 +116,7 @@ func TestUserErrorAuth(t *testing.T) { authSetupRoot(t, authapi.Auth) // unauthenticated client - if _, err := authapi.UserAdd(context.TODO(), "foo", "bar"); !errors.Is(err, rpctypes.ErrUserEmpty) { + if _, err := authapi.UserAdd(context.TODO(), "foo", "bar"); err != rpctypes.ErrUserEmpty { t.Fatalf("expected %v, got %v", rpctypes.ErrUserEmpty, err) } @@ -128,11 +127,11 @@ func TestUserErrorAuth(t *testing.T) { DialOptions: []grpc.DialOption{grpc.WithBlock()}, } cfg.Username, cfg.Password = "wrong-id", "123" - if _, err := integration2.NewClient(t, cfg); !errors.Is(err, rpctypes.ErrAuthFailed) { + if _, err := integration2.NewClient(t, cfg); err != rpctypes.ErrAuthFailed { t.Fatalf("expected %v, got %v", rpctypes.ErrAuthFailed, err) } cfg.Username, cfg.Password = "root", "wrong-pass" - if _, err := integration2.NewClient(t, cfg); !errors.Is(err, rpctypes.ErrAuthFailed) { + if _, err := integration2.NewClient(t, cfg); err != rpctypes.ErrAuthFailed { t.Fatalf("expected %v, got %v", rpctypes.ErrAuthFailed, err) } diff --git a/tests/integration/v3_grpc_test.go b/tests/integration/v3_grpc_test.go index 8efeb5d522d0..2cc4ab660327 100644 --- a/tests/integration/v3_grpc_test.go +++ b/tests/integration/v3_grpc_test.go @@ -17,7 +17,6 @@ package integration import ( "bytes" "context" - "errors" "fmt" "math/rand" "os" @@ -115,7 +114,7 @@ func TestV3PutRestart(t *testing.T) { defer cancel() reqput := &pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")} _, err := kvc.Put(ctx, reqput) - if err != nil && errors.Is(err, ctx.Err()) { + if err != nil && err == ctx.Err() { t.Fatalf("expected grpc error, got local ctx error (%v)", err) } } @@ -1600,7 +1599,7 @@ func TestTLSGRPCRejectSecureClient(t *testing.T) { if client != nil || err == nil { client.Close() t.Fatalf("expected no client") - } else if !errors.Is(err, context.DeadlineExceeded) { + } else if err != context.DeadlineExceeded { t.Fatalf("unexpected error (%v)", err) } } @@ -1777,7 +1776,7 @@ func testTLSReload( // 5. expect dial time-out when loading expired certs select { case gerr := <-errc: - if !errors.Is(gerr, context.DeadlineExceeded) { + if gerr != context.DeadlineExceeded { t.Fatalf("expected %v, got %v", context.DeadlineExceeded, gerr) } case <-time.After(5 * time.Second): diff --git a/tests/integration/v3_tls_test.go b/tests/integration/v3_tls_test.go index fbdf2bb8b5e4..a13ad5c0bebc 100644 --- a/tests/integration/v3_tls_test.go +++ b/tests/integration/v3_tls_test.go @@ -17,7 +17,6 @@ package integration import ( "context" "crypto/tls" - "errors" "testing" "time" @@ -73,7 +72,7 @@ func testTLSCipherSuites(t *testing.T, valid bool) { if cli != nil { cli.Close() } - if !valid && !errors.Is(cerr, context.DeadlineExceeded) { + if !valid && cerr != context.DeadlineExceeded { t.Fatalf("expected %v with TLS handshake failure, got %v", context.DeadlineExceeded, cerr) } if valid && cerr != nil {