From e8185cf62da67378989658903e4f4c024ebd1ef4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 24 Dec 2017 17:22:09 -0800 Subject: [PATCH] Use cmp.Diff to compare pcap packets. This fixes a spurious failure from reflect.DeepEqual. --- glide.yaml | 5 +++++ pcap/writer_test.go | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/glide.yaml b/glide.yaml index d63e208..114b7af 100644 --- a/glide.yaml +++ b/glide.yaml @@ -10,3 +10,8 @@ import: - bpf - icmp - ipv4 +testImport: +- package: github.com/google/go-cmp + version: ^0.1.0 + subpackages: + - cmp diff --git a/pcap/writer_test.go b/pcap/writer_test.go index 0774d26..d4fb595 100644 --- a/pcap/writer_test.go +++ b/pcap/writer_test.go @@ -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) } }