diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-12 22:02:45 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-12 23:01:34 +0900 |
commit | f60ce32b8b1f6f161e840e0162bfaf1137d29a0b (patch) | |
tree | 18ac007ea54f23d1bf2639dd8f7f759e14de5284 /packet/bgp_test.go | |
parent | 93f5c44b390ccf84fd2d97b321e7b435c683c616 (diff) |
packet: use reflect.DeepEqual() for unit tests
This fixes the problem that the current unit tests don't guarantee
that DecodeFromBytes() properly parses the data generated by
Serialize().
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp_test.go')
-rw-r--r-- | packet/bgp_test.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 286bd27c..983914f1 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "github.com/stretchr/testify/assert" "net" + "reflect" "testing" ) @@ -142,20 +143,22 @@ func update() *BGPMessage { func Test_Message(t *testing.T) { l := []*BGPMessage{keepalive(), notification(), refresh(), open(), update()} - for _, m := range l { - buf1, _ := m.Serialize() + for _, m1 := range l { + buf1, _ := m1.Serialize() t.Log("LEN =", len(buf1)) - msg, err := ParseBGPMessage(buf1) + m2, err := ParseBGPMessage(buf1) if err != nil { t.Error(err) } - buf2, _ := msg.Serialize() - if bytes.Compare(buf1, buf2) == 0 { + // FIXME: shouldn't but workaround for some structs. + buf2, _ := m2.Serialize() + + if reflect.DeepEqual(m1, m2) == true { t.Log("OK") } else { t.Error("Something wrong") - t.Error(len(buf1), &m, buf1) - t.Error(len(buf2), &msg, buf2) + t.Error(len(buf1), m1, buf1) + t.Error(len(buf2), m2, buf2) } } } |