You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gopsutil/load/load_test.go

70 lines
1.2 KiB
Go

package load
11 years ago
import (
"fmt"
11 years ago
"testing"
"github.com/shirou/gopsutil/internal/common"
11 years ago
)
func skipIfNotImplementedErr(t *testing.T, err error) {
if err == common.ErrNotImplementedError {
t.Skip("not implemented")
}
}
11 years ago
func TestLoad(t *testing.T) {
v, err := Avg()
skipIfNotImplementedErr(t, err)
11 years ago
if err != nil {
t.Errorf("error %v", err)
}
empty := &AvgStat{}
if v == empty {
11 years ago
t.Errorf("error load: %v", v)
}
t.Log(v)
11 years ago
}
func TestLoadAvgStat_String(t *testing.T) {
v := AvgStat{
Load1: 10.1,
Load5: 20.1,
Load15: 30.1,
}
e := `{"load1":10.1,"load5":20.1,"load15":30.1}`
if e != fmt.Sprintf("%v", v) {
t.Errorf("LoadAvgStat string is invalid: %v", v)
}
t.Log(e)
}
func TestMisc(t *testing.T) {
v, err := Misc()
skipIfNotImplementedErr(t, err)
if err != nil {
t.Errorf("error %v", err)
}
empty := &MiscStat{}
if v == empty {
t.Errorf("error load: %v", v)
}
t.Log(v)
}
func TestMiscStatString(t *testing.T) {
v := MiscStat{
ProcsTotal: 4,
ProcsRunning: 1,
ProcsBlocked: 2,
Ctxt: 3,
}
e := `{"procsTotal":4,"procsRunning":1,"procsBlocked":2,"ctxt":3}`
if e != fmt.Sprintf("%v", v) {
t.Errorf("TestMiscString string is invalid: %v", v)
}
t.Log(e)
}