From 811048079352062abc7e380da545c4da4a5b0506 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Sat, 29 Aug 2020 18:29:48 +0200 Subject: [PATCH] [host] Skip tests on non-implemented platforms #446 --- host/host_test.go | 20 +++++++++++++++++++- host/host_windows.go | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/host/host_test.go b/host/host_test.go index b4db399..49d20a2 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -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) } diff --git a/host/host_windows.go b/host/host_windows.go index f9e1a16..e73c8c8 100644 --- a/host/host_windows.go +++ b/host/host_windows.go @@ -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) {