Documentation
¶
Overview ¶
Package awsmock provides a configurable mock implementation of aws.Finder for unit testing downstream consumers of truffle's instance discovery API.
Basic usage:
m := awsmock.New(
awsmock.WithInstances([]aws.InstanceTypeResult{
{InstanceType: "m7i.large", Region: "us-east-1", VCPUs: 2, MemoryMiB: 8192},
}),
awsmock.WithRegions([]string{"us-east-1", "us-west-2"}),
awsmock.WithOnDemandPrices(map[string]float64{"m7i.large/us-east-1": 0.1008}),
)
// Use m anywhere an aws.Finder is accepted.
Index ¶
- type Finder
- func (m *Finder) GetAllRegions(_ context.Context) ([]string, error)
- func (m *Finder) GetCapacityBlocks(_ context.Context, _ []string, _ aws.CapacityBlockOptions) ([]aws.CapacityBlockResult, error)
- func (m *Finder) GetCapacityReservations(_ context.Context, _ []string, _ aws.CapacityReservationOptions) ([]aws.CapacityReservationResult, error)
- func (m *Finder) GetEnabledRegions(_ context.Context) ([]string, error)
- func (m *Finder) GetInstanceTypes(_ context.Context, region string) ([]string, error)
- func (m *Finder) GetSpotPricing(_ context.Context, _ []aws.InstanceTypeResult, _ aws.SpotOptions) ([]aws.SpotPriceResult, error)
- func (m *Finder) HourlyRate(ctx context.Context, instanceType, region, model string) (float64, error)
- func (m *Finder) OnDemandPrice(_ context.Context, instanceType, region string) (float64, error)
- func (m *Finder) SearchInstanceTypes(_ context.Context, regions []string, matcher *regexp.Regexp, ...) ([]aws.InstanceTypeResult, error)
- type Option
- func WithBlocks(blocks []aws.CapacityBlockResult) Option
- func WithError(err error) Option
- func WithInstances(instances []aws.InstanceTypeResult) Option
- func WithOnDemandPrices(prices map[string]float64) Option
- func WithRegions(regions []string) Option
- func WithReservations(reservations []aws.CapacityReservationResult) Option
- func WithSpotPrices(prices []aws.SpotPriceResult) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Finder ¶
type Finder struct {
Regions []string
Instances []aws.InstanceTypeResult
SpotPrices []aws.SpotPriceResult
Reservations []aws.CapacityReservationResult
Blocks []aws.CapacityBlockResult
OnDemandMap map[string]float64 // key: "instanceType/region"
InstanceTypes map[string][]string // key: region
// Error injection: if non-nil, the corresponding method returns this error.
SearchErr error
SpotErr error
RegionsErr error
ReservationErr error
BlocksErr error
PriceErr error
}
Finder is a mock implementation of aws.Finder. Configure it with New and option functions, or set fields directly for simple cases.
func (*Finder) GetCapacityBlocks ¶
func (m *Finder) GetCapacityBlocks(_ context.Context, _ []string, _ aws.CapacityBlockOptions) ([]aws.CapacityBlockResult, error)
func (*Finder) GetCapacityReservations ¶
func (m *Finder) GetCapacityReservations(_ context.Context, _ []string, _ aws.CapacityReservationOptions) ([]aws.CapacityReservationResult, error)
func (*Finder) GetEnabledRegions ¶
func (*Finder) GetInstanceTypes ¶
func (*Finder) GetSpotPricing ¶
func (m *Finder) GetSpotPricing(_ context.Context, _ []aws.InstanceTypeResult, _ aws.SpotOptions) ([]aws.SpotPriceResult, error)
func (*Finder) HourlyRate ¶
func (*Finder) OnDemandPrice ¶
func (*Finder) SearchInstanceTypes ¶
type Option ¶
type Option func(*Finder)
Option configures a Finder.
func WithBlocks ¶
func WithBlocks(blocks []aws.CapacityBlockResult) Option
WithBlocks sets the Capacity Blocks returned by GetCapacityBlocks.
func WithInstances ¶
func WithInstances(instances []aws.InstanceTypeResult) Option
WithInstances sets the instance results returned by SearchInstanceTypes.
func WithOnDemandPrices ¶
WithOnDemandPrices sets per-type/region prices. Keys are "instanceType/region".
func WithRegions ¶
WithRegions sets the regions returned by GetEnabledRegions and GetAllRegions.
func WithReservations ¶
func WithReservations(reservations []aws.CapacityReservationResult) Option
WithReservations sets the ODCRs returned by GetCapacityReservations.
func WithSpotPrices ¶
func WithSpotPrices(prices []aws.SpotPriceResult) Option
WithSpotPrices sets the results returned by GetSpotPricing.