Skip to content

Commit

Permalink
Convert err != cases to errors.Is in already-modified files
Browse files Browse the repository at this point in the history
Signed-off-by: redwrasse <[email protected]>
  • Loading branch information
redwrasse committed Aug 31, 2024
1 parent ff8f4cc commit 248824b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions server/etcdserver/v3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/clientv3/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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)
}

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

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

Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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()) {
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/clientv3/lease/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 248824b

Please sign in to comment.