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

68 lines
1.3 KiB
Go
Raw Normal View History

2014-12-30 22:09:05 +09:00
package host
2014-04-18 16:34:47 +09:00
import (
2014-05-12 11:51:08 +09:00
"fmt"
2014-04-18 16:34:47 +09:00
"testing"
)
func TestHostInfo(t *testing.T) {
v, err := HostInfo()
2014-04-18 16:34:47 +09:00
if err != nil {
t.Errorf("error %v", err)
}
empty := &HostInfoStat{}
2014-05-12 11:51:08 +09:00
if v == empty {
t.Errorf("Could not get hostinfo %v", v)
}
}
func TestBoot_time(t *testing.T) {
v, err := BootTime()
if err != nil {
t.Errorf("error %v", err)
}
if v == 0 {
t.Errorf("Could not boot time %v", v)
2014-04-18 16:34:47 +09:00
}
}
2014-04-22 17:38:47 +09:00
func TestUsers(t *testing.T) {
v, err := Users()
2014-04-22 17:38:47 +09:00
if err != nil {
t.Errorf("error %v", err)
}
empty := UserStat{}
2014-04-22 17:39:51 +09:00
for _, u := range v {
2014-05-12 11:51:08 +09:00
if u == empty {
2014-04-22 17:38:47 +09:00
t.Errorf("Could not Users %v", v)
}
}
}
2014-05-12 11:51:08 +09:00
func TestHostInfoStat_String(t *testing.T) {
v := HostInfoStat{
2014-05-12 11:51:08 +09:00
Hostname: "test",
Uptime: 3000,
Procs: 100,
2014-05-16 18:11:17 +09:00
OS: "linux",
Platform: "ubuntu",
2014-05-12 11:51:08 +09:00
}
e := `{"hostname":"test","uptime":3000,"procs":100,"os":"linux","platform":"ubuntu","platform_family":"","platform_version":"","virtualization_system":"","virtualization_role":""}`
2014-05-12 11:51:08 +09:00
if e != fmt.Sprintf("%v", v) {
t.Errorf("HostInfoStat string is invalid: %v", v)
}
}
func TestUserStat_String(t *testing.T) {
v := UserStat{
2014-05-12 11:51:08 +09:00
User: "user",
Terminal: "term",
Host: "host",
Started: 100,
}
e := `{"user":"user","terminal":"term","host":"host","started":100}`
if e != fmt.Sprintf("%v", v) {
t.Errorf("UserStat string is invalid: %v", v)
}
}