Skip to content

Commit

Permalink
added getNVMeController mock
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhatdell committed Oct 25, 2024
1 parent f695470 commit d2a1d29
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions gofsutil_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ var (
GOFSRescanCallback func(scan string)
// GOFSMockMountInfo contains mount information for filesystem volumes
GOFSMockMountInfo *DeviceMountInfo
// GONVMEControllerDevice is the name of the NVM Express device
GONVMEControllerDevice string
// GONVMEDeviceToControllerMap has device to controller mapping
GONVMEDeviceToControllerMap map[string]string
// GONVMEValidDevices mocks existing devices
GONVMEValidDevices map[string]bool

// GOFSMock allows you to induce errors in the various routine.
GOFSMock struct {
Expand All @@ -68,7 +70,7 @@ var (
InduceResizeFSError bool
InduceGetMpathNameFromDeviceError bool
InduceFilesystemInfoError bool
InduceNVMEDeviceError bool
InduceGetNVMeControllerError bool
}
)

Expand Down Expand Up @@ -554,9 +556,14 @@ func (fs *mockfs) GetNVMeController(device string) (string, error) {
}

func (fs *mockfs) getNVMeController(device string) (string, error) {
nvmeControllerDevice := GONVMEControllerDevice
if GOFSMock.InduceNVMEDeviceError {
if GOFSMock.InduceGetNVMeControllerError {
return "", errors.New("induced error")
}
return nvmeControllerDevice, nil
if _, exists := GONVMEValidDevices[device]; !exists {
return "", fmt.Errorf("device %s does not exist", device)
}
if controller, found := GONVMEDeviceToControllerMap[device]; found {
return controller, nil
}
return "", fmt.Errorf("controller not found for device %s", device)
}

0 comments on commit d2a1d29

Please sign in to comment.