Skip to content

Commit 547c702

Browse files
authored
Use errors.Is() (#3541)
1 parent 128cfdb commit 547c702

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

grpc/middleware/xray/middleware.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package xray
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"io"
78
"net"
@@ -232,7 +233,7 @@ func (c *xrayStreamClientWrapper) recordErrorAndClose(err error) {
232233
defer c.mu.Unlock()
233234
if !c.finished {
234235
// io.EOF is normal grpc stream close, not error.
235-
if err == io.EOF {
236+
if errors.Is(err, io.EOF) {
236237
c.s.RecordResponse(nil)
237238
} else {
238239
c.s.RecordError(err)

grpc/middleware/xray/middleware_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package xray
44

55
import (
66
"context"
7+
"errors"
78
"io"
89
"net"
910
"testing"
@@ -551,7 +552,7 @@ func TestStreamClient(t *testing.T) {
551552
if err == nil {
552553
var msg any
553554
err2 := cs.RecvMsg(msg)
554-
closed := err2 == io.EOF
555+
closed := errors.Is(err2, io.EOF)
555556
if tc.StreamClosed != closed {
556557
t.Errorf("expected stream closed to be %v, got %v", tc.StreamClosed, closed)
557558
}

middleware/xray/xray_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestConnect(t *testing.T) {
4242
_, err := Connect(context.Background(), time.Millisecond, func() (net.Conn, error) {
4343
return nil, dialErr
4444
})
45-
if err != dialErr {
45+
if !errors.Is(err, dialErr) {
4646
t.Fatalf("Unexpected err, got %q, expected %q", err, dialErr)
4747
}
4848
})

pkg/validation_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestValidateFormat(t *testing.T) {
9696

9797
for k, tc := range cases {
9898
actual := ValidateFormat(tc.name, tc.val, tc.format)
99-
if actual != tc.expected {
99+
if !errors.Is(actual, tc.expected) {
100100
// Compare only the messages because the error has always a new error ID.
101101
if actual == nil || tc.expected == nil || actual.Error() != tc.expected.Error() {
102102
t.Errorf("%s: got %#v, expected %#v", k, actual, tc.expected)
@@ -124,7 +124,7 @@ func TestValidatePattern(t *testing.T) {
124124

125125
for k, tc := range cases {
126126
actual := ValidatePattern(tc.name, tc.val, tc.pattern)
127-
if actual != tc.expected {
127+
if !errors.Is(actual, tc.expected) {
128128
// Compare only the messages because the error has always a new error ID.
129129
if actual.Error() != tc.expected.Error() {
130130
t.Errorf("%s: got %#v, expected %#v", k, actual, tc.expected)

0 commit comments

Comments
 (0)