From 06cac0fecdc29196187908b74939a2926c28a6d9 Mon Sep 17 00:00:00 2001 From: Tatsushi Demachi Date: Tue, 18 Aug 2015 21:58:05 +0900 Subject: [PATCH] Add listen function's test --- fastping_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fastping_test.go b/fastping_test.go index 6028898..c708b82 100644 --- a/fastping_test.go +++ b/fastping_test.go @@ -353,6 +353,27 @@ func TestErr(t *testing.T) { } } +func TestListen(t *testing.T) { + noSource := "" + invalidSource := "192.0.2" + + p := NewPinger() + p.ctx = newContext() + + conn := p.listen("ip4:icmp", noSource) + if conn == nil { + t.Errorf("listen failed: %v", p.Err()) + } else { + conn.Close() + } + + conn = p.listen("ip4:icmp", invalidSource) + if conn != nil { + t.Errorf("listen should return nothing but something: %v", conn) + conn.Close() + } +} + func TestTimeToBytes(t *testing.T) { // 2009-11-10 23:00:00 +0000 UTC = 1257894000000000000 expect := []byte{0x11, 0x74, 0xef, 0xed, 0xab, 0x18, 0x60, 0x00}