fake

package
v0.36.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRegion  = "us-west-2"
	DefaultAccount = "123456789"
)

Variables

View Source
var DefaultSupportedUsageClasses = aws.StringSlice([]string{"on-demand", "spot"})

DefaultSupportedUsageClasses is a var because []*string can't be a const

Functions

func Filter

func Filter(filters []*ec2.Filter, id, name string, tags []*ec2.Tag) bool

func FilterDescribeImages

func FilterDescribeImages(images []*ec2.Image, filters []*ec2.Filter) []*ec2.Image

func FilterDescribeSecurtyGroups

func FilterDescribeSecurtyGroups(sgs []*ec2.SecurityGroup, filters []*ec2.Filter) []*ec2.SecurityGroup

FilterDescribeSecurtyGroups filters the passed in security groups based on the filters passed in. Filters are chained with a logical "AND"

func FilterDescribeSubnets

func FilterDescribeSubnets(subnets []*ec2.Subnet, filters []*ec2.Filter) []*ec2.Subnet

FilterDescribeSubnets filters the passed in subnets based on the filters passed in. Filters are chained with a logical "AND"

func ImageID

func ImageID() string

func InstanceID

func InstanceID() string

func InstanceProfileID

func InstanceProfileID() string

func LaunchTemplateID

func LaunchTemplateID() string

func LaunchTemplateName

func LaunchTemplateName() string

func MakeInstanceOfferings added in v0.35.0

func MakeInstanceOfferings(instanceTypes []*ec2.InstanceTypeInfo) []*ec2.InstanceTypeOffering

func MakeInstances added in v0.35.0

func MakeInstances() []*ec2.InstanceTypeInfo

func MakeUniqueInstancesAndFamilies added in v0.35.0

func MakeUniqueInstancesAndFamilies(instances []*ec2.InstanceTypeInfo, numInstanceFamilies int) ([]*ec2.InstanceTypeInfo, sets.Set[string])

func NewOnDemandPrice

func NewOnDemandPrice(instanceType string, price float64) aws.JSONValue

func NewOnDemandPriceWithCurrency added in v0.36.0

func NewOnDemandPriceWithCurrency(instanceType string, price float64, currency string) aws.JSONValue

func PrivateDNSName

func PrivateDNSName() string

func ProviderID

func ProviderID(id string) string

func RandomProviderID

func RandomProviderID() string

func RoleID

func RoleID() string

func SecurityGroupID

func SecurityGroupID() string

func SubnetID

func SubnetID() string

func SubnetsFromFleetRequest

func SubnetsFromFleetRequest(createFleetInput *ec2.CreateFleetInput) []string

SubnetsFromFleetRequest returns a unique slice of subnetIDs passed as overrides from a CreateFleetInput

Types

type AtomicError

type AtomicError struct {
	// contains filtered or unexported fields
}

func (*AtomicError) Get

func (e *AtomicError) Get() error

Get is equivalent to the error being called, so we increase number of calls in this function

func (*AtomicError) IsNil

func (e *AtomicError) IsNil() bool

func (*AtomicError) Reset

func (e *AtomicError) Reset()

func (*AtomicError) Set

func (e *AtomicError) Set(err error, opts ...AtomicErrorOption)

type AtomicErrorOption

type AtomicErrorOption func(atomicError *AtomicError)

func MaxCalls

func MaxCalls(maxCalls int) AtomicErrorOption

type AtomicPtr

type AtomicPtr[T any] struct {
	// contains filtered or unexported fields
}

AtomicPtr is intended for use in mocks to easily expose variables for use in testing. It makes setting and retrieving the values race free by wrapping the pointer itself in a mutex. There is no Get() method, but instead a Clone() method deep copies the object being stored by serializing/de-serializing it from JSON. This pattern shouldn't be followed anywhere else but is an easy way to eliminate races in our tests.

func (*AtomicPtr[T]) Clone

func (a *AtomicPtr[T]) Clone() *T

func (*AtomicPtr[T]) IsNil

func (a *AtomicPtr[T]) IsNil() bool

func (*AtomicPtr[T]) Reset

func (a *AtomicPtr[T]) Reset()

func (*AtomicPtr[T]) Set

func (a *AtomicPtr[T]) Set(v *T)

type AtomicPtrSlice

type AtomicPtrSlice[T any] struct {
	// contains filtered or unexported fields
}

AtomicPtrSlice exposes a slice of a pointer type in a race-free manner. The interface is just enough to replace the set.Set usage in our previous tests.

func (*AtomicPtrSlice[T]) Add

func (a *AtomicPtrSlice[T]) Add(input *T)

func (*AtomicPtrSlice[T]) ForEach

func (a *AtomicPtrSlice[T]) ForEach(fn func(*T))

func (*AtomicPtrSlice[T]) Len

func (a *AtomicPtrSlice[T]) Len() int

func (*AtomicPtrSlice[T]) Pop

func (a *AtomicPtrSlice[T]) Pop() *T

func (*AtomicPtrSlice[T]) Reset

func (a *AtomicPtrSlice[T]) Reset()

type CapacityPool

type CapacityPool struct {
	CapacityType string
	InstanceType string
	Zone         string
}

type CloudProvider

type CloudProvider struct {
	InstanceTypes []*corecloudprovider.InstanceType
	ValidAMIs     []string
}

func (*CloudProvider) Create

func (*CloudProvider) Delete

func (*CloudProvider) Get

func (*CloudProvider) GetInstanceTypes

func (*CloudProvider) GetSupportedNodeClasses added in v0.34.7

func (c *CloudProvider) GetSupportedNodeClasses() []schema.GroupVersionKind

func (*CloudProvider) IsDrifted

func (*CloudProvider) List

func (*CloudProvider) Name

func (c *CloudProvider) Name() string

Name returns the CloudProvider implementation name.

type EC2API

type EC2API struct {
	ec2iface.EC2API
	EC2Behavior
}

func NewEC2API

func NewEC2API() *EC2API

func (*EC2API) CreateFleetWithContext

func (e *EC2API) CreateFleetWithContext(_ context.Context, input *ec2.CreateFleetInput, _ ...request.Option) (*ec2.CreateFleetOutput, error)

nolint: gocyclo

func (*EC2API) CreateLaunchTemplateWithContext

func (e *EC2API) CreateLaunchTemplateWithContext(_ context.Context, input *ec2.CreateLaunchTemplateInput, _ ...request.Option) (*ec2.CreateLaunchTemplateOutput, error)

func (*EC2API) CreateTagsWithContext

func (e *EC2API) CreateTagsWithContext(_ context.Context, input *ec2.CreateTagsInput, _ ...request.Option) (*ec2.CreateTagsOutput, error)

func (*EC2API) DeleteLaunchTemplateWithContext

func (e *EC2API) DeleteLaunchTemplateWithContext(_ context.Context, input *ec2.DeleteLaunchTemplateInput, _ ...request.Option) (*ec2.DeleteLaunchTemplateOutput, error)

func (*EC2API) DescribeImagesPagesWithContext

func (e *EC2API) DescribeImagesPagesWithContext(ctx context.Context, input *ec2.DescribeImagesInput, fn func(*ec2.DescribeImagesOutput, bool) bool, _ ...request.Option) error

func (*EC2API) DescribeImagesWithContext

func (e *EC2API) DescribeImagesWithContext(_ context.Context, input *ec2.DescribeImagesInput, _ ...request.Option) (*ec2.DescribeImagesOutput, error)

func (*EC2API) DescribeInstanceTypeOfferingsPagesWithContext

func (e *EC2API) DescribeInstanceTypeOfferingsPagesWithContext(ctx context.Context, input *ec2.DescribeInstanceTypeOfferingsInput, fn func(*ec2.DescribeInstanceTypeOfferingsOutput, bool) bool, _ ...request.Option) error

func (*EC2API) DescribeInstanceTypesPagesWithContext

func (e *EC2API) DescribeInstanceTypesPagesWithContext(ctx context.Context, input *ec2.DescribeInstanceTypesInput, fn func(*ec2.DescribeInstanceTypesOutput, bool) bool, _ ...request.Option) error

func (*EC2API) DescribeInstanceTypesWithContext

func (e *EC2API) DescribeInstanceTypesWithContext(_ context.Context, _ *ec2.DescribeInstanceTypesInput, _ ...request.Option) (*ec2.DescribeInstanceTypesOutput, error)

func (*EC2API) DescribeInstancesPagesWithContext

func (e *EC2API) DescribeInstancesPagesWithContext(ctx context.Context, input *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool, opts ...request.Option) error

func (*EC2API) DescribeInstancesWithContext

func (e *EC2API) DescribeInstancesWithContext(_ context.Context, input *ec2.DescribeInstancesInput, _ ...request.Option) (*ec2.DescribeInstancesOutput, error)

func (*EC2API) DescribeLaunchTemplatesPagesWithContext

func (e *EC2API) DescribeLaunchTemplatesPagesWithContext(ctx context.Context, input *ec2.DescribeLaunchTemplatesInput, fn func(*ec2.DescribeLaunchTemplatesOutput, bool) bool, _ ...request.Option) error

func (*EC2API) DescribeLaunchTemplatesWithContext

func (e *EC2API) DescribeLaunchTemplatesWithContext(_ context.Context, input *ec2.DescribeLaunchTemplatesInput, _ ...request.Option) (*ec2.DescribeLaunchTemplatesOutput, error)

func (*EC2API) DescribeSecurityGroupsWithContext

