(t *testing.T)
| 46 | } |
| 47 | |
| 48 | func TestFiles(t *testing.T) { |
| 49 | for _, fname := range []string{"usec", "nsec"} { |
| 50 | f, err := os.Open(fmt.Sprintf("testdata/%s.pcap", fname)) |
| 51 | if err != nil { |
| 52 | t.Fatalf("Opening test input file: %s", err) |
| 53 | } |
| 54 | r, err := NewReader(f) |
| 55 | if err != nil { |
| 56 | t.Fatalf("Creating pcap reader: %s", err) |
| 57 | } |
| 58 | if r.LinkType != LinkEthernet { |
| 59 | t.Errorf("Expected link type %d, got %d", LinkEthernet, r.LinkType) |
| 60 | } |
| 61 | |
| 62 | pkts := []*Packet{} |
| 63 | for r.Next() { |
| 64 | pkts = append(pkts, r.Packet()) |
| 65 | } |
| 66 | if r.Err() != nil { |
| 67 | t.Fatalf("Reading packets from %s.pcap: %s", fname, r.Err()) |
| 68 | } |
| 69 | res := sprintPackets(pkts) |
| 70 | |
| 71 | expectedFile := fmt.Sprintf("testdata/%s.parsed", fname) |
| 72 | expected, err := ioutil.ReadFile(expectedFile) |
| 73 | if err != nil { |
| 74 | t.Fatalf("Reading expected file: %s", err) |
| 75 | } |
| 76 | if res != string(expected) { |
| 77 | if os.Getenv("UPDATE_TESTDATA") != "" { |
| 78 | ioutil.WriteFile(expectedFile, []byte(res), 0644) |
| 79 | t.Errorf("%s.pcap didn't decode to %s.parsed (updated %s.parsed)", fname, fname, fname) |
| 80 | } else { |
| 81 | t.Fatalf("%s.pcap didn't decode to %s.parsed (rerun with UPDATE_TESTDATA=1 to get diff)", fname, fname) |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
nothing calls this directly
no test coverage detected