mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
Add some more testing to procspy
This commit is contained in:
@@ -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",
|
||||
},
|
||||
|
||||
40
probe/endpoint/procspy/spy_linux_internal_test.go
Normal file
40
probe/endpoint/procspy/spy_linux_internal_test.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user