(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestPCAPGoWrite(t *testing.T) { |
| 21 | f, err := ioutil.TempFile("", "pcapgo") |
| 22 | if err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | data := []byte{0xab, 0xcd, 0xef, 0x01, 0x02, 0x03, 0x04} |
| 26 | ci := gopacket.CaptureInfo{ |
| 27 | Timestamp: time.Unix(12345667, 1234567000), |
| 28 | Length: 700, |
| 29 | CaptureLength: len(data), |
| 30 | } |
| 31 | func() { |
| 32 | defer f.Close() |
| 33 | w := pcapgo.NewWriter(f) |
| 34 | if err := w.WriteFileHeader(65536, layers.LinkTypeEthernet); err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | if err := w.WritePacket(ci, data); err != nil { |
| 38 | t.Fatal(err) |
| 39 | } |
| 40 | }() |
| 41 | h, err := OpenOffline(f.Name()) |
| 42 | if err != nil { |
| 43 | t.Fatal(err) |
| 44 | } |
| 45 | defer h.Close() |
| 46 | gotData, gotCI, err := h.ReadPacketData() |
| 47 | if err != nil { |
| 48 | t.Fatal("could not read first packet:", err) |
| 49 | } |
| 50 | if !bytes.Equal(gotData, data) { |
| 51 | t.Errorf("byte mismatch:\nwant: %v\n got: %v", data, gotData) |
| 52 | } |
| 53 | if !reflect.DeepEqual(ci, gotCI) { |
| 54 | t.Errorf("CI mismatch:\nwant: %v\n got: %v", ci, gotCI) |
| 55 | } |
| 56 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…