File: stop_sending_frame_test.go

package info (click to toggle)
golang-github-lucas-clemente-quic-go 0.54.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,312 kB
  • sloc: sh: 54; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,478 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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{byte(FrameTypeStopSending)}
	expected = append(expected, encodeVarInt(0xdeadbeefcafe)...)
	expected = append(expected, encodeVarInt(0xdecafbad)...)
	require.Equal(t, expected, b)
	require.Len(t, b, int(frame.Length(protocol.Version1)))
}