Merge pull request #751 from weaveworks/testing

Add some more testing to procspy
This commit is contained in:
Tom Wilkie
2015-12-15 17:56:41 +00:00
2 changed files with 46 additions and 4 deletions

View File

@@ -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",
},

View 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)
}
}