From 34b63e671bb5ba4fe9a2a937789464b8805bb68e Mon Sep 17 00:00:00 2001 From: Shirou WAKAYAMA Date: Thu, 10 Mar 2016 22:32:16 +0900 Subject: [PATCH] [net]linux: add a test and fix private field name. --- net/net_linux.go | 18 +++++++++--------- net/net_linux_test.go | 5 +++++ net/net_test.go | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/net/net_linux.go b/net/net_linux.go index a2006ec..5d538f6 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -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 diff --git a/net/net_linux_test.go b/net/net_linux_test.go index 55f1ec2..47faeb9 100644 --- a/net/net_linux_test.go +++ b/net/net_linux_test.go @@ -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)) +} diff --git a/net/net_test.go b/net/net_test.go index 0bac45f..aabce81 100644 --- a/net/net_test.go +++ b/net/net_test.go @@ -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", -- GitLab