fix test and openbsd errors.

pull/980/head
shirou 5 years ago
parent 9ffeb8d368
commit f377a07e5a

@ -40,7 +40,7 @@ func TestCpu_times(t *testing.T) {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
if len(cpuTotal) == 0 { if len(cpuTotal) == 0 {
t.Error("could not get CPUs ", err) t.Error("could not get CPUs", err)
} }
perCPU, err := Times(true) perCPU, err := Times(true)
skipIfNotImplementedErr(t, err) skipIfNotImplementedErr(t, err)
@ -48,7 +48,7 @@ func TestCpu_times(t *testing.T) {
t.Errorf("error %v", err) t.Errorf("error %v", err)
} }
if len(perCPU) == 0 { if len(perCPU) == 0 {
t.Error("could not get CPUs ", err) t.Error("could not get CPUs", err)
} }
var perCPUUserTimeSum float64 var perCPUUserTimeSum float64
var perCPUSystemTimeSum float64 var perCPUSystemTimeSum float64
@ -59,9 +59,21 @@ func TestCpu_times(t *testing.T) {
perCPUIdleTimeSum += pc.Idle perCPUIdleTimeSum += pc.Idle
} }
margin := 2.0 margin := 2.0
assert.InEpsilon(t, cpuTotal[0].User, perCPUUserTimeSum, margin) t.Log(cpuTotal[0])
assert.InEpsilon(t, cpuTotal[0].System, perCPUSystemTimeSum, margin)
assert.InEpsilon(t, cpuTotal[0].Idle, perCPUIdleTimeSum, margin) if cpuTotal[0].User == 0 && cpuTotal[0].System == 0 && cpuTotal[0].Idle == 0 {
t.Error("could not get cpu values")
}
if cpuTotal[0].User != 0 {
assert.InEpsilon(t, cpuTotal[0].User, perCPUUserTimeSum, margin)
}
if cpuTotal[0].System != 0 {
assert.InEpsilon(t, cpuTotal[0].System, perCPUSystemTimeSum, margin)
}
if cpuTotal[0].Idle != 0 {
assert.InEpsilon(t, cpuTotal[0].Idle, perCPUIdleTimeSum, margin)
}
} }
func TestCpu_counts(t *testing.T) { func TestCpu_counts(t *testing.T) {

@ -92,13 +92,13 @@ func TestUsers(t *testing.T) {
func TestHostInfoStat_String(t *testing.T) { func TestHostInfoStat_String(t *testing.T) {
v := InfoStat{ v := InfoStat{
Hostname: "test", Hostname: "test",
Uptime: 3000, Uptime: 3000,
Procs: 100, Procs: 100,
OS: "linux", OS: "linux",
Platform: "ubuntu", Platform: "ubuntu",
BootTime: 1447040000, BootTime: 1447040000,
HostID: "edfd25ff-3c9c-b1a4-e660-bd826495ad35", HostID: "edfd25ff-3c9c-b1a4-e660-bd826495ad35",
KernelArch: "x86_64", KernelArch: "x86_64",
} }
e := `{"hostname":"test","uptime":3000,"bootTime":1447040000,"procs":100,"os":"linux","platform":"ubuntu","platformFamily":"","platformVersion":"","kernelVersion":"","kernelArch":"x86_64","virtualizationSystem":"","virtualizationRole":"","hostid":"edfd25ff-3c9c-b1a4-e660-bd826495ad35"}` e := `{"hostname":"test","uptime":3000,"bootTime":1447040000,"procs":100,"os":"linux","platform":"ubuntu","platformFamily":"","platformVersion":"","kernelVersion":"","kernelArch":"x86_64","virtualizationSystem":"","virtualizationRole":"","hostid":"edfd25ff-3c9c-b1a4-e660-bd826495ad35"}`
@ -121,15 +121,15 @@ func TestUserStat_String(t *testing.T) {
} }
func TestHostGuid(t *testing.T) { func TestHostGuid(t *testing.T) {
hi, err := Info() id, err := HostID()
skipIfNotImplementedErr(t, err) skipIfNotImplementedErr(t, err)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if hi.HostID == "" { if id == "" {
t.Error("Host id is empty") t.Error("Host id is empty")
} else { } else {
t.Logf("Host id value: %v", hi.HostID) t.Logf("Host id value: %v", id)
} }
} }

@ -4,7 +4,6 @@ package net
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os/exec" "os/exec"
"regexp" "regexp"
@ -153,7 +152,7 @@ func FilterCounters() ([]FilterStat, error) {
} }
func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) { func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
return nil, errors.New("NetFilterCounters not implemented for openbsd") return nil, common.ErrNotImplementedError
} }
func ConntrackStats(percpu bool) ([]ConntrackStat, error) { func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
@ -173,7 +172,7 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
} }
func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) { func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) {
return nil, errors.New("NetProtoCounters not implemented for openbsd") return nil, common.ErrNotImplementedError
} }
func parseNetstatLine(line string) (ConnectionStat, error) { func parseNetstatLine(line string) (ConnectionStat, error) {

Loading…
Cancel
Save