github.com/MerlinKodo/quic-go@v0.39.2/internal/logutils/frame_test.go (about)

     1  package logutils
     2  
     3  import (
     4  	"github.com/MerlinKodo/quic-go/internal/wire"
     5  	"github.com/MerlinKodo/quic-go/logging"
     6  
     7  	. "github.com/onsi/ginkgo/v2"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("CRYPTO frame", func() {
    12  	It("converts CRYPTO frames", func() {
    13  		f := ConvertFrame(&wire.CryptoFrame{
    14  			Offset: 1234,
    15  			Data:   []byte("foobar"),
    16  		})
    17  		Expect(f).To(BeAssignableToTypeOf(&logging.CryptoFrame{}))
    18  		cf := f.(*logging.CryptoFrame)
    19  		Expect(cf.Offset).To(Equal(logging.ByteCount(1234)))
    20  		Expect(cf.Length).To(Equal(logging.ByteCount(6)))
    21  	})
    22  
    23  	It("converts STREAM frames", func() {
    24  		f := ConvertFrame(&wire.StreamFrame{
    25  			StreamID: 42,
    26  			Offset:   1234,
    27  			Data:     []byte("foo"),
    28  			Fin:      true,
    29  		})
    30  		Expect(f).To(BeAssignableToTypeOf(&logging.StreamFrame{}))
    31  		sf := f.(*logging.StreamFrame)
    32  		Expect(sf.StreamID).To(Equal(logging.StreamID(42)))
    33  		Expect(sf.Offset).To(Equal(logging.ByteCount(1234)))
    34  		Expect(sf.Length).To(Equal(logging.ByteCount(3)))
    35  		Expect(sf.Fin).To(BeTrue())
    36  	})
    37  
    38  	It("converts DATAGRAM frames", func() {
    39  		f := ConvertFrame(&wire.DatagramFrame{Data: []byte("foobar")})
    40  		Expect(f).To(BeAssignableToTypeOf(&logging.DatagramFrame{}))
    41  		df := f.(*logging.DatagramFrame)
    42  		Expect(df.Length).To(Equal(logging.ByteCount(6)))
    43  	})
    44  
    45  	It("converts other frames", func() {
    46  		f := ConvertFrame(&wire.MaxDataFrame{MaximumData: 1234})
    47  		Expect(f).To(BeAssignableToTypeOf(&logging.MaxDataFrame{}))
    48  		Expect(f).ToNot(BeAssignableToTypeOf(&logging.MaxStreamDataFrame{}))
    49  		mdf := f.(*logging.MaxDataFrame)
    50  		Expect(mdf.MaximumData).To(Equal(logging.ByteCount(1234)))
    51  	})
    52  })