mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-10 19:29:14 +08:00
Merge branch 'master' of github.com:shirou/gopsutil
This commit is contained in:
commit
afd4d392e6
@ -4,6 +4,10 @@ gopsutil: psutil for golang
|
||||
.. image:: https://drone.io/github.com/shirou/gopsutil/status.png
|
||||
:target: https://drone.io/github.com/shirou/gopsutil
|
||||
|
||||
.. image:: https://coveralls.io/repos/shirou/gopsutil/badge.png?branch=master
|
||||
:target: https://coveralls.io/r/shirou/gopsutil?branch=master
|
||||
|
||||
|
||||
This is a port of psutil(http://pythonhosted.org/psutil/). This
|
||||
challenges porting all psutil functions on some architectures.
|
||||
|
||||
|
54
net_test.go
Normal file
54
net_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
package gopsutil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func TestAddrString(t *testing.T) {
|
||||
v := Addr{IP: "192.168.0.1", Port: 8000}
|
||||
|
||||
s := fmt.Sprintf("%v", v)
|
||||
if s != "{\"ip\":\"192.168.0.1\",\"port\":8000}" {
|
||||
t.Errorf("Addr string is invalid: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetIOCountersStatString(t *testing.T) {
|
||||
v := NetIOCountersStat{
|
||||
Name: "test",
|
||||
BytesSent: 100,
|
||||
}
|
||||
e := `{"name":"test","bytes_sent":100,"bytes_recv":0,"packets_sent":0,"packets_recv":0,"errin":0,"errout":0,"dropin":0,"dropout":0}`
|
||||
if e != fmt.Sprintf("%v", v) {
|
||||
t.Errorf("NetIOCountersStat string is invalid: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetConnectionStatString(t *testing.T) {
|
||||
v := NetConnectionStat{
|
||||
Fd: 10,
|
||||
Family: 10,
|
||||
Type: 10,
|
||||
}
|
||||
e := `{"fd":10,"family":10,"type":10,"laddr":{"ip":"","port":0},"raddr":{"ip":"","port":0},"status":"","pid":0}`
|
||||
if e != fmt.Sprintf("%v", v) {
|
||||
t.Errorf("NetConnectionStat string is invalid: %v", v)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNetIOCounters(t *testing.T) {
|
||||
v, err := NetIOCounters(true)
|
||||
if err != nil{
|
||||
t.Errorf("Could not get NetIOCounters: %v", err)
|
||||
}
|
||||
if len(v) == 0{
|
||||
t.Errorf("Could not get NetIOCounters: %v", v)
|
||||
}
|
||||
for _, vv := range(v){
|
||||
if vv.Name == ""{
|
||||
t.Errorf("Invalid NetIOCounters: %v", vv)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user