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:
Marten Seemann
2024-09-13 10:27:39 +08:00
committed by GitHub
parent 7a10ed602d
commit 672f906a40
30 changed files with 3768 additions and 4168 deletions

View File

@@ -2,49 +2,39 @@ package wire
import (
"io"
"testing"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/quicvarint"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"
)
var _ = Describe("DATA_BLOCKED frame", func() {
Context("when parsing", func() {
It("accepts sample frame", func() {
data := encodeVarInt(0x12345678)
frame, l, err := parseDataBlockedFrame(data, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(frame.MaximumData).To(Equal(protocol.ByteCount(0x12345678)))
Expect(l).To(Equal(len(data)))
})
func TestParseDataBlocked(t *testing.T) {
data := encodeVarInt(0x12345678)
frame, l, err := parseDataBlockedFrame(data, protocol.Version1)
require.NoError(t, err)
require.Equal(t, protocol.ByteCount(0x12345678), frame.MaximumData)
require.Equal(t, len(data), l)
}
It("errors on EOFs", func() {
data := encodeVarInt(0x12345678)
_, l, err := parseDataBlockedFrame(data, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
Expect(l).To(Equal(len(data)))
for i := range data {
_, _, err := parseDataBlockedFrame(data[:i], protocol.Version1)
Expect(err).To(MatchError(io.EOF))
}
})
})
func TestParseDataBlockedErrorsOnEOFs(t *testing.T) {
data := encodeVarInt(0x12345678)
_, l, err := parseDataBlockedFrame(data, protocol.Version1)
require.NoError(t, err)
require.Equal(t, len(data), l)
for i := range data {
_, _, err := parseDataBlockedFrame(data[:i], protocol.Version1)
require.Equal(t, io.EOF, err)
}
}
Context("when writing", func() {
It("writes a sample frame", func() {
frame := DataBlockedFrame{MaximumData: 0xdeadbeef}
b, err := frame.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
expected := []byte{dataBlockedFrameType}
expected = append(expected, encodeVarInt(0xdeadbeef)...)
Expect(b).To(Equal(expected))
})
It("has the correct min length", func() {
frame := DataBlockedFrame{MaximumData: 0x12345}
Expect(frame.Length(protocol.Version1)).To(BeEquivalentTo(1 + quicvarint.Len(0x12345)))
})
})
})
func TestWriteDataBlocked(t *testing.T) {
frame := DataBlockedFrame{MaximumData: 0xdeadbeef}
b, err := frame.Append(nil, protocol.Version1)
require.NoError(t, err)
expected := []byte{dataBlockedFrameType}
expected = append(expected, encodeVarInt(0xdeadbeef)...)
require.Equal(t, expected, b)
require.Equal(t, protocol.ByteCount(1+quicvarint.Len(uint64(frame.MaximumData))), frame.Length(protocol.Version1))
}