From 66d4ad1f20e37fcff308b82677e08dad05cda726 Mon Sep 17 00:00:00 2001 From: David Roman Date: Tue, 8 Oct 2024 16:24:32 +0200 Subject: [PATCH] cmd_test: find echo from PATH instead of using a hardcoded path Closes: https://github.com/markusressel/fan2go/issues/320 --- internal/fans/cmd_test.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/fans/cmd_test.go b/internal/fans/cmd_test.go index cb94f26..1a086e9 100644 --- a/internal/fans/cmd_test.go +++ b/internal/fans/cmd_test.go @@ -5,8 +5,15 @@ import ( "github.com/markusressel/fan2go/internal/util" "github.com/stretchr/testify/assert" "testing" + "os/exec" ) +func getEchoPath() string { + // unlikely to fail + p, _ := exec.LookPath("echo") + return p +} + func TestCmdFan_NewFan(t *testing.T) { // GIVEN config := configuration.FanConfig{ @@ -132,7 +139,7 @@ func TestCmdFan_GetRpm(t *testing.T) { config := configuration.FanConfig{ Cmd: &configuration.CmdFanConfig{ GetRpm: &configuration.ExecConfig{ - Exec: "/usr/bin/echo", + Exec: getEchoPath(), Args: []string{"1000"}, }, }, @@ -171,7 +178,7 @@ func TestCmdFan_GetRpm_ParseError(t *testing.T) { config := configuration.FanConfig{ Cmd: &configuration.CmdFanConfig{ GetRpm: &configuration.ExecConfig{ - Exec: "/usr/bin/echo", + Exec: getEchoPath(), Args: []string{"not_a_number"}, }, }, @@ -226,7 +233,7 @@ func TestCmdFan_GetRpmAvg(t *testing.T) { config := configuration.FanConfig{ Cmd: &configuration.CmdFanConfig{ GetRpm: &configuration.ExecConfig{ - Exec: "/usr/bin/echo", + Exec: getEchoPath(), Args: []string{"1000"}, }, }, @@ -262,7 +269,7 @@ func TestCmdFan_GetPwm(t *testing.T) { config := configuration.FanConfig{ Cmd: &configuration.CmdFanConfig{ GetPwm: &configuration.ExecConfig{ - Exec: "/usr/bin/echo", + Exec: getEchoPath(), Args: []string{"255"}, }, }, @@ -282,7 +289,7 @@ func TestCmdFan_SetPwm(t *testing.T) { config := configuration.FanConfig{ Cmd: &configuration.CmdFanConfig{ SetPwm: &configuration.ExecConfig{ - Exec: "/usr/bin/echo", + Exec: getEchoPath(), Args: []string{"%pwm%"}, }, }, @@ -476,7 +483,7 @@ func TestCmdFan_Supports_RpmSensor_True(t *testing.T) { config := configuration.FanConfig{ Cmd: &configuration.CmdFanConfig{ GetRpm: &configuration.ExecConfig{ - Exec: "/usr/bin/echo", + Exec: getEchoPath(), Args: []string{"1000"}, }, },