migrate the connection tests away from Ginkgo (#4823)

This commit is contained in:
Marten Seemann
2025-01-06 14:48:11 +08:00
committed by GitHub
parent 9b55fbe0be
commit f41a6a644d
7 changed files with 2781 additions and 3268 deletions

View File

@@ -1,52 +1,72 @@
package quic
import (
"testing"
"github.com/quic-go/quic-go/internal/wire"
"github.com/quic-go/quic-go/logging"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"
)
var _ = Describe("CRYPTO frame", func() {
It("converts CRYPTO frames", func() {
f := toLoggingFrame(&wire.CryptoFrame{
Offset: 1234,
Data: []byte("foobar"),
})
Expect(f).To(BeAssignableToTypeOf(&logging.CryptoFrame{}))
cf := f.(*logging.CryptoFrame)
Expect(cf.Offset).To(Equal(logging.ByteCount(1234)))
Expect(cf.Length).To(Equal(logging.ByteCount(6)))
func TestConnectionLoggingCryptoFrame(t *testing.T) {
f := toLoggingFrame(&wire.CryptoFrame{
Offset: 1234,
Data: []byte("foobar"),
})
require.Equal(t, &logging.CryptoFrame{
Offset: 1234,
Length: 6,
}, f)
}
It("converts STREAM frames", func() {
f := toLoggingFrame(&wire.StreamFrame{
StreamID: 42,
Offset: 1234,
Data: []byte("foo"),
Fin: true,
})
Expect(f).To(BeAssignableToTypeOf(&logging.StreamFrame{}))
sf := f.(*logging.StreamFrame)
Expect(sf.StreamID).To(Equal(logging.StreamID(42)))
Expect(sf.Offset).To(Equal(logging.ByteCount(1234)))
Expect(sf.Length).To(Equal(logging.ByteCount(3)))
Expect(sf.Fin).To(BeTrue())
func TestConnectionLoggingStreamFrame(t *testing.T) {
f := toLoggingFrame(&wire.StreamFrame{
StreamID: 42,
Offset: 1234,
Data: []byte("foo"),
Fin: true,
})
require.Equal(t, &logging.StreamFrame{
StreamID: 42,
Offset: 1234,
Length: 3,
Fin: true,
}, f)
}
It("converts DATAGRAM frames", func() {
f := toLoggingFrame(&wire.DatagramFrame{Data: []byte("foobar")})
Expect(f).To(BeAssignableToTypeOf(&logging.DatagramFrame{}))
df := f.(*logging.DatagramFrame)
Expect(df.Length).To(Equal(logging.ByteCount(6)))
})
func TestConnectionLoggingAckFrame(t *testing.T) {
ack := &wire.AckFrame{
AckRanges: []wire.AckRange{
{Smallest: 1, Largest: 3},
{Smallest: 6, Largest: 7},
},
DelayTime: 42,
ECNCE: 123,
ECT0: 456,
ECT1: 789,
}
f := toLoggingFrame(ack)
// now modify the ACK range in the original frame
ack.AckRanges[0].Smallest = 2
require.Equal(t, &logging.AckFrame{
AckRanges: []wire.AckRange{
{Smallest: 1, Largest: 3}, // unchanged, since the ACK ranges were cloned
{Smallest: 6, Largest: 7},
},
DelayTime: 42,
ECNCE: 123,
ECT0: 456,
ECT1: 789,
}, f)
}
It("converts other frames", func() {
f := toLoggingFrame(&wire.MaxDataFrame{MaximumData: 1234})
Expect(f).To(BeAssignableToTypeOf(&logging.MaxDataFrame{}))
Expect(f).ToNot(BeAssignableToTypeOf(&logging.MaxStreamDataFrame{}))
mdf := f.(*logging.MaxDataFrame)
Expect(mdf.MaximumData).To(Equal(logging.ByteCount(1234)))
})
})
func TestConnectionLoggingDatagramFrame(t *testing.T) {
f := toLoggingFrame(&wire.DatagramFrame{Data: []byte("foobar")})
require.Equal(t, &logging.DatagramFrame{Length: 6}, f)
}
func TestConnectionLoggingOtherFrames(t *testing.T) {
f := toLoggingFrame(&wire.MaxDataFrame{MaximumData: 1234})
require.Equal(t, &logging.MaxDataFrame{MaximumData: 1234}, f)
}