fix incorrect usage of errors.Is

errors.Is is supposed to used for equality of errors, not for type
assertions. That's what errors.As is there for.
This commit is contained in:
Marten Seemann 2021-06-26 15:18:54 -07:00
parent a887f8f436
commit dbb517858e
10 changed files with 37 additions and 133 deletions

View file

@ -60,7 +60,7 @@ var _ = Describe("Packet Unpacker", func() {
opener := mocks.NewMockLongHeaderOpener(mockCtrl)
cs.EXPECT().GetHandshakeOpener().Return(opener, nil)
_, err := unpacker.Unpack(hdr, time.Now(), data)
Expect(errors.Is(err, &headerParseError{})).To(BeTrue())
Expect(err).To(BeAssignableToTypeOf(&headerParseError{}))
var headerErr *headerParseError
Expect(errors.As(err, &headerErr)).To(BeTrue())
Expect(err).To(MatchError("Packet too small. Expected at least 20 bytes after the header, got 19"))
@ -77,9 +77,7 @@ var _ = Describe("Packet Unpacker", func() {
opener := mocks.NewMockShortHeaderOpener(mockCtrl)
cs.EXPECT().Get1RTTOpener().Return(opener, nil)
_, err := unpacker.Unpack(hdr, time.Now(), data)
Expect(errors.Is(err, &headerParseError{})).To(BeTrue())
var headerErr *headerParseError
Expect(errors.As(err, &headerErr)).To(BeTrue())
Expect(err).To(BeAssignableToTypeOf(&headerParseError{}))
Expect(err).To(MatchError("Packet too small. Expected at least 20 bytes after the header, got 19"))
})