Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/implementation/commandrunner/lsblk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/implementation/commandrunner/lsblk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestMockLSBLKRun(t *testing.T) {

commandrunner.LSBLKExecCommand = mockedExecCommand

runner := commandrunner.NewLSBLK()
runner := commandrunner.NewLSBLK(nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not giving a path as arg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I don't need to, I want to test the default behavior, so not providing a path is the way IMO


// Run the function
output, err := runner.Run([]string{"mocked lsblk command"})
Expand Down
9 changes: 7 additions & 2 deletions pkg/implementation/commandrunner/mdadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/implementation/commandrunner/mdadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestMockMDADMRun(t *testing.T) {

commandrunner.MDADMExecCommand = mockedExecCommand

runner := commandrunner.NewMDADM()
runner := commandrunner.NewMDADM(nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


// Run the function & assert the results
output, err := runner.Run([]string{"mocked mdadm command"})
Expand Down
9 changes: 7 additions & 2 deletions pkg/implementation/commandrunner/smartctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/implementation/commandrunner/smartctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestMockSmartCTLRun(t *testing.T) {

commandrunner.SmartCTLExecCommand = mockedExecCommand

runner := commandrunner.NewSmartCTL()
runner := commandrunner.NewSmartCTL(nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


// Run the function
output, err := runner.Run([]string{"mocked smartctl command"})
Expand Down
9 changes: 7 additions & 2 deletions pkg/implementation/commandrunner/ssacli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/implementation/commandrunner/ssacli_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
9 changes: 7 additions & 2 deletions pkg/implementation/commandrunner/udevadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/implementation/commandrunner/udevadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestMockUDevADMRun(t *testing.T) {

commandrunner.UDevADMExecCommand = mockedExecCommand

runner := commandrunner.NewUDevADM()
runner := commandrunner.NewUDevADM(nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


// Run the function
output, err := runner.Run([]string{"mocked udevadm command"})
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down