github.com/metacubex/quic-go@v0.44.1-0.20240520163451-20b689a59136/internal/protocol/protocol_test.go (about) 1 package protocol 2 3 import ( 4 . "github.com/onsi/ginkgo/v2" 5 . "github.com/onsi/gomega" 6 ) 7 8 var _ = Describe("Protocol", func() { 9 Context("Long Header Packet Types", func() { 10 It("has the correct string representation", func() { 11 Expect(PacketTypeInitial.String()).To(Equal("Initial")) 12 Expect(PacketTypeRetry.String()).To(Equal("Retry")) 13 Expect(PacketTypeHandshake.String()).To(Equal("Handshake")) 14 Expect(PacketType0RTT.String()).To(Equal("0-RTT Protected")) 15 Expect(PacketType(10).String()).To(Equal("unknown packet type: 10")) 16 }) 17 }) 18 19 It("converts ECN bits from the IP header wire to the correct types", func() { 20 Expect(ParseECNHeaderBits(0)).To(Equal(ECNNon)) 21 Expect(ParseECNHeaderBits(0b00000010)).To(Equal(ECT0)) 22 Expect(ParseECNHeaderBits(0b00000001)).To(Equal(ECT1)) 23 Expect(ParseECNHeaderBits(0b00000011)).To(Equal(ECNCE)) 24 Expect(func() { ParseECNHeaderBits(0b1010101) }).To(Panic()) 25 }) 26 27 It("converts to IP header bits", func() { 28 for _, v := range [...]ECN{ECNNon, ECT0, ECT1, ECNCE} { 29 Expect(ParseECNHeaderBits(v.ToHeaderBits())).To(Equal(v)) 30 } 31 Expect(func() { ECN(42).ToHeaderBits() }).To(Panic()) 32 }) 33 34 It("has a string representation for ECN", func() { 35 Expect(ECNUnsupported.String()).To(Equal("ECN unsupported")) 36 Expect(ECNNon.String()).To(Equal("Not-ECT")) 37 Expect(ECT0.String()).To(Equal("ECT(0)")) 38 Expect(ECT1.String()).To(Equal("ECT(1)")) 39 Expect(ECNCE.String()).To(Equal("CE")) 40 Expect(ECN(42).String()).To(Equal("invalid ECN value: 42")) 41 }) 42 })