Replaced sys by HostSys

Added TemperatureStat string test
This commit is contained in:
Eric Gourlaouen 2017-03-20 18:55:04 +01:00
parent 8b08ca5fdc
commit 22aefb460a
2 changed files with 13 additions and 2 deletions

View File

@ -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
}

View File

@ -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")
}
}