reset streams that the request body is not read from

fixes #384
This commit is contained in:
Marten Seemann
2017-01-09 23:47:01 +07:00
parent d541472101
commit 64bc80339e
5 changed files with 115 additions and 6 deletions

View File

@@ -0,0 +1,39 @@
package h2quic
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Request body", func() {
var (
stream *mockStream
rb *requestBody
)
BeforeEach(func() {
stream = &mockStream{}
stream.Write([]byte("foobar")) // provides data to be read
rb = newRequestBody(stream)
})
It("reads from the stream", func() {
b := make([]byte, 10)
n, _ := stream.Read(b)
Expect(n).To(Equal(6))
Expect(b[0:6]).To(Equal([]byte("foobar")))
})
It("saves if the stream was read from", func() {
Expect(rb.requestRead).To(BeFalse())
rb.Read(make([]byte, 1))
Expect(rb.requestRead).To(BeTrue())
})
It("doesn't close the stream when closing the request body", func() {
Expect(stream.closed).To(BeFalse())
err := rb.Close()
Expect(err).ToNot(HaveOccurred())
Expect(stream.closed).To(BeFalse())
})
})