awsmock

package
v0.37.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 4 Imported by: 0

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

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 New

func New(opts ...Option) *Finder

New creates a mock Finder with the given options.

func (*Finder) GetAllRegions

func (m *Finder) GetAllRegions(_ context.Context) ([]string, error)

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 (m *Finder) GetEnabledRegions(_ context.Context) ([]string, error)

func (*Finder) GetInstanceTypes

func (m *Finder) GetInstanceTypes(_ context.Context, region string) ([]string, error)

func (*Finder) GetSpotPricing

func (m *Finder) GetSpotPricing(_ context.Context, _ []aws.InstanceTypeResult, _ aws.SpotOptions) ([]aws.SpotPriceResult, error)

func (*Finder) HourlyRate

func (m *Finder) HourlyRate(ctx context.Context, instanceType, region, model string) (float64, error)

func (*Finder) OnDemandPrice

func (m *Finder) OnDemandPrice(_ context.Context, instanceType, region string) (float64, error)

func (*Finder) SearchInstanceTypes

func (m *Finder) SearchInstanceTypes(_ context.Context, regions []string, matcher *regexp.Regexp, opts aws.FilterOptions) ([]aws.InstanceTypeResult, error)

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 WithError

func WithError(err error) Option

WithError injects an error into all methods.

func WithInstances

func WithInstances(instances []aws.InstanceTypeResult) Option

WithInstances sets the instance results returned by SearchInstanceTypes.

func WithOnDemandPrices

func WithOnDemandPrices(prices map[string]float64) Option

WithOnDemandPrices sets per-type/region prices. Keys are "instanceType/region".

func WithRegions

func WithRegions(regions []string) Option

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL