diff --git a/probe/endpoint/procspy/proc_internal_test.go b/probe/endpoint/procspy/proc_internal_test.go index 19c9aa381..8cab48202 100644 --- a/probe/endpoint/procspy/proc_internal_test.go +++ b/probe/endpoint/procspy/proc_internal_test.go @@ -18,7 +18,7 @@ var mockFS = fs.Dir("", fs.File{ FName: "16", FStat: syscall.Stat_t{ - Ino: 45, + Ino: 5107, Mode: syscall.S_IFSOCK, }, }, @@ -35,8 +35,10 @@ var mockFS = fs.Dir("", ), fs.Dir("net", fs.File{ - FName: "tcp", - FContents: "I'm a little teapot", + FName: "tcp", + FContents: ` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode + 0: 00000000:A6C0 00000000:0000 01 00000000:00000000 00:00000000 00000000 105 0 5107 1 ffff8800a6aaf040 100 0 0 10 2d +`, }, ), fs.File{ @@ -57,7 +59,7 @@ func TestWalkProcPid(t *testing.T) { t.Fatal(err) } want := map[uint64]*Proc{ - 45: { + 5107: { PID: 1, Name: "foo", }, diff --git a/probe/endpoint/procspy/spy_linux_internal_test.go b/probe/endpoint/procspy/spy_linux_internal_test.go new file mode 100644 index 000000000..fc5ed3890 --- /dev/null +++ b/probe/endpoint/procspy/spy_linux_internal_test.go @@ -0,0 +1,40 @@ +package procspy + +import ( + "net" + "reflect" + "testing" + + fs_hook "github.com/weaveworks/scope/common/fs" + "github.com/weaveworks/scope/probe/process" + "github.com/weaveworks/scope/test" +) + +func TestLinuxConnections(t *testing.T) { + fs_hook.Mock(mockFS) + defer fs_hook.Restore() + + iter, err := cbConnections(true, process.NewWalker("/proc")) + if err != nil { + t.Fatal(err) + } + have := iter.Next() + want := &Connection{ + LocalAddress: net.ParseIP("0.0.0.0").To4(), + LocalPort: 42688, + RemoteAddress: net.ParseIP("0.0.0.0").To4(), + RemotePort: 0, + inode: 5107, + Proc: Proc{ + PID: 1, + Name: "foo", + }, + } + if !reflect.DeepEqual(want, have) { + t.Fatal(test.Diff(want, have)) + } + + if have := iter.Next(); have != nil { + t.Fatal(have) + } +}