MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / TestDecodeIP

Function TestDecodeIP

packet/decoder_test.go:16–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestDecodeIP(t *testing.T) {
17 ipDecoder := NewIPDecoder()
18 icmpDecoder := NewICMPDecoder()
19 udps := []UDP{
20 {
21 IP: IP{
22 Src: netip.MustParseAddr("172.16.0.1"),
23 Dst: netip.MustParseAddr("10.0.0.1"),
24 Protocol: layers.IPProtocolUDP,
25 },
26 SrcPort: 31678,
27 DstPort: 53,
28 },
29 {
30
31 IP: IP{
32 Src: netip.MustParseAddr("fd51:2391:523:f4ee::1"),
33 Dst: netip.MustParseAddr("fd51:2391:697:f4ee::2"),
34 Protocol: layers.IPProtocolUDP,
35 },
36 SrcPort: 52139,
37 DstPort: 1053,
38 },
39 }
40
41 encoder := NewEncoder()
42 for _, udp := range udps {
43 p, err := encoder.Encode(&udp)
44 require.NoError(t, err)
45
46 ipPacket, err := ipDecoder.Decode(p)
47 require.NoError(t, err)
48 assertIPLayer(t, &udp.IP, ipPacket)
49
50 icmpPacket, err := icmpDecoder.Decode(p)
51 require.Error(t, err)
52 require.Nil(t, icmpPacket)
53 }
54}
55
56func TestDecodeICMP(t *testing.T) {
57 ipDecoder := NewIPDecoder()

Callers

nothing calls this directly

Calls 8

EncodeMethod · 0.95
DecodeMethod · 0.95
DecodeMethod · 0.95
NewIPDecoderFunction · 0.85
NewICMPDecoderFunction · 0.85
NewEncoderFunction · 0.85
assertIPLayerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected