Skip to content

Commit

Permalink
cmd_test: find echo from PATH instead of using a hardcoded path
Browse files Browse the repository at this point in the history
Closes: #320
  • Loading branch information
stkw0 committed Oct 8, 2024
1 parent fe56dd3 commit 66d4ad1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions internal/fans/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"},
},
},
Expand Down Expand Up @@ -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"},
},
},
Expand Down Expand Up @@ -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"},
},
},
Expand Down Expand Up @@ -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"},
},
},
Expand All @@ -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%"},
},
},
Expand Down Expand Up @@ -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"},
},
},
Expand Down

0 comments on commit 66d4ad1

Please sign in to comment.