route/vendor/github.com/lucas-clemente/quic-go/internal/wire/blocked_frame_test.go

55 lines
1.5 KiB
Go
Raw Normal View History

2018-01-03 19:19:49 +00:00
package wire
import (
"bytes"
2018-01-20 18:07:01 +00:00
"io"
2018-01-03 19:19:49 +00:00
"github.com/lucas-clemente/quic-go/internal/protocol"
2018-01-20 18:07:01 +00:00
"github.com/lucas-clemente/quic-go/internal/utils"
2018-01-03 19:19:49 +00:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("BLOCKED frame", func() {
Context("when parsing", func() {
It("accepts sample frame", func() {
2018-01-20 18:07:01 +00:00
data := []byte{0x08}
data = append(data, encodeVarInt(0x12345678)...)
b := bytes.NewReader(data)
frame, err := ParseBlockedFrame(b, versionIETFFrames)
2018-01-03 19:19:49 +00:00
Expect(err).ToNot(HaveOccurred())
2018-01-20 18:07:01 +00:00
Expect(frame.Offset).To(Equal(protocol.ByteCount(0x12345678)))
2018-01-03 19:19:49 +00:00
Expect(b.Len()).To(BeZero())
})
It("errors on EOFs", func() {
2018-01-20 18:07:01 +00:00
data := []byte{0x08}
data = append(data, encodeVarInt(0x12345678)...)
_, err := ParseBlockedFrame(bytes.NewReader(data), versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
for i := range data {
_, err := ParseBlockedFrame(bytes.NewReader(data[:i]), versionIETFFrames)
Expect(err).To(MatchError(io.EOF))
}
2018-01-03 19:19:49 +00:00
})
})
Context("when writing", func() {
It("writes a sample frame", func() {
b := &bytes.Buffer{}
2018-01-20 18:07:01 +00:00
frame := BlockedFrame{Offset: 0xdeadbeef}
2018-01-03 19:19:49 +00:00
err := frame.Write(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
2018-01-20 18:07:01 +00:00
expected := []byte{0x08}
expected = append(expected, encodeVarInt(0xdeadbeef)...)
Expect(b.Bytes()).To(Equal(expected))
2018-01-03 19:19:49 +00:00
})
It("has the correct min length", func() {
2018-01-20 18:07:01 +00:00
frame := BlockedFrame{Offset: 0x12345}
Expect(frame.MinLength(versionIETFFrames)).To(Equal(1 + utils.VarIntLen(0x12345)))
2018-01-03 19:19:49 +00:00
})
})
})