1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

[net]linux: add a test and fix private field name.

This commit is contained in:
Shirou WAKAYAMA 2016-03-10 22:32:16 +09:00
parent 567da004c5
commit 34b63e671b
3 changed files with 15 additions and 10 deletions

View File

@ -217,32 +217,32 @@ var TCPStatuses = map[string]string{
type netConnectionKindType struct {
family uint32
sockType uint32
f string // file name
filename string
}
var kindTCP4 = netConnectionKindType{
family: syscall.AF_INET,
sockType: syscall.SOCK_STREAM,
f: "tcp",
filename: "tcp",
}
var kindTCP6 = netConnectionKindType{
family: syscall.AF_INET6,
sockType: syscall.SOCK_STREAM,
f: "tcp6",
filename: "tcp6",
}
var kindUDP4 = netConnectionKindType{
family: syscall.AF_INET,
sockType: syscall.SOCK_DGRAM,
f: "udp",
filename: "udp",
}
var kindUDP6 = netConnectionKindType{
family: syscall.AF_INET6,
sockType: syscall.SOCK_DGRAM,
f: "udp6",
filename: "udp6",
}
var kindUNIX = netConnectionKindType{
family: syscall.AF_UNIX,
f: "unix",
family: syscall.AF_UNIX,
filename: "unix",
}
var netConnectionKindMap = map[string][]netConnectionKindType{
@ -309,7 +309,7 @@ func NetConnectionsPid(kind string, pid int32) ([]NetConnectionStat, error) {
for _, t := range tmap {
var path string
var ls []connTmp
path = fmt.Sprintf("%s/net/%s", root, t.f)
path = fmt.Sprintf("%s/net/%s", root, t.filename)
switch t.family {
case syscall.AF_INET:
fallthrough
@ -456,7 +456,7 @@ func decodeAddress(family uint32, src string) (Addr, error) {
}
decoded, err := hex.DecodeString(addr)
if err != nil {
return Addr{}, fmt.Errorf("decode error:", err)
return Addr{}, fmt.Errorf("decode error, %s", err)
}
var ip net.IP
// Assumes this is little_endian

View File

@ -68,3 +68,8 @@ func TestDecodeAddress(t *testing.T) {
}
}
}
func TestReverse(t *testing.T) {
src := []byte{0x01, 0x02, 0x03}
assert.Equal(t, []byte{0x03, 0x02, 0x01}, Reverse(src))
}

View File

@ -91,7 +91,7 @@ func TestNetIOCountersPerNic(t *testing.T) {
}
}
func Test_getNetIOCountersAll(t *testing.T) {
func TestGetNetIOCountersAll(t *testing.T) {
n := []NetIOCountersStat{
NetIOCountersStat{
Name: "a",