2013-12-21 19:04:41 -05:00
|
|
|
package common
|
|
|
|
|
2013-12-22 12:47:44 -05:00
|
|
|
import "sync"
|
|
|
|
|
2013-12-21 19:04:41 -05:00
|
|
|
type DriverMock struct {
|
2013-12-22 12:47:44 -05:00
|
|
|
sync.Mutex
|
|
|
|
|
2013-12-21 19:04:41 -05:00
|
|
|
CreateSATAControllerVM string
|
|
|
|
CreateSATAControllerController string
|
|
|
|
CreateSATAControllerErr error
|
|
|
|
|
2015-01-16 11:34:12 -05:00
|
|
|
CreateSCSIControllerVM string
|
2015-01-15 20:53:01 -05:00
|
|
|
CreateSCSIControllerController string
|
|
|
|
CreateSCSIControllerErr error
|
|
|
|
|
2013-12-22 18:19:19 -05:00
|
|
|
DeleteCalled bool
|
|
|
|
DeleteName string
|
|
|
|
DeleteErr error
|
|
|
|
|
|
|
|
ImportCalled bool
|
|
|
|
ImportName string
|
|
|
|
ImportPath string
|
2014-09-05 13:23:37 -04:00
|
|
|
ImportFlags []string
|
2013-12-22 18:19:19 -05:00
|
|
|
ImportErr error
|
|
|
|
|
2014-05-06 18:37:49 -04:00
|
|
|
IsoCalled bool
|
|
|
|
IsoErr error
|
|
|
|
|
2013-12-21 19:04:41 -05:00
|
|
|
IsRunningName string
|
|
|
|
IsRunningReturn bool
|
|
|
|
IsRunningErr error
|
|
|
|
|
|
|
|
StopName string
|
|
|
|
StopErr error
|
|
|
|
|
|
|
|
SuppressMessagesCalled bool
|
|
|
|
SuppressMessagesErr error
|
|
|
|
|
2013-12-22 11:10:11 -05:00
|
|
|
VBoxManageCalls [][]string
|
|
|
|
VBoxManageErrs []error
|
2013-12-21 19:04:41 -05:00
|
|
|
|
|
|
|
VerifyCalled bool
|
|
|
|
VerifyErr error
|
|
|
|
|
|
|
|
VersionCalled bool
|
|
|
|
VersionResult string
|
|
|
|
VersionErr error
|
2019-06-26 10:06:37 -04:00
|
|
|
|
2019-06-26 11:22:13 -04:00
|
|
|
LoadSnapshotsCalled []string
|
|
|
|
LoadSnapshotsResult *VBoxSnapshot
|
|
|
|
CreateSnapshotCalled []string
|
|
|
|
CreateSnapshotError error
|
|
|
|
HasSnapshotsCalled []string
|
|
|
|
HasSnapshotsResult bool
|
2019-06-26 10:06:37 -04:00
|
|
|
GetCurrentSnapshotCalled []string
|
|
|
|
GetCurrentSnapshotResult *VBoxSnapshot
|
2019-06-26 11:22:13 -04:00
|
|
|
SetSnapshotCalled []*VBoxSnapshot
|
|
|
|
DeleteSnapshotCalled []*VBoxSnapshot
|
2013-12-21 19:04:41 -05:00
|
|
|
}
|
|
|
|
|
2017-03-22 21:11:19 -04:00
|
|
|
func (d *DriverMock) CreateSATAController(vm string, controller string, portcount int) error {
|
2013-12-21 19:04:41 -05:00
|
|
|
d.CreateSATAControllerVM = vm
|
|
|
|
d.CreateSATAControllerController = vm
|
|
|
|
return d.CreateSATAControllerErr
|
|
|
|
}
|
|
|
|
|
2015-01-15 20:53:01 -05:00
|
|
|
func (d *DriverMock) CreateSCSIController(vm string, controller string) error {
|
2015-01-16 11:34:12 -05:00
|
|
|
d.CreateSCSIControllerVM = vm
|
|
|
|
d.CreateSCSIControllerController = vm
|
|
|
|
return d.CreateSCSIControllerErr
|
2015-01-15 20:53:01 -05:00
|
|
|
}
|
|
|
|
|
2013-12-22 18:19:19 -05:00
|
|
|
func (d *DriverMock) Delete(name string) error {
|
|
|
|
d.DeleteCalled = true
|
|
|
|
d.DeleteName = name
|
|
|
|
return d.DeleteErr
|
|
|
|
}
|
|
|
|
|
2014-09-05 13:23:37 -04:00
|
|
|
func (d *DriverMock) Import(name string, path string, flags []string) error {
|
2013-12-22 18:19:19 -05:00
|
|
|
d.ImportCalled = true
|
|
|
|
d.ImportName = name
|
|
|
|
d.ImportPath = path
|
2014-09-05 13:23:37 -04:00
|
|
|
d.ImportFlags = flags
|
2013-12-22 18:19:19 -05:00
|
|
|
return d.ImportErr
|
|
|
|
}
|
|
|
|
|
2014-05-06 18:37:49 -04:00
|
|
|
func (d *DriverMock) Iso() (string, error) {
|
|
|
|
d.IsoCalled = true
|
|
|
|
return "", d.IsoErr
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:04:41 -05:00
|
|
|
func (d *DriverMock) IsRunning(name string) (bool, error) {
|
2013-12-22 12:47:44 -05:00
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
|
2013-12-21 19:04:41 -05:00
|
|
|
d.IsRunningName = name
|
|
|
|
return d.IsRunningReturn, d.IsRunningErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) Stop(name string) error {
|
|
|
|
d.StopName = name
|
|
|
|
return d.StopErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) SuppressMessages() error {
|
|
|
|
d.SuppressMessagesCalled = true
|
|
|
|
return d.SuppressMessagesErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) VBoxManage(args ...string) error {
|
2013-12-22 11:10:11 -05:00
|
|
|
d.VBoxManageCalls = append(d.VBoxManageCalls, args)
|
|
|
|
|
|
|
|
if len(d.VBoxManageErrs) >= len(d.VBoxManageCalls) {
|
|
|
|
return d.VBoxManageErrs[len(d.VBoxManageCalls)-1]
|
|
|
|
}
|
|
|
|
return nil
|
2013-12-21 19:04:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) Verify() error {
|
|
|
|
d.VerifyCalled = true
|
|
|
|
return d.VerifyErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) Version() (string, error) {
|
|
|
|
d.VersionCalled = true
|
|
|
|
return d.VersionResult, d.VersionErr
|
|
|
|
}
|
2019-06-26 10:06:37 -04:00
|
|
|
|
2019-06-26 10:26:10 -04:00
|
|
|
func (d *DriverMock) LoadSnapshots(vmName string) (*VBoxSnapshot, error) {
|
2019-06-26 10:06:37 -04:00
|
|
|
if vmName == "" {
|
|
|
|
panic("Argument empty exception: vmName")
|
|
|
|
}
|
|
|
|
|
|
|
|
d.LoadSnapshotsCalled = append(d.LoadSnapshotsCalled, vmName)
|
|
|
|
return d.LoadSnapshotsResult, nil
|
|
|
|
}
|
|
|
|
|
2019-06-26 10:26:10 -04:00
|
|
|
func (d *DriverMock) CreateSnapshot(vmName string, snapshotName string) error {
|
2019-06-26 10:06:37 -04:00
|
|
|
if vmName == "" {
|
|
|
|
panic("Argument empty exception: vmName")
|
|
|
|
}
|
|
|
|
if snapshotName == "" {
|
|
|
|
panic("Argument empty exception: snapshotName")
|
|
|
|
}
|
|
|
|
|
|
|
|
d.CreateSnapshotCalled = append(d.CreateSnapshotCalled, snapshotName)
|
|
|
|
return d.CreateSnapshotError
|
|
|
|
}
|
|
|
|
|
2019-06-26 10:26:10 -04:00
|
|
|
func (d *DriverMock) HasSnapshots(vmName string) (bool, error) {
|
2019-06-26 10:06:37 -04:00
|
|
|
if vmName == "" {
|
|
|
|
panic("Argument empty exception: vmName")
|
|
|
|
}
|
|
|
|
|
|
|
|
d.HasSnapshotsCalled = append(d.HasSnapshotsCalled, vmName)
|
|
|
|
return d.HasSnapshotsResult, nil
|
|
|
|
}
|
|
|
|
|
2019-06-26 10:26:10 -04:00
|
|
|
func (d *DriverMock) GetCurrentSnapshot(vmName string) (*VBoxSnapshot, error) {
|
2019-06-26 10:06:37 -04:00
|
|
|
if vmName == "" {
|
|
|
|
panic("Argument empty exception: vmName")
|
|
|
|
}
|
|
|
|
|
|
|
|
d.GetCurrentSnapshotCalled = append(d.GetCurrentSnapshotCalled, vmName)
|
|
|
|
return d.GetCurrentSnapshotResult, nil
|
|
|
|
}
|
|
|
|
|
2019-06-26 10:26:10 -04:00
|
|
|
func (d *DriverMock) SetSnapshot(vmName string, snapshot *VBoxSnapshot) error {
|
2019-06-26 10:06:37 -04:00
|
|
|
if vmName == "" {
|
|
|
|
panic("Argument empty exception: vmName")
|
|
|
|
}
|
|
|
|
if snapshot == nil {
|
|
|
|
panic("Argument empty exception: snapshot")
|
|
|
|
}
|
|
|
|
|
|
|
|
d.SetSnapshotCalled = append(d.SetSnapshotCalled, snapshot)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-26 10:26:10 -04:00
|
|
|
func (d *DriverMock) DeleteSnapshot(vmName string, snapshot *VBoxSnapshot) error {
|
2019-06-26 10:06:37 -04:00
|
|
|
if vmName == "" {
|
|
|
|
panic("Argument empty exception: vmName")
|
|
|
|
}
|
|
|
|
if snapshot == nil {
|
|
|
|
panic("Argument empty exception: snapshot")
|
|
|
|
}
|
|
|
|
d.DeleteSnapshotCalled = append(d.DeleteSnapshotCalled, snapshot)
|
|
|
|
return nil
|
2019-06-26 10:11:11 -04:00
|
|
|
}
|