Merge pull request #980 from shirou/feature/fix_tests_and_not_implemented_error

fix test and openbsd errors.
tags/v3.20.10
shirou 5 years ago committed by GitHub
commit bb232c46d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -92,13 +92,13 @@ func TestUsers(t *testing.T) {
func TestHostInfoStat_String(t *testing.T) {
v := InfoStat{
Hostname: "test",
Uptime: 3000,
Procs: 100,
OS: "linux",
Platform: "ubuntu",
BootTime: 1447040000,
HostID: "edfd25ff-3c9c-b1a4-e660-bd826495ad35",
Hostname: "test",
Uptime: 3000,
Procs: 100,
OS: "linux",
Platform: "ubuntu",
BootTime: 1447040000,
HostID: "edfd25ff-3c9c-b1a4-e660-bd826495ad35",
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"}`
@ -121,15 +121,15 @@ func TestUserStat_String(t *testing.T) {
}
func TestHostGuid(t *testing.T) {
hi, err := Info()
id, err := HostID()
skipIfNotImplementedErr(t, err)
if err != nil {
t.Error(err)
}
if hi.HostID == "" {
if id == "" {
t.Error("Host id is empty")
} else {
t.Logf("Host id value: %v", hi.HostID)
t.Logf("Host id value: %v", id)
}
}

@ -4,7 +4,6 @@ package net
import (
"context"
"errors"
"fmt"
"os/exec"
"regexp"
@ -153,7 +152,7 @@ func FilterCounters() ([]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) {
@ -173,7 +172,7 @@ func ProtoCounters(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) {

Loading…
Cancel
Save