forked from quic-go/quic-go
wire: migrate tests away from Ginkgo (#4643)
* wire: translate ACK frame tests * wire: translate CONNECTION_CLOSE frame tests * wire: translate DATA_BLOCKED frame tests * wire: translate DATAGRAM frame tests * wire: translate HANDSHAKE_DONE frame tests * wire: translate MAX_DATA frame tests * wire: translate MAX_STREAM_DATA frame tests * wire: translate MAX_STREAMS frame tests * wire: translate NEW_CONNECTION_ID frame tests * wire: translate NEW_TOKEN frame tests * wire: translate PATH_CHALLENGE frame tests * wire: translate PATH_RESPONSE frame tests * wire: translate PING frame test * wire: translate RESET_STREAM frame tests * wire: translate RETIRE_CONNECTION_ID frame tests * wire: translate STOP_SENDING frame tests * wire: translate STREAM_DATA_BLOCKED frame tests * wire: translate STREAMS_BLOCKED frame tests * wire: translate CRYPTO frame tests * wire: translate STREAM frame tests * wire: translate version negotiation tests * wire: translate header tests * wire: translate pool tests * wire: translate frame logging tests * wire: translate short header tests * wire: translate framer parser tests * wire: translate transport parameter tests
This commit is contained in:
@@ -2,60 +2,46 @@ package wire
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
"github.com/quic-go/quic-go/internal/qerr"
|
||||
"github.com/quic-go/quic-go/quicvarint"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var _ = Describe("STOP_SENDING frame", func() {
|
||||
Context("when parsing", func() {
|
||||
It("parses a sample frame", func() {
|
||||
data := encodeVarInt(0xdecafbad) // stream ID
|
||||
data = append(data, encodeVarInt(0x1337)...) // error code
|
||||
frame, l, err := parseStopSendingFrame(data, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(frame.StreamID).To(Equal(protocol.StreamID(0xdecafbad)))
|
||||
Expect(frame.ErrorCode).To(Equal(qerr.StreamErrorCode(0x1337)))
|
||||
Expect(l).To(Equal(len(data)))
|
||||
})
|
||||
func TestParseStopSending(t *testing.T) {
|
||||
data := encodeVarInt(0xdecafbad) // stream ID
|
||||
data = append(data, encodeVarInt(0x1337)...) // error code
|
||||
frame, l, err := parseStopSendingFrame(data, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, protocol.StreamID(0xdecafbad), frame.StreamID)
|
||||
require.Equal(t, qerr.StreamErrorCode(0x1337), frame.ErrorCode)
|
||||
require.Equal(t, len(data), l)
|
||||
}
|
||||
|
||||
It("errors on EOFs", func() {
|
||||
data := encodeVarInt(0xdecafbad) // stream ID
|
||||
data = append(data, encodeVarInt(0x123456)...) // error code
|
||||
_, l, err := parseStopSendingFrame(data, protocol.Version1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(l).To(Equal(len(data)))
|
||||
for i := range data {
|
||||
_, _, err := parseStopSendingFrame(data[:i], protocol.Version1)
|
||||
Expect(err).To(MatchError(io.EOF))
|
||||
}
|
||||
})
|
||||
})
|
||||
func TestParseStopSendingErrorsOnEOFs(t *testing.T) {
|
||||
data := encodeVarInt(0xdecafbad) // stream ID
|
||||
data = append(data, encodeVarInt(0x123456)...) // error code
|
||||
_, l, err := parseStopSendingFrame(data, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(data), l)
|
||||
for i := range data {
|
||||
_, _, err := parseStopSendingFrame(data[:i], protocol.Version1)
|
||||
require.Equal(t, io.EOF, err)
|
||||
}
|
||||
}
|
||||
|
||||
Context("when writing", func() {
|
||||
It("writes", func() {
|
||||
frame := &StopSendingFrame{
|
||||
StreamID: 0xdeadbeefcafe,
|
||||
ErrorCode: 0xdecafbad,
|
||||
}
|
||||
b, err := frame.Append(nil, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
expected := []byte{stopSendingFrameType}
|
||||
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
||||
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
||||
Expect(b).To(Equal(expected))
|
||||
})
|
||||
|
||||
It("has the correct min length", func() {
|
||||
frame := &StopSendingFrame{
|
||||
StreamID: 0xdeadbeef,
|
||||
ErrorCode: 0x1234567,
|
||||
}
|
||||
Expect(frame.Length(protocol.Version1)).To(BeEquivalentTo(1 + quicvarint.Len(0xdeadbeef) + quicvarint.Len(0x1234567)))
|
||||
})
|
||||
})
|
||||
})
|
||||
func TestWriteStopSendingFrame(t *testing.T) {
|
||||
frame := &StopSendingFrame{
|
||||
StreamID: 0xdeadbeefcafe,
|
||||
ErrorCode: 0xdecafbad,
|
||||
}
|
||||
b, err := frame.Append(nil, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
expected := []byte{stopSendingFrameType}
|
||||
expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
|
||||
expected = append(expected, encodeVarInt(0xdecafbad)...)
|
||||
require.Equal(t, expected, b)
|
||||
require.Len(t, b, int(frame.Length(protocol.Version1)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user