2014-12-30 21:09:05 +08:00
|
|
|
package host
|
2014-04-18 15:34:47 +08:00
|
|
|
|
|
|
|
import (
|
2014-05-12 10:51:08 +08:00
|
|
|
"fmt"
|
2014-04-18 15:34:47 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHostInfo(t *testing.T) {
|
2016-03-22 22:09:12 +08:00
|
|
|
v, err := Info()
|
2014-04-18 15:34:47 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
2016-03-22 22:09:12 +08:00
|
|
|
empty := &InfoStat{}
|
2014-05-12 10:51:08 +08:00
|
|
|
if v == empty {
|
2014-04-22 09:39:55 +08:00
|
|
|
t.Errorf("Could not get hostinfo %v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBoot_time(t *testing.T) {
|
2014-05-23 09:31:47 +08:00
|
|
|
v, err := BootTime()
|
2014-04-22 09:39:55 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
|
|
|
if v == 0 {
|
2015-06-19 10:58:46 +08:00
|
|
|
t.Errorf("Could not get boot time %v", v)
|
2014-04-18 15:34:47 +08:00
|
|
|
}
|
|
|
|
}
|
2014-04-22 16:38:47 +08:00
|
|
|
|
|
|
|
func TestUsers(t *testing.T) {
|
2014-05-23 09:31:47 +08:00
|
|
|
v, err := Users()
|
2014-04-22 16:38:47 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
2014-05-23 09:31:47 +08:00
|
|
|
empty := UserStat{}
|
2014-04-22 16:39:51 +08:00
|
|
|
for _, u := range v {
|
2014-05-12 10:51:08 +08:00
|
|
|
if u == empty {
|
2014-04-22 16:38:47 +08:00
|
|
|
t.Errorf("Could not Users %v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-12 10:51:08 +08:00
|
|
|
|
|
|
|
func TestHostInfoStat_String(t *testing.T) {
|
2016-03-22 22:09:12 +08:00
|
|
|
v := InfoStat{
|
2014-05-12 10:51:08 +08:00
|
|
|
Hostname: "test",
|
|
|
|
Uptime: 3000,
|
|
|
|
Procs: 100,
|
2014-05-16 17:11:17 +08:00
|
|
|
OS: "linux",
|
2014-05-16 15:37:20 +08:00
|
|
|
Platform: "ubuntu",
|
2015-11-24 08:30:17 +08:00
|
|
|
BootTime: 1447040000,
|
2014-05-12 10:51:08 +08:00
|
|
|
}
|
2016-03-23 09:52:46 +08:00
|
|
|
e := `{"hostname":"test","uptime":3000,"bootTime":1447040000,"procs":100,"os":"linux","platform":"ubuntu","platformFamily":"","platformVersion":"","virtualizationSystem":"","virtualizationRole":""}`
|
2014-05-12 10:51:08 +08:00
|
|
|
if e != fmt.Sprintf("%v", v) {
|
|
|
|
t.Errorf("HostInfoStat string is invalid: %v", v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserStat_String(t *testing.T) {
|
2014-05-23 09:31:47 +08:00
|
|
|
v := UserStat{
|
2014-05-12 10:51:08 +08: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)
|
|
|
|
}
|
|
|
|
}
|