mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
Merge pull request #928 from Lomanic/skip-tests-when-not-implemented
This commit is contained in:
commit
4cfc60d68b
@ -7,11 +7,19 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCpu_times(t *testing.T) {
|
||||
v, err := Times(false)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -27,6 +35,7 @@ func TestCpu_times(t *testing.T) {
|
||||
|
||||
// test sum of per cpu stats is within margin of error for cpu total stats
|
||||
cpuTotal, err := Times(false)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -34,6 +43,7 @@ func TestCpu_times(t *testing.T) {
|
||||
t.Error("could not get CPUs ", err)
|
||||
}
|
||||
perCPU, err := Times(true)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -56,6 +66,7 @@ func TestCpu_times(t *testing.T) {
|
||||
|
||||
func TestCpu_counts(t *testing.T) {
|
||||
v, err := Counts(true)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -79,6 +90,7 @@ func TestCPUTimeStat_String(t *testing.T) {
|
||||
|
||||
func TestCpuInfo(t *testing.T) {
|
||||
v, err := Info()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -99,6 +111,7 @@ func testCPUPercent(t *testing.T, percpu bool) {
|
||||
if runtime.GOOS != "windows" {
|
||||
testCount = 100
|
||||
v, err := Percent(time.Millisecond, percpu)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -112,6 +125,7 @@ func testCPUPercent(t *testing.T, percpu bool) {
|
||||
for i := 0; i < testCount; i++ {
|
||||
duration := time.Duration(10) * time.Microsecond
|
||||
v, err := Percent(duration, percpu)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -132,6 +146,7 @@ func testCPUPercentLastUsed(t *testing.T, percpu bool) {
|
||||
if runtime.GOOS != "windows" {
|
||||
testCount = 2
|
||||
v, err := Percent(time.Millisecond, percpu)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -144,6 +159,7 @@ func testCPUPercentLastUsed(t *testing.T, percpu bool) {
|
||||
}
|
||||
for i := 0; i < testCount; i++ {
|
||||
v, err := Percent(0, percpu)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
|
@ -5,14 +5,23 @@ import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisk_usage(t *testing.T) {
|
||||
path := "/"
|
||||
if runtime.GOOS == "windows" {
|
||||
path = "C:"
|
||||
}
|
||||
v, err := Usage(path)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -23,6 +32,7 @@ func TestDisk_usage(t *testing.T) {
|
||||
|
||||
func TestDisk_partitions(t *testing.T) {
|
||||
ret, err := Partitions(false)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil || len(ret) == 0 {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -41,6 +51,7 @@ func TestDisk_partitions(t *testing.T) {
|
||||
|
||||
func TestDisk_io_counters(t *testing.T) {
|
||||
ret, err := IOCounters()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
|
@ -4,10 +4,19 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHostInfo(t *testing.T) {
|
||||
v, err := Info()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -26,6 +35,7 @@ func TestUptime(t *testing.T) {
|
||||
}
|
||||
|
||||
v, err := Uptime()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -39,6 +49,7 @@ func TestBoot_time(t *testing.T) {
|
||||
t.Skip("Skip CI")
|
||||
}
|
||||
v, err := BootTime()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -51,6 +62,7 @@ func TestBoot_time(t *testing.T) {
|
||||
t.Logf("first boot time: %d", v)
|
||||
|
||||
v2, err := BootTime()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -62,6 +74,7 @@ func TestBoot_time(t *testing.T) {
|
||||
|
||||
func TestUsers(t *testing.T) {
|
||||
v, err := Users()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -85,8 +98,9 @@ func TestHostInfoStat_String(t *testing.T) {
|
||||
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":"","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"}`
|
||||
if e != fmt.Sprintf("%v", v) {
|
||||
t.Errorf("HostInfoStat string is invalid:\ngot %v\nwant %v", v, e)
|
||||
}
|
||||
@ -107,6 +121,7 @@ func TestUserStat_String(t *testing.T) {
|
||||
|
||||
func TestHostGuid(t *testing.T) {
|
||||
hi, err := Info()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -130,6 +145,7 @@ func TestTemperatureStat_String(t *testing.T) {
|
||||
|
||||
func TestVirtualization(t *testing.T) {
|
||||
system, role, err := Virtualization()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Virtualization() failed, %v", err)
|
||||
}
|
||||
@ -139,6 +155,7 @@ func TestVirtualization(t *testing.T) {
|
||||
|
||||
func TestKernelVersion(t *testing.T) {
|
||||
version, err := KernelVersion()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("KernelVersion() failed, %v", err)
|
||||
}
|
||||
@ -151,6 +168,7 @@ func TestKernelVersion(t *testing.T) {
|
||||
|
||||
func TestPlatformInformation(t *testing.T) {
|
||||
platform, family, version, err := PlatformInformation()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("PlatformInformation() failed, %v", err)
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ func Users() ([]UserStat, error) {
|
||||
func UsersWithContext(ctx context.Context) ([]UserStat, error) {
|
||||
var ret []UserStat
|
||||
|
||||
return ret, nil
|
||||
return ret, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func SensorsTemperatures() ([]TemperatureStat, error) {
|
||||
|
@ -3,10 +3,19 @@ package load
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
v, err := Avg()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -33,6 +42,7 @@ func TestLoadAvgStat_String(t *testing.T) {
|
||||
|
||||
func TestMisc(t *testing.T) {
|
||||
v, err := Misc()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
|
@ -5,15 +5,23 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVirtual_memory(t *testing.T) {
|
||||
if runtime.GOOS == "solaris" {
|
||||
t.Skip("Only .Total is supported on Solaris")
|
||||
}
|
||||
|
||||
v, err := VirtualMemory()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
@ -44,7 +52,7 @@ func TestVirtual_memory(t *testing.T) {
|
||||
"Total should be computable (%v): %v", totalStr, v)
|
||||
|
||||
assert.True(t, runtime.GOOS == "windows" || v.Free > 0)
|
||||
assert.True(t, v.Available > v.Free,
|
||||
assert.True(t, runtime.GOOS == "windows" || v.Available > v.Free,
|
||||
"Free should be a subset of Available: %v", v)
|
||||
|
||||
inDelta := assert.InDelta
|
||||
@ -58,6 +66,7 @@ func TestVirtual_memory(t *testing.T) {
|
||||
|
||||
func TestSwap_memory(t *testing.T) {
|
||||
v, err := SwapMemory()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
|
@ -9,6 +9,12 @@ import (
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddrString(t *testing.T) {
|
||||
v := Addr{IP: "192.168.0.1", Port: 8000}
|
||||
|
||||
@ -61,10 +67,12 @@ func TestNetConnectionStatString(t *testing.T) {
|
||||
|
||||
func TestNetIOCountersAll(t *testing.T) {
|
||||
v, err := IOCounters(false)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Could not get NetIOCounters: %v", err)
|
||||
}
|
||||
per, err := IOCounters(true)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Could not get NetIOCounters: %v", err)
|
||||
}
|
||||
@ -85,6 +93,7 @@ func TestNetIOCountersAll(t *testing.T) {
|
||||
|
||||
func TestNetIOCountersPerNic(t *testing.T) {
|
||||
v, err := IOCounters(true)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Could not get NetIOCounters: %v", err)
|
||||
}
|
||||
@ -113,6 +122,7 @@ func TestGetNetIOCountersAll(t *testing.T) {
|
||||
},
|
||||
}
|
||||
ret, err := getIOCountersAll(n)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -132,6 +142,7 @@ func TestGetNetIOCountersAll(t *testing.T) {
|
||||
|
||||
func TestNetInterfaces(t *testing.T) {
|
||||
v, err := Interfaces()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("Could not get NetInterfaceStat: %v", err)
|
||||
}
|
||||
@ -147,6 +158,7 @@ func TestNetInterfaces(t *testing.T) {
|
||||
|
||||
func TestNetProtoCountersStatsAll(t *testing.T) {
|
||||
v, err := ProtoCounters(nil)
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get NetProtoCounters: %v", err)
|
||||
}
|
||||
@ -165,6 +177,7 @@ func TestNetProtoCountersStatsAll(t *testing.T) {
|
||||
|
||||
func TestNetProtoCountersStats(t *testing.T) {
|
||||
v, err := ProtoCounters([]string{"tcp", "ip"})
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get NetProtoCounters: %v", err)
|
||||
}
|
||||
@ -190,6 +203,7 @@ func TestNetConnections(t *testing.T) {
|
||||
}
|
||||
|
||||
v, err := Connections("inet")
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("could not get NetConnections: %v", err)
|
||||
}
|
||||
@ -217,6 +231,7 @@ func TestNetFilterCounters(t *testing.T) {
|
||||
}
|
||||
|
||||
v, err := FilterCounters()
|
||||
skipIfNotImplementedErr(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("could not get NetConnections: %v", err)
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ package net
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
@ -323,7 +322,7 @@ func FilterCounters() ([]FilterStat, error) {
|
||||
}
|
||||
|
||||
func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
|
||||
return nil, errors.New("NetFilterCounters not implemented for windows")
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func ConntrackStats(percpu bool) ([]ConntrackStat, error) {
|
||||
@ -344,7 +343,7 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
|
||||
}
|
||||
|
||||
func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) {
|
||||
return nil, errors.New("NetProtoCounters not implemented for windows")
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func getTableUintptr(family uint32, buf []byte) uintptr {
|
||||
|
Loading…
x
Reference in New Issue
Block a user