Files
quic-go/internal/handshake/crypto_stream_conn_test.go
Marten Seemann 77f5d30338 buffer writes to the crypto stream
mint performs a Write for every state change. This results in a lot of
small packets getting sent when using an unbuffered connection. By
buffering, we make sure that packets are filled up properly.
2018-08-13 08:47:29 +07:00

42 lines
864 B
Go

package handshake
import (
"bytes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Crypto Stream Conn", func() {
var (
stream *bytes.Buffer
csc *cryptoStreamConn
)
BeforeEach(func() {
stream = &bytes.Buffer{}
csc = newCryptoStreamConn(stream)
})
It("buffers writes", func() {
_, err := csc.Write([]byte("foo"))
Expect(err).ToNot(HaveOccurred())
Expect(stream.Len()).To(BeZero())
_, err = csc.Write([]byte("bar"))
Expect(err).ToNot(HaveOccurred())
Expect(stream.Len()).To(BeZero())
Expect(csc.Flush()).To(Succeed())
Expect(stream.Bytes()).To(Equal([]byte("foobar")))
})
It("reads from the stream", func() {
stream.Write([]byte("foobar"))
b := make([]byte, 6)
n, err := csc.Read(b)
Expect(err).ToNot(HaveOccurred())
Expect(n).To(Equal(6))
Expect(b).To(Equal([]byte("foobar")))
})
})