-
Notifications
You must be signed in to change notification settings - Fork 63
/
conn_darwin_test.go
32 lines (24 loc) · 1.03 KB
/
conn_darwin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type noopInvoker struct{}
func (noopInvoker) Exec() ([]byte, error) {
output := `
goland 44546 1 chenjiandongx 14u IPv4 0x22b93638598dd98d 0t0 UDP *:60203
goland 44546 1 chenjiandongx 17u IPv4 0x22b93638598dfb3d 0t0 UDP *:8976
wget 44817 44815 chenjiandongx 19u IPv4 0x22b9363883c47b35 0t0 TCP 127.0.0.1:53747->127.0.0.1:49152 (ESTABLISHED)`
return []byte(output), nil
}
func TestDarwinGetSockets(t *testing.T) {
conn := lsofConn{invoker: noopInvoker{}}
sockets, err := conn.GetOpenSockets()
assert.NoError(t, err)
expected := map[LocalSocket]ProcessInfo{
{IP: "*", Port: 8976, Protocol: ProtoUDP}: {Pid: 44546, Name: "goland"},
{IP: "*", Port: 60203, Protocol: ProtoUDP}: {Pid: 44546, Name: "goland"},
{IP: "127.0.0.1", Port: 53747, Protocol: ProtoTCP}: {Pid: 44817, Name: "wget"},
}
assert.Equal(t, OpenSockets(expected), sockets)
}