func (e *EC2API) DescribeSecurityGroupsWithContext(_ context.Context, input *ec2.DescribeSecurityGroupsInput, _ ...request.Option) (*ec2.DescribeSecurityGroupsOutput, error)

func (*EC2API) DescribeSpotPriceHistoryPagesWithContext

func (e *EC2API) DescribeSpotPriceHistoryPagesWithContext(ctx aws.Context, input *ec2.DescribeSpotPriceHistoryInput, fn func(*ec2.DescribeSpotPriceHistoryOutput, bool) bool, _ ...request.Option) error

func (*EC2API) DescribeSpotPriceHistoryWithContext

func (e *EC2API) DescribeSpotPriceHistoryWithContext(_ aws.Context, input *ec2.DescribeSpotPriceHistoryInput, _ ...request.Option) (*ec2.DescribeSpotPriceHistoryOutput, error)

func (*EC2API) DescribeSubnetsWithContext

func (e *EC2API) DescribeSubnetsWithContext(_ context.Context, input *ec2.DescribeSubnetsInput, _ ...request.Option) (*ec2.DescribeSubnetsOutput, error)

func (*EC2API) Reset

func (e *EC2API) Reset()

Reset must be called between tests otherwise tests will pollute each other.

func (*EC2API) TerminateInstancesWithContext

func (e *EC2API) TerminateInstancesWithContext(_ context.Context, input *ec2.TerminateInstancesInput, _ ...request.Option) (*ec2.TerminateInstancesOutput, error)

type EC2Behavior

type EC2Behavior struct {
	DescribeImagesOutput                AtomicPtr[ec2.DescribeImagesOutput]
	DescribeLaunchTemplatesOutput       AtomicPtr[ec2.DescribeLaunchTemplatesOutput]
	DescribeSubnetsOutput               AtomicPtr[ec2.DescribeSubnetsOutput]
	DescribeSecurityGroupsOutput        AtomicPtr[ec2.DescribeSecurityGroupsOutput]
	DescribeInstanceTypesOutput         AtomicPtr[ec2.DescribeInstanceTypesOutput]
	DescribeInstanceTypeOfferingsOutput AtomicPtr[ec2.DescribeInstanceTypeOfferingsOutput]
	DescribeAvailabilityZonesOutput     AtomicPtr[ec2.DescribeAvailabilityZonesOutput]
	DescribeSpotPriceHistoryInput       AtomicPtr[ec2.DescribeSpotPriceHistoryInput]
	DescribeSpotPriceHistoryOutput      AtomicPtr[ec2.DescribeSpotPriceHistoryOutput]
	CreateFleetBehavior                 MockedFunction[ec2.CreateFleetInput, ec2.CreateFleetOutput]
	TerminateInstancesBehavior          MockedFunction[ec2.TerminateInstancesInput, ec2.TerminateInstancesOutput]
	DescribeInstancesBehavior           MockedFunction[ec2.DescribeInstancesInput, ec2.DescribeInstancesOutput]
	CreateTagsBehavior                  MockedFunction[ec2.CreateTagsInput, ec2.CreateTagsOutput]
	CalledWithCreateLaunchTemplateInput AtomicPtrSlice[ec2.CreateLaunchTemplateInput]
	CalledWithDescribeImagesInput       AtomicPtrSlice[ec2.DescribeImagesInput]
	Instances                           sync.Map
	LaunchTemplates                     sync.Map
	InsufficientCapacityPools           atomic.Slice[CapacityPool]
	NextError                           AtomicError
}

EC2Behavior must be reset between tests otherwise tests will pollute each other.

type EKSAPI

type EKSAPI struct {
	eksiface.EKSAPI
	EKSAPIBehavior
}

func NewEKSAPI added in v0.35.0

func NewEKSAPI() *EKSAPI

func (*EKSAPI) DescribeClusterWithContext

func (s *EKSAPI) DescribeClusterWithContext(_ context.Context, input *eks.DescribeClusterInput, _ ...request.Option) (*eks.DescribeClusterOutput, error)

func (*EKSAPI) Reset

