2013-12-13 00:38:34 -05:00
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
// DriverMock is a Driver implementation that is a mocked out so that
|
|
|
|
// it can be used for tests.
|
|
|
|
type DriverMock struct {
|
2014-12-09 11:42:33 -05:00
|
|
|
ImageExistsName string
|
|
|
|
ImageExistsResult bool
|
|
|
|
|
2013-12-13 22:03:10 -05:00
|
|
|
CreateImageName string
|
|
|
|
CreateImageDesc string
|
2014-11-24 11:36:14 -05:00
|
|
|
CreateImageZone string
|
|
|
|
CreateImageDisk string
|
2013-12-13 22:03:10 -05:00
|
|
|
CreateImageErrCh <-chan error
|
|
|
|
|
2013-12-13 22:07:10 -05:00
|
|
|
DeleteImageName string
|
|
|
|
DeleteImageErrCh <-chan error
|
|
|
|
|
2013-12-13 01:34:47 -05:00
|
|
|
DeleteInstanceZone string
|
|
|
|
DeleteInstanceName string
|
|
|
|
DeleteInstanceErrCh <-chan error
|
|
|
|
DeleteInstanceErr error
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
DeleteDiskZone string
|
|
|
|
DeleteDiskName string
|
|
|
|
DeleteDiskErrCh <-chan error
|
|
|
|
DeleteDiskErr error
|
|
|
|
|
2013-12-13 16:01:28 -05:00
|
|
|
GetNatIPZone string
|
|
|
|
GetNatIPName string
|
|
|
|
GetNatIPResult string
|
|
|
|
GetNatIPErr error
|
|
|
|
|
2013-12-13 00:38:34 -05:00
|
|
|
RunInstanceConfig *InstanceConfig
|
|
|
|
RunInstanceErrCh <-chan error
|
|
|
|
RunInstanceErr error
|
2013-12-13 16:01:28 -05:00
|
|
|
|
|
|
|
WaitForInstanceState string
|
|
|
|
WaitForInstanceZone string
|
|
|
|
WaitForInstanceName string
|
|
|
|
WaitForInstanceErrCh <-chan error
|
2013-12-13 00:38:34 -05:00
|
|
|
}
|
|
|
|
|
2014-12-09 11:42:33 -05:00
|
|
|
func (d *DriverMock) ImageExists(name string) bool {
|
|
|
|
d.ImageExistsName = name
|
|
|
|
return d.ImageExistsResult
|
|
|
|
}
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
func (d *DriverMock) CreateImage(name, description, zone, disk string) <-chan error {
|
2013-12-13 22:03:10 -05:00
|
|
|
d.CreateImageName = name
|
|
|
|
d.CreateImageDesc = description
|
2014-11-24 11:36:14 -05:00
|
|
|
d.CreateImageZone = zone
|
|
|
|
d.CreateImageDisk = disk
|
2013-12-13 22:03:10 -05:00
|
|
|
|
|
|
|
resultCh := d.CreateImageErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
2013-12-13 22:07:10 -05:00
|
|
|
return resultCh
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DriverMock) DeleteImage(name string) <-chan error {
|
|
|
|
d.DeleteImageName = name
|
|
|
|
|
|
|
|
resultCh := d.DeleteImageErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
2013-12-13 22:03:10 -05:00
|
|
|
return resultCh
|
|
|
|
}
|
|
|
|
|
2013-12-13 01:34:47 -05:00
|
|
|
func (d *DriverMock) DeleteInstance(zone, name string) (<-chan error, error) {
|
|
|
|
d.DeleteInstanceZone = zone
|
|
|
|
d.DeleteInstanceName = name
|
|
|
|
|
|
|
|
resultCh := d.DeleteInstanceErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh, d.DeleteInstanceErr
|
|
|
|
}
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
func (d *DriverMock) DeleteDisk(zone, name string) (<-chan error, error) {
|
|
|
|
d.DeleteDiskZone = zone
|
|
|
|
d.DeleteDiskName = name
|
|
|
|
|
|
|
|
resultCh := d.DeleteDiskErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh, d.DeleteDiskErr
|
|
|
|
}
|
|
|
|
|
2013-12-13 16:01:28 -05:00
|
|
|
func (d *DriverMock) GetNatIP(zone, name string) (string, error) {
|
|
|
|
d.GetNatIPZone = zone
|
|
|
|
d.GetNatIPName = name
|
|
|
|
return d.GetNatIPResult, d.GetNatIPErr
|
|
|
|
}
|
|
|
|
|
2013-12-13 00:38:34 -05:00
|
|
|
func (d *DriverMock) RunInstance(c *InstanceConfig) (<-chan error, error) {
|
|
|
|
d.RunInstanceConfig = c
|
|
|
|
|
|
|
|
resultCh := d.RunInstanceErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh, d.RunInstanceErr
|
|
|
|
}
|
2013-12-13 16:01:28 -05:00
|
|
|
|
|
|
|
func (d *DriverMock) WaitForInstance(state, zone, name string) <-chan error {
|
|
|
|
d.WaitForInstanceState = state
|
|
|
|
d.WaitForInstanceZone = zone
|
|
|
|
d.WaitForInstanceName = name
|
|
|
|
|
|
|
|
resultCh := d.WaitForInstanceErrCh
|
|
|
|
if resultCh == nil {
|
|
|
|
ch := make(chan error)
|
|
|
|
close(ch)
|
|
|
|
resultCh = ch
|
|
|
|
}
|
|
|
|
|
|
|
|
return resultCh
|
|
|
|
}
|