Skip to content

Commit

Permalink
Add tests for latest ipv6 related fixes (#4477)
Browse files Browse the repository at this point in the history
* Add tests for latest ipv6 related fixes

Add tests for #4442

* Fix error message

We don't really know what file we are reading from, as it could be
`/proc/net/tcp` or `/proc/net/tcp6`
  • Loading branch information
exekias authored and andrewkroh committed Jun 12, 2017
1 parent 4e34814 commit 3e2645b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packetbeat/procs/procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func parseProcNetTCP(input io.Reader, ipv6 bool) ([]*socketInfo, error) {
for err != io.EOF {
line, err = buf.ReadBytes('\n')
if err != nil && err != io.EOF {
logp.Err("Error reading /proc/net/tcp: %s", err)
logp.Err("Error reading proc net tcp file: %s", err)
return nil, err
}
words := bytes.Fields(line)
Expand Down
16 changes: 5 additions & 11 deletions packetbeat/procs/procs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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())
}
}
2 changes: 1 addition & 1 deletion packetbeat/tests/files/proc_net_tcp6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3e2645b

Please sign in to comment.