func (s *EKSAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

type EKSAPIBehavior

type EKSAPIBehavior struct {
	DescribeClusterBehavior MockedFunction[eks.DescribeClusterInput, eks.DescribeClusterOutput]
}

EKSAPIBehavior must be reset between tests otherwise tests will pollute each other.

type IAMAPI

type IAMAPI struct {
	sync.Mutex

	iamiface.IAMAPI
	IAMAPIBehavior

	InstanceProfiles map[string]*iam.InstanceProfile
}

func NewIAMAPI

func NewIAMAPI() *IAMAPI

func (*IAMAPI) AddRoleToInstanceProfileWithContext

func (s *IAMAPI) AddRoleToInstanceProfileWithContext(_ context.Context, input *iam.AddRoleToInstanceProfileInput, _ ...request.Option) (*iam.AddRoleToInstanceProfileOutput, error)

func (*IAMAPI) CreateInstanceProfileWithContext

func (s *IAMAPI) CreateInstanceProfileWithContext(_ context.Context, input *iam.CreateInstanceProfileInput, _ ...request.Option) (*iam.CreateInstanceProfileOutput, error)

func (*IAMAPI) DeleteInstanceProfileWithContext

func (s *IAMAPI) DeleteInstanceProfileWithContext(_ context.Context, input *iam.DeleteInstanceProfileInput, _ ...request.Option) (*iam.DeleteInstanceProfileOutput, error)

func (*IAMAPI) GetInstanceProfileWithContext

func (s *IAMAPI) GetInstanceProfileWithContext(_ context.Context, input *iam.GetInstanceProfileInput, _ ...request.Option) (*iam.GetInstanceProfileOutput, error)

func (*IAMAPI) Reset

func (s *IAMAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

type IAMAPIBehavior

IAMAPIBehavior must be reset between tests otherwise tests will pollute each other.

type MockedFunction

type MockedFunction[I any, O any] struct {
	Output          AtomicPtr[O]      // Output to return on call to this function
	CalledWithInput AtomicPtrSlice[I] // Slice used to keep track of passed input to this function
	Error           AtomicError       // Error to return a certain number of times defined by custom error options
	// contains filtered or unexported fields
}

func (*MockedFunction[I, O]) Calls

func (m *MockedFunction[I, O]) Calls() int

func (*MockedFunction[I, O]) FailedCalls

func (m *MockedFunction[I, O]) FailedCalls() int

func (*MockedFunction[I, O]) Invoke

func (m *MockedFunction[I, O]) Invoke(input *I, defaultTransformer func(*I) (*O, error)) (*O, error)

func (*MockedFunction[I, O]) Reset

func (m *MockedFunction[I, O]) Reset()

Reset must be called between tests otherwise tests will pollute each other.

func (*MockedFunction[I, O]) SuccessfulCalls

func (m *MockedFunction[I, O]) SuccessfulCalls() int

type PricingAPI

type PricingAPI struct {
	pricingiface.PricingAPI
	PricingBehavior
}

func (*PricingAPI) GetProductsPagesWithContext

func (p *PricingAPI) GetProductsPagesWithContext(_ aws.Context, _ *pricing.GetProductsInput, fn func(*pricing.GetProductsOutput, bool) bool, _ ...request.Option) error

func (*PricingAPI) Reset

func (p *PricingAPI) Reset()

type PricingBehavior

type PricingBehavior struct {
	NextError         AtomicError
	GetProductsOutput AtomicPtr[pricing.GetProductsOutput]
}

type SQSAPI

type SQSAPI struct {
	sqsiface.SQSAPI
	SQSBehavior
}

func (*SQSAPI) DeleteMessageWithContext

func (s *SQSAPI) DeleteMessageWithContext(_ context.Context, input *sqs.DeleteMessageInput, _ ...request.Option) (*sqs.DeleteMessageOutput, error)

func (*SQSAPI) GetQueueUrlWithContext

func (s *SQSAPI) GetQueueUrlWithContext(_ context.Context, input *sqs.GetQueueUrlInput, _ ...request.Option) (*sqs.GetQueueUrlOutput, error)

func (*SQSAPI) ReceiveMessageWithContext

func (s *SQSAPI) ReceiveMessageWithContext(_ context.Context, input *sqs.ReceiveMessageInput, _ ...request.Option) (*sqs.ReceiveMessageOutput, error)

func (*SQSAPI) Reset

func (s *SQSAPI) Reset()

Reset must be called between tests otherwise tests will pollute each other.

type SQSBehavior

type SQSBehavior struct {
	GetQueueURLBehavior    MockedFunction[sqs.GetQueueUrlInput, sqs.GetQueueUrlOutput]
	ReceiveMessageBehavior MockedFunction[sqs.ReceiveMessageInput, sqs.ReceiveMessageOutput]
	DeleteMessageBehavior  MockedFunction[sqs.DeleteMessageInput, sqs.DeleteMessageOutput]
}

SQSBehavior must be reset between tests otherwise tests will pollute each other.

type SSMAPI

type SSMAPI struct {
	ssmiface.SSMAPI
	Parameters         map[string]string
	GetParameterOutput *ssm.GetParameterOutput
	WantErr            error
}

func NewSSMAPI

func NewSSMAPI() *SSMAPI

func (SSMAPI) GetParameterWithContext

func (a SSMAPI) GetParameterWithContext(_ context.Context, input *ssm.GetParameterInput, _ ...request.Option) (*ssm.GetParameterOutput, error)

func (*SSMAPI) Reset

func (a *SSMAPI) Reset()

Jump to

Keyboard shortcuts

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