提交 34b63e67 编写于 作者: S Shirou WAKAYAMA

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

上级 567da004
...@@ -217,32 +217,32 @@ var TCPStatuses = map[string]string{ ...@@ -217,32 +217,32 @@ var TCPStatuses = map[string]string{
type netConnectionKindType struct { type netConnectionKindType struct {
family uint32 family uint32
sockType uint32 sockType uint32
f string // file name filename string
} }
var kindTCP4 = netConnectionKindType{ var kindTCP4 = netConnectionKindType{
family: syscall.AF_INET, family: syscall.AF_INET,
sockType: syscall.SOCK_STREAM, sockType: syscall.SOCK_STREAM,
f: "tcp", filename: "tcp",
} }
var kindTCP6 = netConnectionKindType{ var kindTCP6 = netConnectionKindType{
family: syscall.AF_INET6, family: syscall.AF_INET6,
sockType: syscall.SOCK_STREAM, sockType: syscall.SOCK_STREAM,
f: "tcp6", filename: "tcp6",
} }
var kindUDP4 = netConnectionKindType{ var kindUDP4 = netConnectionKindType{
family: syscall.AF_INET, family: syscall.AF_INET,
sockType: syscall.SOCK_DGRAM, sockType: syscall.SOCK_DGRAM,
f: "udp", filename: "udp",
} }
var kindUDP6 = netConnectionKindType{ var kindUDP6 = netConnectionKindType{
family: syscall.AF_INET6, family: syscall.AF_INET6,
sockType: syscall.SOCK_DGRAM, sockType: syscall.SOCK_DGRAM,
f: "udp6", filename: "udp6",
} }
var kindUNIX = netConnectionKindType{ var kindUNIX = netConnectionKindType{
family: syscall.AF_UNIX, family: syscall.AF_UNIX,
f: "unix", filename: "unix",
} }
var netConnectionKindMap = map[string][]netConnectionKindType{ var netConnectionKindMap = map[string][]netConnectionKindType{
...@@ -309,7 +309,7 @@ func NetConnectionsPid(kind string, pid int32) ([]NetConnectionStat, error) { ...@@ -309,7 +309,7 @@ func NetConnectionsPid(kind string, pid int32) ([]NetConnectionStat, error) {
for _, t := range tmap { for _, t := range tmap {
var path string var path string
var ls []connTmp var ls []connTmp
path = fmt.Sprintf("%s/net/%s", root, t.f) path = fmt.Sprintf("%s/net/%s", root, t.filename)
switch t.family { switch t.family {
case syscall.AF_INET: case syscall.AF_INET:
fallthrough fallthrough
...@@ -456,7 +456,7 @@ func decodeAddress(family uint32, src string) (Addr, error) { ...@@ -456,7 +456,7 @@ func decodeAddress(family uint32, src string) (Addr, error) {
} }
decoded, err := hex.DecodeString(addr) decoded, err := hex.DecodeString(addr)
if err != nil { if err != nil {
return Addr{}, fmt.Errorf("decode error:", err) return Addr{}, fmt.Errorf("decode error, %s", err)
} }
var ip net.IP var ip net.IP
// Assumes this is little_endian // Assumes this is little_endian
......
...@@ -68,3 +68,8 @@ func TestDecodeAddress(t *testing.T) { ...@@ -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))
}
...@@ -91,7 +91,7 @@ func TestNetIOCountersPerNic(t *testing.T) { ...@@ -91,7 +91,7 @@ func TestNetIOCountersPerNic(t *testing.T) {
} }
} }
func Test_getNetIOCountersAll(t *testing.T) { func TestGetNetIOCountersAll(t *testing.T) {
n := []NetIOCountersStat{ n := []NetIOCountersStat{
NetIOCountersStat{ NetIOCountersStat{
Name: "a", Name: "a",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册