MCPcopy Create free account
hub / github.com/google/gopacket / TestWritePacket

Function TestWritePacket

pcapgo/write_test.go:45–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestWritePacket(t *testing.T) {
46 ci := gopacket.CaptureInfo{
47 Timestamp: time.Unix(0x01020304, 0xAA*1000),
48 Length: 0xABCD,
49 CaptureLength: 10,
50 }
51 data := []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
52 var buf bytes.Buffer
53 w := NewWriter(&buf)
54 w.WritePacket(ci, data)
55 want := []byte{
56 0x04, 0x03, 0x02, 0x01, 0xAA, 0x00, 0x00, 0x00,
57 0x0A, 0x00, 0x00, 0x00, 0xCD, 0xAB, 0x00, 0x00,
58 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
59 }
60 if got := buf.Bytes(); !bytes.Equal(got, want) {
61 t.Errorf("buf mismatch:\nwant: %+v\ngot: %+v", want, got)
62 }
63}
64
65func BenchmarkWritePacket(b *testing.B) {
66 b.StopTimer()

Callers

nothing calls this directly

Calls 3

WritePacketMethod · 0.95
NewWriterFunction · 0.85
BytesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…