fake

package
v0.0.0-...-5affba4 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 string, tags []*ec2.Tag) bool

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 NewOnDemandPrice

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

func PrivateDNSName

func PrivateDNSName() string

func ProviderID

func ProviderID(id string) string

func RandomProviderID

func RandomProviderID() 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]) 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) IsMachineDrifted

func (c *CloudProvider) IsMachineDrifted(_ context.Context, machine *v1alpha5.Machine) (bool, error)

func (*CloudProvider) Name

func (c *CloudProvider) Name() string

Name returns the CloudProvider implementation name.

type EC2API

type EC2API struct {
	ec2iface.EC2API
	EC2Behavior
}

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) DescribeImagesWithContext

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

func (*EC2API) DescribeInstanceTypesPagesWithContext

func (e *EC2API) DescribeInstanceTypesPagesWithContext(_ context.Context, _ *ec2.DescribeInstanceTypesInput, fn func(*ec2.DescribeInstanceTypesOutput, bool) bool, _ ...request.Option) 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) DescribeLaunchTemplatesWithContext

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

func (*EC2API) DescribeSecurityGroupsWithContext

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

func (*EC2API) DescribeSpotPriceHistoryPagesWithContext

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

func (*EC2API) DescribeSubnetsWithContext

func (e *EC2API) DescribeSubnetsWithContext(ctx context.Context, input *ec2.DescribeSubnetsInput, opts ...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 (*EKSAPI) DescribeCluster

func (s *EKSAPI) DescribeCluster(input *eks.DescribeClusterInput) (*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 {
	DescribeClusterBehaviour MockedFunction[eks.DescribeClusterInput, eks.DescribeClusterOutput]
}

EKSAPIBehavior 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) (*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

func (*MockedFunction[I, O]) WithDefault

func (m *MockedFunction[I, O]) WithDefault(output *O) *MockedFunction[I, O]

type PricingAPI

type PricingAPI struct {
	pricingiface.PricingAPI
	PricingBehavior
}

func (*PricingAPI) GetProductsPagesWithContext

func (p *PricingAPI) GetProductsPagesWithContext(_ aws.Context, inp *pricing.GetProductsInput, fn func(*pricing.GetProductsOutput, bool) bool, opts ...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) GetQueueAttributesWithContext

func (s *SQSAPI) GetQueueAttributesWithContext(_ context.Context, input *sqs.GetQueueAttributesInput, _ ...request.Option) (*sqs.GetQueueAttributesOutput, 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

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

type SSMAPI

type SSMAPI struct {
	ssmiface.SSMAPI
	GetParameterOutput *ssm.GetParameterOutput
	WantErr            error
}

func (SSMAPI) GetParameterWithContext

func (a SSMAPI) GetParameterWithContext(ctx context.Context, input *ssm.GetParameterInput, opts ...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