From 33a1e5d8138ca8640b4ddbe60ca13d34fde7e302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20P=C3=A9rez-Aradros=20Herce?= Date: Thu, 8 Jun 2017 14:46:41 +0200 Subject: [PATCH] Add tests for latest ipv6 related fixes Add tests for #4442 --- packetbeat/procs/procs_test.go | 16 +++++----------- packetbeat/tests/files/proc_net_tcp6.txt | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/packetbeat/procs/procs_test.go b/packetbeat/procs/procs_test.go index 9deaa84d6aed..1122f60cfcf3 100644 --- a/packetbeat/procs/procs_test.go +++ b/packetbeat/procs/procs_test.go @@ -209,11 +209,7 @@ func TestFindSocketsOfPid(t *testing.T) { } func TestParse_Proc_Net_Tcp(t *testing.T) { - file, err := os.Open("../tests/files/proc_net_tcp.txt") - if err != nil { - t.Fatalf("Opening ../tests/files/proc_net_tcp.txt: %s", err) - } - socketInfo, err := parseProcNetTCP(file, false) + socketInfo, err := socketsFromProc("../tests/files/proc_net_tcp.txt", false) if err != nil { t.Fatalf("Parse_Proc_Net_Tcp: %s", err) } @@ -229,11 +225,7 @@ func TestParse_Proc_Net_Tcp(t *testing.T) { } func TestParse_Proc_Net_Tcp6(t *testing.T) { - file, err := os.Open("../tests/files/proc_net_tcp6.txt") - if err != nil { - t.Fatalf("Opening ../tests/files/proc_net_tcp6.txt: %s", err) - } - socketInfo, err := parseProcNetTCP(file, true) + socketInfo, err := socketsFromProc("../tests/files/proc_net_tcp6.txt", true) if err != nil { t.Fatalf("Parse_Proc_Net_Tcp: %s", err) } @@ -243,8 +235,10 @@ func TestParse_Proc_Net_Tcp6(t *testing.T) { if socketInfo[5].srcIP.String() != "::" { t.Error("Failed to parse source IP address ::, got instead", socketInfo[5].srcIP.String()) } - // TODO add an example of a 'real' IPv6 address if socketInfo[5].srcPort != 59497 { t.Error("Failed to parse source port 59497, got instead", socketInfo[5].srcPort) } + if socketInfo[4].srcIP.String() != "2001:db8::123:ffff:89ab:cdef" { + t.Error("Failed to parse source IP address 2001:db8::123:ffff:89ab:cdef, got instead", socketInfo[4].srcIP.String()) + } } diff --git a/packetbeat/tests/files/proc_net_tcp6.txt b/packetbeat/tests/files/proc_net_tcp6.txt index 2489a8aaa1f1..e68549618e06 100644 --- a/packetbeat/tests/files/proc_net_tcp6.txt +++ b/packetbeat/tests/files/proc_net_tcp6.txt @@ -3,5 +3,5 @@ 1: 00000000000000000000000001000000:0277 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 3465486 1 ffff88041a77aa40 100 0 0 10 0 2: 00000000000000000000000001000000:1538 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 131 0 25936 1 ffff8800c541c080 100 0 0 10 0 3: 00000000000000000000000001000000:0019 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 23925 1 ffff8800c541c900 100 0 0 10 0 - 4: 00000000000000000000000000000000:445C 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 1000 0 33807 1 ffff88041a77a1c0 100 0 0 10 0 + 4: B80D012000000000FFFF2301EFCDAB89:445C 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 1000 0 33807 1 ffff88041a77a1c0 100 0 0 10 0 5: 00000000000000000000000000000000:E869 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 104 0 15881 1 ffff8800c541d180 100 0 0 10 0