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) {
|
2016-03-22 23:09:12 +09:00
|
|
|
v, err := Info()
|
2014-04-18 16:34:47 +09:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
2016-03-22 23:09:12 +09:00
|
|
|
empty := &InfoStat{}
|
2014-05-12 11:51:08 +09:00
|
|
|
if v == empty {
|
2014-04-22 10:39:55 +09:00
|
|
|
t.Errorf("Could not get hostinfo %v", v)
|
|
|
|
}
|
2016-07-10 23:47:29 -05:00
|
|
|
if v.Procs == 0 {
|
|
|
|
t.Errorf("Could not determine the number of host processes")
|
|
|
|
}
|
2014-04-22 10:39:55 +09:00
|
|
|
}
|
|
|
|
|
2016-06-12 23:20:51 +09:00
|
|
|
func TestUptime(t *testing.T) {
|
|
|
|
v, err := Uptime()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
|
|
|
if v == 0 {
|
|
|
|
t.Errorf("Could not get up time %v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-22 10:39:55 +09:00
|
|
|
func TestBoot_time(t *testing.T) {
|
2014-05-23 10:31:47 +09:00
|
|
|
v, err := BootTime()
|
2014-04-22 10:39:55 +09:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
|
|
|
if v == 0 {
|
2015-06-19 11:58:46 +09:00
|
|
|
t.Errorf("Could not get boot time %v", v)
|
2014-04-18 16:34:47 +09:00
|
|
|
}
|
2016-06-12 23:20:51 +09:00
|
|
|
if v < 946652400 {
|
|
|
|
t.Errorf("Invalid Boottime, older than 2000-01-01")
|
|
|
|
}
|
2014-04-18 16:34:47 +09:00
|
|
|
}
|
2014-04-22 17:38:47 +09:00
|
|
|
|
|
|
|
func TestUsers(t *testing.T) {
|
2014-05-23 10:31:47 +09:00
|
|
|
v, err := Users()
|
2014-04-22 17:38:47 +09:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
2014-05-23 10:31:47 +09:00
|
|
|
empty := UserStat{}
|
2016-04-23 23:43:00 +09:00
|
|
|
if len(v) == 0 {
|
|
|
|
t.Errorf("Users is empty")
|
|
|
|
}
|
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) {
|
2016-03-22 23:09:12 +09:00
|
|
|
v := InfoStat{
|
2014-05-12 11:51:08 +09:00
|
|
|
Hostname: "test",
|
|
|
|
Uptime: 3000,
|
|
|
|
Procs: 100,
|
2014-05-16 18:11:17 +09:00
|
|
|
OS: "linux",
|
2014-05-16 16:37:20 +09:00
|
|
|
Platform: "ubuntu",
|
2015-11-24 09:30:17 +09:00
|
|
|
BootTime: 1447040000,
|
2016-08-11 00:51:07 -07:00
|
|
|
HostID: "edfd25ff-3c9c-b1a4-e660-bd826495ad35",
|
2014-05-12 11:51:08 +09:00
|
|
|
}
|
2016-08-22 14:15:30 -07:00
|
|
|
e := `{"hostname":"test","uptime":3000,"bootTime":1447040000,"procs":100,"os":"linux","platform":"ubuntu","platformFamily":"","platformVersion":"","kernelVersion":"","virtualizationSystem":"","virtualizationRole":"","hostid":"edfd25ff-3c9c-b1a4-e660-bd826495ad35"}`
|
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) {
|
2014-05-23 10:31:47 +09:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|