From 22aefb460aec32d60c408c86b4285ce5d3fc3c1f Mon Sep 17 00:00:00 2001 From: Eric Gourlaouen Date: Mon, 20 Mar 2017 18:55:04 +0100 Subject: [PATCH] Replaced sys by HostSys Added TemperatureStat string test --- host/host_linux.go | 4 ++-- host/host_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/host/host_linux.go b/host/host_linux.go index 230db65..f4e35b9 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -525,14 +525,14 @@ func Virtualization() (string, string, error) { func SensorsTemperatures() ([]TemperatureStat, error) { var temperatures []TemperatureStat - files, err := filepath.Glob("/sys/class/hwmon/hwmon*/temp*_*") + files, err := filepath.Glob(common.HostSys("/class/hwmon/hwmon*/temp*_*")) if err != nil { return temperatures, err } if len(files) == 0 { // CentOS has an intermediate /device directory: // https://github.com/giampaolo/psutil/issues/971 - files, err = filepath.Glob("/sys/class/hwmon/hwmon*/temp*_*") + files, err = filepath.Glob(common.HostSys("/class/hwmon/hwmon*/temp*_*")) if err != nil { return temperatures, err } diff --git a/host/host_test.go b/host/host_test.go index e751893..85b07cd 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -103,3 +103,14 @@ func TestHostGuid(t *testing.T) { t.Logf("Host id value: %v", hi.HostID) } } + +func TestTemperatureStat_String(t *testing.T) { + v := TemperatureStat{ + SensorKey: "CPU", + Temperature: 1.1, + } + s := `{"sensorKey":"CPU","sensorTemperature":1.1}` + if s != fmt.Sprintf("%v", v) { + t.Errorf("TemperatureStat string is invalid") + } +}