MCPcopy Create free account
hub / github.com/HyBuildNet/quic-relay / TestClassifyPacket

Function TestClassifyPacket

internal/proxy/parser_test.go:73–97  ·  view source on GitHub ↗

Test packet classification

(t *testing.T)

Source from the content-addressed store, hash-verified

71
72// Test packet classification
73func TestClassifyPacket(t *testing.T) {
74 tests := []struct {
75 name string
76 firstByte byte
77 expected PacketType
78 }{
79 {"Initial", 0xC0, PacketInitial}, // 1100 0000 - Long header, type 00
80 {"Initial with PN", 0xC3, PacketInitial}, // 1100 0011 - Long header, type 00, PN len 4
81 {"0-RTT", 0xD0, PacketZeroRTT}, // 1101 0000 - Long header, type 01
82 {"Handshake", 0xE0, PacketHandshake}, // 1110 0000 - Long header, type 10
83 {"Retry", 0xF0, PacketRetry}, // 1111 0000 - Long header, type 11
84 {"Short Header", 0x40, PacketShortHeader}, // 0100 0000 - Short header
85 {"Short Header 2", 0x5F, PacketShortHeader}, // 0101 1111 - Short header
86 }
87
88 for _, tt := range tests {
89 t.Run(tt.name, func(t *testing.T) {
90 packet := []byte{tt.firstByte, 0, 0, 0, 0}
91 got := ClassifyPacket(packet)
92 if got != tt.expected {
93 t.Errorf("ClassifyPacket(%02x) = %v, want %v", tt.firstByte, got, tt.expected)
94 }
95 })
96 }
97}

Callers

nothing calls this directly

Calls 2

ClassifyPacketFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected