uquic/internal/wire/stream_data_blocked_frame_test.go
Gaukas Wang 95575f5fe7
break: update repo url [ci skip]
uTLS is not yet bumped to the new version, so this commit breaks the dependencies relationship by getting rid of the local replace.
2023-08-03 18:58:52 -06:00

61 lines
1.9 KiB
Go

package wire
import (
"bytes"
"io"
"github.com/refraction-networking/uquic/internal/protocol"
"github.com/refraction-networking/uquic/quicvarint"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("STREAM_DATA_BLOCKED frame", func() {
Context("parsing", func() {
It("accepts sample frame", func() {
data := encodeVarInt(0xdeadbeef) // stream ID
data = append(data, encodeVarInt(0xdecafbad)...) // offset
b := bytes.NewReader(data)
frame, err := parseStreamDataBlockedFrame(b, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdeadbeef)))
Expect(frame.MaximumStreamData).To(Equal(protocol.ByteCount(0xdecafbad)))
Expect(b.Len()).To(BeZero())
})
It("errors on EOFs", func() {
data := encodeVarInt(0xdeadbeef)
data = append(data, encodeVarInt(0xc0010ff)...)
_, err := parseStreamDataBlockedFrame(bytes.NewReader(data), protocol.Version1)
Expect(err).NotTo(HaveOccurred())
for i := range data {
_, err := parseStreamDataBlockedFrame(bytes.NewReader(data[:i]), protocol.Version1)
Expect(err).To(MatchError(io.EOF))
}
})
})
Context("writing", func() {
It("has proper min length", func() {
f := &StreamDataBlockedFrame{
StreamID: 0x1337,
MaximumStreamData: 0xdeadbeef,
}
Expect(f.Length(0)).To(Equal(1 + quicvarint.Len(0x1337) + quicvarint.Len(0xdeadbeef)))
})
It("writes a sample frame", func() {
f := &StreamDataBlockedFrame{
StreamID: 0xdecafbad,
MaximumStreamData: 0x1337,
}
b, err := f.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
expected := []byte{streamDataBlockedFrameType}
expected = append(expected, encodeVarInt(uint64(f.StreamID))...)
expected = append(expected, encodeVarInt(uint64(f.MaximumStreamData))...)
Expect(b).To(Equal(expected))
})
})
})