packer-cn/builder/oracle/oci/driver_mock.go

97 lines
2.2 KiB
Go
Raw Normal View History

package oci
2018-06-26 05:05:56 -04:00
import (
"context"
"github.com/oracle/oci-go-sdk/core"
)
// driverMock implements the Driver interface and communicates with Oracle
// OCI.
type driverMock struct {
CreateInstanceID string
CreateInstanceErr error
CreateImageID string
CreateImageErr error
DeleteImageID string
DeleteImageErr error
GetInstanceIPErr error
TerminateInstanceID string
TerminateInstanceErr error
WaitForImageCreationErr error
WaitForInstanceStateErr error
cfg *Config
}
// CreateInstance creates a new compute instance.
2018-06-26 05:05:56 -04:00
func (d *driverMock) CreateInstance(ctx context.Context, publicKey string) (string, error) {
if d.CreateInstanceErr != nil {
return "", d.CreateInstanceErr
}
d.CreateInstanceID = "ocid1..."
return d.CreateInstanceID, nil
}
// CreateImage creates a new custom image.
2018-06-26 05:05:56 -04:00
func (d *driverMock) CreateImage(ctx context.Context, id string) (core.Image, error) {
if d.CreateImageErr != nil {
2018-04-11 05:20:40 -04:00
return core.Image{}, d.CreateImageErr
}
d.CreateImageID = id
2018-04-11 05:20:40 -04:00
return core.Image{Id: &id}, nil
}
// DeleteImage mocks deleting a custom image.
2018-06-26 05:05:56 -04:00
func (d *driverMock) DeleteImage(ctx context.Context, id string) error {
if d.DeleteImageErr != nil {
return d.DeleteImageErr
}
d.DeleteImageID = id
return nil
}
// GetInstanceIP returns the public or private IP corresponding to the given instance id.
2018-06-26 05:05:56 -04:00
func (d *driverMock) GetInstanceIP(ctx context.Context, id string) (string, error) {
if d.GetInstanceIPErr != nil {
return "", d.GetInstanceIPErr
}
if d.cfg.UsePrivateIP {
return "private_ip", nil
}
return "ip", nil
}
// TerminateInstance terminates a compute instance.
2018-06-26 05:05:56 -04:00
func (d *driverMock) TerminateInstance(ctx context.Context, id string) error {
if d.TerminateInstanceErr != nil {
return d.TerminateInstanceErr
}
d.TerminateInstanceID = id
return nil
}
// WaitForImageCreation waits for a provisioning custom image to reach the
// "AVAILABLE" state.
2018-06-26 05:05:56 -04:00
func (d *driverMock) WaitForImageCreation(ctx context.Context, id string) error {
return d.WaitForImageCreationErr
}
// WaitForInstanceState waits for an instance to reach the a given terminal
// state.
2018-06-26 05:05:56 -04:00
func (d *driverMock) WaitForInstanceState(ctx context.Context, id string, waitStates []string, terminalState string) error {
return d.WaitForInstanceStateErr
}