open-nomad/client/stats/host_test.go

33 lines
642 B
Go
Raw Normal View History

package stats
import (
"testing"
2021-03-30 18:47:33 +00:00
"github.com/shirou/gopsutil/v3/cpu"
)
func TestHostCpuStatsCalculator_Nan(t *testing.T) {
times := cpu.TimesStat{
User: 0.0,
Idle: 100.0,
System: 0.0,
}
calculator := NewHostCpuStatsCalculator()
calculator.Calculate(times)
idle, user, system, total := calculator.Calculate(times)
if idle != 100.0 {
t.Errorf("idle: Expected: %f, Got %f", 100.0, idle)
}
if user != 0.0 {
t.Errorf("user: Expected: %f, Got %f", 0.0, user)
}
if system != 0.0 {
t.Errorf("system: Expected: %f, Got %f", 0.0, system)
}
if total != 0.0 {
t.Errorf("total: Expected: %f, Got %f", 0.0, total)
}
}