github.com/tumi8/quic-go@v0.37.4-tum/http3/body_test.go (about) 1 package http3 2 3 import ( 4 "errors" 5 "github.com/tumi8/quic-go" 6 mockquic "github.com/tumi8/quic-go/noninternal/mocks/quic" 7 8 "github.com/tumi8/quic-go" 9 mockquic "github.com/tumi8/quic-go/noninternal/mocks/quic" 10 11 "github.com/golang/mock/gomock" 12 . "github.com/onsi/ginkgo/v2" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("Response Body", func() { 17 var reqDone chan struct{} 18 19 BeforeEach(func() { reqDone = make(chan struct{}) }) 20 21 It("closes the reqDone channel when Read errors", func() { 22 str := mockquic.NewMockStream(mockCtrl) 23 str.EXPECT().Read(gomock.Any()).Return(0, errors.New("test error")) 24 rb := newResponseBody(str, nil, reqDone) 25 _, err := rb.Read([]byte{0}) 26 Expect(err).To(MatchError("test error")) 27 Expect(reqDone).To(BeClosed()) 28 }) 29 30 It("allows multiple calls to Read, when Read errors", func() { 31 str := mockquic.NewMockStream(mockCtrl) 32 str.EXPECT().Read(gomock.Any()).Return(0, errors.New("test error")).Times(2) 33 rb := newResponseBody(str, nil, reqDone) 34 _, err := rb.Read([]byte{0}) 35 Expect(err).To(HaveOccurred()) 36 Expect(reqDone).To(BeClosed()) 37 _, err = rb.Read([]byte{0}) 38 Expect(err).To(HaveOccurred()) 39 }) 40 41 It("closes responses", func() { 42 str := mockquic.NewMockStream(mockCtrl) 43 rb := newResponseBody(str, nil, reqDone) 44 str.EXPECT().CancelRead(quic.StreamErrorCode(ErrCodeRequestCanceled)) 45 Expect(rb.Close()).To(Succeed()) 46 }) 47 48 It("allows multiple calls to Close", func() { 49 str := mockquic.NewMockStream(mockCtrl) 50 rb := newResponseBody(str, nil, reqDone) 51 str.EXPECT().CancelRead(quic.StreamErrorCode(ErrCodeRequestCanceled)).MaxTimes(2) 52 Expect(rb.Close()).To(Succeed()) 53 Expect(reqDone).To(BeClosed()) 54 Expect(rb.Close()).To(Succeed()) 55 }) 56 })