diff --git a/pkg/implementation/commandrunner/lsblk.go b/pkg/implementation/commandrunner/lsblk.go index 9d9bc9b..c0b6623 100644 --- a/pkg/implementation/commandrunner/lsblk.go +++ b/pkg/implementation/commandrunner/lsblk.go @@ -18,9 +18,14 @@ var ( LSBLKExecCommand = exec.Command ) -func NewLSBLK() *LSBLK { +func NewLSBLK(path *string) *LSBLK { + cliPath := LSBLKBinaryPath + if path != nil && *path != "" { + cliPath = *path + } + return &LSBLK{ - cliPath: LSBLKBinaryPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/lsblk_test.go b/pkg/implementation/commandrunner/lsblk_test.go index af11da6..edbad5c 100644 --- a/pkg/implementation/commandrunner/lsblk_test.go +++ b/pkg/implementation/commandrunner/lsblk_test.go @@ -15,7 +15,7 @@ func TestMockLSBLKRun(t *testing.T) { commandrunner.LSBLKExecCommand = mockedExecCommand - runner := commandrunner.NewLSBLK() + runner := commandrunner.NewLSBLK(nil) // Run the function output, err := runner.Run([]string{"mocked lsblk command"}) diff --git a/pkg/implementation/commandrunner/mdadm.go b/pkg/implementation/commandrunner/mdadm.go index caf97a4..6290ed6 100644 --- a/pkg/implementation/commandrunner/mdadm.go +++ b/pkg/implementation/commandrunner/mdadm.go @@ -18,9 +18,14 @@ var ( MDADMExecCommand = exec.Command ) -func NewMDADM() *MDADM { +func NewMDADM(path *string) *MDADM { + cliPath := MDADMBinaryPath + if path != nil && *path != "" { + cliPath = *path + } + return &MDADM{ - cliPath: MDADMBinaryPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/mdadm_test.go b/pkg/implementation/commandrunner/mdadm_test.go index fce7a0b..4e451e3 100644 --- a/pkg/implementation/commandrunner/mdadm_test.go +++ b/pkg/implementation/commandrunner/mdadm_test.go @@ -15,7 +15,7 @@ func TestMockMDADMRun(t *testing.T) { commandrunner.MDADMExecCommand = mockedExecCommand - runner := commandrunner.NewMDADM() + runner := commandrunner.NewMDADM(nil) // Run the function & assert the results output, err := runner.Run([]string{"mocked mdadm command"}) diff --git a/pkg/implementation/commandrunner/smartctl.go b/pkg/implementation/commandrunner/smartctl.go index a922709..494288c 100644 --- a/pkg/implementation/commandrunner/smartctl.go +++ b/pkg/implementation/commandrunner/smartctl.go @@ -19,9 +19,14 @@ var ( SmartCTLExecCommand = exec.Command ) -func NewSmartCTL() *SmartCTL { +func NewSmartCTL(path *string) *SmartCTL { + cliPath := SmartCTLBinaryPath + if path != nil && *path != "" { + cliPath = *path + } + return &SmartCTL{ - cliPath: SmartCTLBinaryPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/smartctl_test.go b/pkg/implementation/commandrunner/smartctl_test.go index 2c12c23..a23ab7a 100644 --- a/pkg/implementation/commandrunner/smartctl_test.go +++ b/pkg/implementation/commandrunner/smartctl_test.go @@ -15,7 +15,7 @@ func TestMockSmartCTLRun(t *testing.T) { commandrunner.SmartCTLExecCommand = mockedExecCommand - runner := commandrunner.NewSmartCTL() + runner := commandrunner.NewSmartCTL(nil) // Run the function output, err := runner.Run([]string{"mocked smartctl command"}) diff --git a/pkg/implementation/commandrunner/ssacli.go b/pkg/implementation/commandrunner/ssacli.go index 2be828f..89dcab2 100644 --- a/pkg/implementation/commandrunner/ssacli.go +++ b/pkg/implementation/commandrunner/ssacli.go @@ -19,9 +19,14 @@ var ( SSACLIExecCommand = exec.Command ) -func NewSSACLI() *SSACLI { +func NewSSACLI(path *string) *SSACLI { + cliPath := SSACLIPath + if path != nil && *path != "" { + cliPath = *path + } + return &SSACLI{ - cliPath: SSACLIPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/ssacli_test.go b/pkg/implementation/commandrunner/ssacli_test.go new file mode 100644 index 0000000..278cec2 --- /dev/null +++ b/pkg/implementation/commandrunner/ssacli_test.go @@ -0,0 +1,22 @@ +package commandrunner_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/scality/raidmgmt/pkg/implementation/commandrunner" +) + +func TestMockSSACLIRun(t *testing.T) { + originalCommand := commandrunner.SSACLIExecCommand + defer func() { commandrunner.SSACLIExecCommand = originalCommand }() + + commandrunner.SSACLIExecCommand = mockedExecCommand + + runner := commandrunner.NewSSACLI(nil) + + output, err := runner.Run([]string{"mocked ssacli command"}) + assert.NoError(t, err) + assert.Contains(t, string(output), "PASS") +} diff --git a/pkg/implementation/commandrunner/udevadm.go b/pkg/implementation/commandrunner/udevadm.go index 83e6e4f..4273ab3 100644 --- a/pkg/implementation/commandrunner/udevadm.go +++ b/pkg/implementation/commandrunner/udevadm.go @@ -20,9 +20,14 @@ var ( UDevADMExecCommand = exec.Command ) -func NewUDevADM() *UDevADM { +func NewUDevADM(path *string) *UDevADM { + cliPath := UDevADMBinaryPath + if path != nil && *path != "" { + cliPath = *path + } + return &UDevADM{ - cliPath: UDevADMBinaryPath, + cliPath: cliPath, } } diff --git a/pkg/implementation/commandrunner/udevadm_test.go b/pkg/implementation/commandrunner/udevadm_test.go index dcacca7..0f26837 100644 --- a/pkg/implementation/commandrunner/udevadm_test.go +++ b/pkg/implementation/commandrunner/udevadm_test.go @@ -15,7 +15,7 @@ func TestMockUDevADMRun(t *testing.T) { commandrunner.UDevADMExecCommand = mockedExecCommand - runner := commandrunner.NewUDevADM() + runner := commandrunner.NewUDevADM(nil) // Run the function output, err := runner.Run([]string{"mocked udevadm command"}) diff --git a/tests/integration/main.go b/tests/integration/main.go index 4e46e07..e61404c 100644 --- a/tests/integration/main.go +++ b/tests/integration/main.go @@ -17,10 +17,10 @@ import ( func main() { logger := zerolog.New(os.Stdout).With().Str("test_type", "integration").Logger() - uDevADMCommandRunner := commandrunner.NewUDevADM() - lsblkCommandRunner := commandrunner.NewLSBLK() - smartCTLCommandRunner := commandrunner.NewSmartCTL() - mdadmCommandRunner := commandrunner.NewMDADM() + uDevADMCommandRunner := commandrunner.NewUDevADM(nil) + lsblkCommandRunner := commandrunner.NewLSBLK(nil) + smartCTLCommandRunner := commandrunner.NewSmartCTL(nil) + mdadmCommandRunner := commandrunner.NewMDADM(nil) physicalDriveGetter := physicaldrivegetter.NewRHEL8( uDevADMCommandRunner,