forked from quic-go/quic-go
* 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
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package wire
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/quic-go/quic-go/internal/protocol"
|
|
"github.com/quic-go/quic-go/internal/qerr"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
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)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
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)))
|
|
}
|