From 248824b6dffbe033ac5e64acd54555755224d2c2 Mon Sep 17 00:00:00 2001 From: redwrasse Date: Fri, 30 Aug 2024 23:17:12 -0700 Subject: [PATCH] Convert err != cases to errors.Is in already-modified files Signed-off-by: redwrasse --- server/etcdserver/server.go | 2 +- server/etcdserver/v3_server.go | 4 ++-- tests/integration/clientv3/kv_test.go | 18 +++++++++--------- tests/integration/clientv3/lease/lease_test.go | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index 7f230a2d2cdc..ba3a3f3ffe1d 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -1981,7 +1981,7 @@ func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry, shouldApplyV3 membership. return } - if ar.Err != errors.ErrNoSpace || len(s.alarmStore.Get(pb.AlarmType_NOSPACE)) > 0 { + if !errorspkg.Is(ar.Err, errors.ErrNoSpace) || len(s.alarmStore.Get(pb.AlarmType_NOSPACE)) > 0 { s.w.Trigger(id, ar) return } diff --git a/server/etcdserver/v3_server.go b/server/etcdserver/v3_server.go index 0a1e369fcbae..803f931f5f78 100644 --- a/server/etcdserver/v3_server.go +++ b/server/etcdserver/v3_server.go @@ -297,7 +297,7 @@ func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, e if err == nil { // already requested to primary lessor(leader) return ttl, nil } - if err != lease.ErrNotPrimary { + if !errorspkg.Is(err, lease.ErrNotPrimary) { return -1, err } } @@ -528,7 +528,7 @@ func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest for { checkedRevision, err := s.AuthStore().CheckPassword(r.Name, r.Password) if err != nil { - if err != auth.ErrAuthNotEnabled { + if !errorspkg.Is(err, auth.ErrAuthNotEnabled) { lg.Warn( "invalid authentication was requested", zap.String("user", r.Name), diff --git a/tests/integration/clientv3/kv_test.go b/tests/integration/clientv3/kv_test.go index cfabfbdea9b3..5f66b4f9034b 100644 --- a/tests/integration/clientv3/kv_test.go +++ b/tests/integration/clientv3/kv_test.go @@ -51,12 +51,12 @@ func TestKVPutError(t *testing.T) { ctx := context.TODO() _, err := kv.Put(ctx, "", "bar") - if err != rpctypes.ErrEmptyKey { + if !errors.Is(err, rpctypes.ErrEmptyKey) { t.Fatalf("expected %v, got %v", rpctypes.ErrEmptyKey, err) } _, err = kv.Put(ctx, "key", strings.Repeat("a", int(maxReqBytes+100))) - if err != rpctypes.ErrRequestTooLarge { + if !errors.Is(err, rpctypes.ErrRequestTooLarge) { t.Fatalf("expected %v, got %v", rpctypes.ErrRequestTooLarge, err) } @@ -68,7 +68,7 @@ func TestKVPutError(t *testing.T) { time.Sleep(1 * time.Second) // give enough time for commit _, err = kv.Put(ctx, "foo2", strings.Repeat("a", int(maxReqBytes-50))) - if err != rpctypes.ErrNoSpace { // over quota + if !errors.Is(err, rpctypes.ErrNoSpace) { // over quota t.Fatalf("expected %v, got %v", rpctypes.ErrNoSpace, err) } } @@ -119,7 +119,7 @@ func TestKVPutWithIgnoreValue(t *testing.T) { kv := clus.RandClient() _, err := kv.Put(context.TODO(), "foo", "", clientv3.WithIgnoreValue()) - if err != rpctypes.ErrKeyNotFound { + if !errors.Is(err, rpctypes.ErrKeyNotFound) { t.Fatalf("err expected %v, got %v", rpctypes.ErrKeyNotFound, err) } @@ -158,7 +158,7 @@ func TestKVPutWithIgnoreLease(t *testing.T) { t.Errorf("failed to create lease %v", err) } - if _, err := kv.Put(context.TODO(), "zoo", "bar", clientv3.WithIgnoreLease()); err != rpctypes.ErrKeyNotFound { + if _, err := kv.Put(context.TODO(), "zoo", "bar", clientv3.WithIgnoreLease()); !errors.Is(err, rpctypes.ErrKeyNotFound) { t.Fatalf("err expected %v, got %v", rpctypes.ErrKeyNotFound, err) } @@ -200,7 +200,7 @@ func TestKVPutWithRequireLeader(t *testing.T) { kv := clus.Client(0) _, err := kv.Put(clientv3.WithRequireLeader(context.Background()), "foo", "bar") - if err != rpctypes.ErrNoLeader { + if !errors.Is(err, rpctypes.ErrNoLeader) { t.Fatal(err) } @@ -414,12 +414,12 @@ func TestKVCompactError(t *testing.T) { } _, err = kv.Compact(ctx, 6) - if err != rpctypes.ErrCompacted { + if !errors.Is(err, rpctypes.ErrCompacted) { t.Fatalf("expected %v, got %v", rpctypes.ErrCompacted, err) } _, err = kv.Compact(ctx, 100) - if err != rpctypes.ErrFutureRev { + if !errors.Is(err, rpctypes.ErrFutureRev) { t.Fatalf("expected %v, got %v", rpctypes.ErrFutureRev, err) } } @@ -751,7 +751,7 @@ func TestKVLargeRequests(t *testing.T) { _, err := cli.Put(context.TODO(), "foo", strings.Repeat("a", test.valueSize)) if _, ok := err.(rpctypes.EtcdError); ok { - if err != test.expectError { + if !errors.Is(err, test.expectError) { t.Errorf("#%d: expected %v, got %v", i, test.expectError, err) } } else if err != nil && !strings.HasPrefix(err.Error(), test.expectError.Error()) { diff --git a/tests/integration/clientv3/lease/lease_test.go b/tests/integration/clientv3/lease/lease_test.go index 1264645afb12..1d9824e81146 100644 --- a/tests/integration/clientv3/lease/lease_test.go +++ b/tests/integration/clientv3/lease/lease_test.go @@ -39,7 +39,7 @@ func TestLeaseNotFoundError(t *testing.T) { kv := clus.RandClient() _, err := kv.Put(context.TODO(), "foo", "bar", clientv3.WithLease(clientv3.LeaseID(500))) - if err != rpctypes.ErrLeaseNotFound { + if !errors.Is(err, rpctypes.ErrLeaseNotFound) { t.Fatalf("expected %v, got %v", rpctypes.ErrLeaseNotFound, err) } } @@ -55,7 +55,7 @@ func TestLeaseGrant(t *testing.T) { kv := clus.RandClient() _, merr := lapi.Grant(context.Background(), clientv3.MaxLeaseTTL+1) - if merr != rpctypes.ErrLeaseTTLTooLarge { + if !errors.Is(merr, rpctypes.ErrLeaseTTLTooLarge) { t.Fatalf("err = %v, want %v", merr, rpctypes.ErrLeaseTTLTooLarge) } @@ -91,7 +91,7 @@ func TestLeaseRevoke(t *testing.T) { } _, err = kv.Put(context.TODO(), "foo", "bar", clientv3.WithLease(resp.ID)) - if err != rpctypes.ErrLeaseNotFound { + if !errors.Is(err, rpctypes.ErrLeaseNotFound) { t.Fatalf("err = %v, want %v", err, rpctypes.ErrLeaseNotFound) } } @@ -115,7 +115,7 @@ func TestLeaseKeepAliveOnce(t *testing.T) { } _, err = lapi.KeepAliveOnce(context.Background(), clientv3.LeaseID(0)) - if err != rpctypes.ErrLeaseNotFound { + if !errors.Is(err, rpctypes.ErrLeaseNotFound) { t.Errorf("expected %v, got %v", rpctypes.ErrLeaseNotFound, err) } }