Use cmp.Diff to compare pcap packets.

This fixes a spurious failure from reflect.DeepEqual.
This commit is contained in:
David Anderson 2017-12-24 17:22:09 -08:00
parent bff58e14b3
commit e8185cf62d
2 changed files with 9 additions and 3 deletions

View File

@ -10,3 +10,8 @@ import:
- bpf
- icmp
- ipv4
testImport:
- package: github.com/google/go-cmp
version: ^0.1.0
subpackages:
- cmp

View File

@ -17,9 +17,10 @@ package pcap
import (
"bytes"
"encoding/binary"
"reflect"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func TestReadback(t *testing.T) {
@ -81,8 +82,8 @@ func TestReadback(t *testing.T) {
t.Fatalf("Reading packets back: %s", r.Err())
}
if !reflect.DeepEqual(pkts, readBack) {
t.Fatalf("Packets were mutated by write-then-read")
if diff := cmp.Diff(pkts, readBack); diff != "" {
t.Fatalf("Packets mutated by write-then-read (-want +got):\n%s", diff)
}
}