awsfake

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package awsfake provides a stateful, in-memory fake of the AWS EC2, ELBv2 and SSM clients used by the holodeck AWS provider. It implements the internal/aws.{EC2Client,ELBv2Client,SSMClient} interfaces so it can be injected via the provider's WithEC2Client/WithSSMClient/WithELBv2Client options, letting the real provisioning/teardown code run credential-free against an observable resource store.

The fake is AWS's documented interface-mock pattern (AWS ships no official Go SDK v2 mocks): https://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/unit-testing.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	Store *Store
	EC2   *FakeEC2
	ELBv2 *FakeELBv2
	SSM   *FakeSSM
}

Fake bundles the three fake clients over one shared Store so a single test can drive create/describe/delete across EC2, ELBv2 and SSM and observe the resulting resource state.

func New

func New() *Fake

New returns a Fake with permissive, seeded defaults: a small image catalog (including two Ubuntu images with distinct creation dates), an instance-type catalog covering the repo's test configs, and empty resource maps.

type FakeEC2

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

FakeEC2 is a stateful in-memory implementation of internalaws.EC2Client.

func (*FakeEC2) AllocateAddress

func (f *FakeEC2) AllocateAddress(ctx context.Context, params *ec2.AllocateAddressInput, optFns ...func(*ec2.Options)) (*ec2.AllocateAddressOutput, error)

func (*FakeEC2) AssociateRouteTable

func (f *FakeEC2) AssociateRouteTable(ctx context.Context, params *ec2.AssociateRouteTableInput, optFns ...func(*ec2.Options)) (*ec2.AssociateRouteTableOutput, error)

func (*FakeEC2) AttachInternetGateway

func (f *FakeEC2) AttachInternetGateway(ctx context.Context, params *ec2.AttachInternetGatewayInput, optFns ...func(*ec2.Options)) (*ec2.AttachInternetGatewayOutput, error)

func (*FakeEC2) AuthorizeSecurityGroupIngress

func (f *FakeEC2) AuthorizeSecurityGroupIngress(ctx context.Context, params *ec2.AuthorizeSecurityGroupIngressInput, optFns ...func(*ec2.Options)) (*ec2.AuthorizeSecurityGroupIngressOutput, error)

func (*FakeEC2) CreateInternetGateway

func (f *FakeEC2) CreateInternetGateway(ctx context.Context, params *ec2.CreateInternetGatewayInput, optFns ...func(*ec2.Options)) (*ec2.CreateInternetGatewayOutput, error)

func (*FakeEC2) CreateNatGateway

func (f *FakeEC2) CreateNatGateway(ctx context.Context, params *ec2.CreateNatGatewayInput, optFns ...func(*ec2.Options)) (*ec2.CreateNatGatewayOutput, error)

func (*FakeEC2) CreateRoute

func (f *FakeEC2) CreateRoute(ctx context.Context, params *ec2.CreateRouteInput, optFns ...func(*ec2.Options)) (*ec2.CreateRouteOutput, error)

func (*FakeEC2) CreateRouteTable

func (f *FakeEC2) CreateRouteTable(ctx context.Context, params *ec2.CreateRouteTableInput, optFns ...func(*ec2.Options)) (*ec2.CreateRouteTableOutput, error)

func (*FakeEC2) CreateSecurityGroup

func (f *FakeEC2) CreateSecurityGroup(ctx context.Context, params *ec2.CreateSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.CreateSecurityGroupOutput, error)

func (*FakeEC2) CreateSubnet

func (f *FakeEC2) CreateSubnet(ctx context.Context, params *ec2.CreateSubnetInput, optFns ...func(*ec2.Options)) (*ec2.CreateSubnetOutput, error)

func (*FakeEC2) CreateTags

func (f *FakeEC2) CreateTags(ctx context.Context, params *ec2.CreateTagsInput, optFns ...func(*ec2.Options)) (*ec2.CreateTagsOutput, error)

func (*FakeEC2) CreateVpc

func (f *FakeEC2) CreateVpc(ctx context.Context, params *ec2.CreateVpcInput, optFns ...func(*ec2.Options)) (*ec2.CreateVpcOutput, error)

func (*FakeEC2) DeleteInternetGateway

func (f *FakeEC2) DeleteInternetGateway(ctx context.Context, params *ec2.DeleteInternetGatewayInput, optFns ...func(*ec2.Options)) (*ec2.DeleteInternetGatewayOutput, error)

func (*FakeEC2) DeleteNatGateway

func (f *FakeEC2) DeleteNatGateway(ctx context.Context, params *ec2.DeleteNatGatewayInput, optFns ...func(*ec2.Options)) (*ec2.DeleteNatGatewayOutput, error)

func (*FakeEC2) DeleteRouteTable

func (f *FakeEC2) DeleteRouteTable(ctx context.Context, params *ec2.DeleteRouteTableInput, optFns ...func(*ec2.Options)) (*ec2.DeleteRouteTableOutput, error)

func (*FakeEC2) DeleteSecurityGroup

func (f *FakeEC2) DeleteSecurityGroup(ctx context.Context, params *ec2.DeleteSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.DeleteSecurityGroupOutput, error)

func (*FakeEC2) DeleteSubnet

func (f *FakeEC2) DeleteSubnet(ctx context.Context, params *ec2.DeleteSubnetInput, optFns ...func(*ec2.Options)) (*ec2.DeleteSubnetOutput, error)

func (*FakeEC2) DeleteVpc

func (f *FakeEC2) DeleteVpc(ctx context.Context, params *ec2.DeleteVpcInput, optFns ...func(*ec2.Options)) (*ec2.DeleteVpcOutput, error)

func (*FakeEC2) DescribeImages

func (f *FakeEC2) DescribeImages(ctx context.Context, params *ec2.DescribeImagesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeImagesOutput, error)

func (*FakeEC2) DescribeInstanceTypes

func (f *FakeEC2) DescribeInstanceTypes(ctx context.Context, params *ec2.DescribeInstanceTypesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstanceTypesOutput, error)

func (*FakeEC2) DescribeInstances

func (f *FakeEC2) DescribeInstances(ctx context.Context, params *ec2.DescribeInstancesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error)

func (*FakeEC2) DescribeInternetGateways

func (f *FakeEC2) DescribeInternetGateways(ctx context.Context, params *ec2.DescribeInternetGatewaysInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInternetGatewaysOutput, error)

func (*FakeEC2) DescribeNatGateways

func (f *FakeEC2) DescribeNatGateways(ctx context.Context, params *ec2.DescribeNatGatewaysInput, optFns ...func(*ec2.Options)) (*ec2.DescribeNatGatewaysOutput, error)

func (*FakeEC2) DescribeNetworkInterfaces

func (f *FakeEC2) DescribeNetworkInterfaces(ctx context.Context, params *ec2.DescribeNetworkInterfacesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeNetworkInterfacesOutput, error)

func (*FakeEC2) DescribeRouteTables

func (f *FakeEC2) DescribeRouteTables(ctx context.Context, params *ec2.DescribeRouteTablesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeRouteTablesOutput, error)

func (*FakeEC2) DescribeSecurityGroups

func (f *FakeEC2) DescribeSecurityGroups(ctx context.Context, params *ec2.DescribeSecurityGroupsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeSecurityGroupsOutput, error)

func (*FakeEC2) DescribeSubnets

func (f *FakeEC2) DescribeSubnets(ctx context.Context, params *ec2.DescribeSubnetsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeSubnetsOutput, error)

func (*FakeEC2) DescribeTags

func (f *FakeEC2) DescribeTags(ctx context.Context, params *ec2.DescribeTagsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeTagsOutput, error)

func (*FakeEC2) DescribeVpcs

func (f *FakeEC2) DescribeVpcs(ctx context.Context, params *ec2.DescribeVpcsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVpcsOutput, error)

func (*FakeEC2) DetachInternetGateway

func (f *FakeEC2) DetachInternetGateway(ctx context.Context, params *ec2.DetachInternetGatewayInput, optFns ...func(*ec2.Options)) (*ec2.DetachInternetGatewayOutput, error)

func (*FakeEC2) ModifyNetworkInterfaceAttribute

func (f *FakeEC2) ModifyNetworkInterfaceAttribute(ctx context.Context, params *ec2.ModifyNetworkInterfaceAttributeInput, optFns ...func(*ec2.Options)) (*ec2.ModifyNetworkInterfaceAttributeOutput, error)

func (*FakeEC2) ModifySubnetAttribute

func (f *FakeEC2) ModifySubnetAttribute(ctx context.Context, params *ec2.ModifySubnetAttributeInput, optFns ...func(*ec2.Options)) (*ec2.ModifySubnetAttributeOutput, error)

func (*FakeEC2) ModifyVpcAttribute

func (f *FakeEC2) ModifyVpcAttribute(ctx context.Context, params *ec2.ModifyVpcAttributeInput, optFns ...func(*ec2.Options)) (*ec2.ModifyVpcAttributeOutput, error)

func (*FakeEC2) ReleaseAddress

func (f *FakeEC2) ReleaseAddress(ctx context.Context, params *ec2.ReleaseAddressInput, optFns ...func(*ec2.Options)) (*ec2.ReleaseAddressOutput, error)

func (*FakeEC2) ReplaceRouteTableAssociation

func (f *FakeEC2) ReplaceRouteTableAssociation(ctx context.Context, params *ec2.ReplaceRouteTableAssociationInput, optFns ...func(*ec2.Options)) (*ec2.ReplaceRouteTableAssociationOutput, error)

func (*FakeEC2) RevokeSecurityGroupEgress

func (f *FakeEC2) RevokeSecurityGroupEgress(ctx context.Context, params *ec2.RevokeSecurityGroupEgressInput, optFns ...func(*ec2.Options)) (*ec2.RevokeSecurityGroupEgressOutput, error)

func (*FakeEC2) RevokeSecurityGroupIngress

func (f *FakeEC2) RevokeSecurityGroupIngress(ctx context.Context, params *ec2.RevokeSecurityGroupIngressInput, optFns ...func(*ec2.Options)) (*ec2.RevokeSecurityGroupIngressOutput, error)

func (*FakeEC2) RunInstances

func (f *FakeEC2) RunInstances(ctx context.Context, params *ec2.RunInstancesInput, optFns ...func(*ec2.Options)) (*ec2.RunInstancesOutput, error)

func (*FakeEC2) TerminateInstances

func (f *FakeEC2) TerminateInstances(ctx context.Context, params *ec2.TerminateInstancesInput, optFns ...func(*ec2.Options)) (*ec2.TerminateInstancesOutput, error)

type FakeELBv2

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

FakeELBv2 is a stateful in-memory implementation of internalaws.ELBv2Client.

type FakeSSM

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

FakeSSM is a stateful in-memory implementation of internalaws.SSMClient.

func (*FakeSSM) GetParameter

func (f *FakeSSM) GetParameter(ctx context.Context, params *ssm.GetParameterInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)

GetParameter returns a seeded parameter value, or a permissive default AMI id (defaultAMI) for any unseeded name so the AMI resolver's SSM path resolves.

type Store

type Store struct {

	// EC2 resources.
	Vpcs              map[string]*ec2types.Vpc
	Subnets           map[string]*ec2types.Subnet
	InternetGateways  map[string]*ec2types.InternetGateway
	RouteTables       map[string]*ec2types.RouteTable
	SecurityGroups    map[string]*ec2types.SecurityGroup
	Instances         map[string]*ec2types.Instance
	NatGateways       map[string]*ec2types.NatGateway
	Addresses         map[string]*ec2types.Address
	NetworkInterfaces map[string]*ec2types.NetworkInterface

	// ELBv2 resources (load balancers/target groups/listeners keyed by ARN).
	LoadBalancers     map[string]*elbv2types.LoadBalancer
	TargetGroups      map[string]*elbv2types.TargetGroup
	Listeners         map[string]*elbv2types.Listener
	RegisteredTargets map[string][]elbv2types.TargetDescription

	// SSM parameters.
	Parameters map[string]string

	// Seed data (excluded from ResourceCounts/Empty).
	Images        []ec2types.Image
	InstanceTypes map[string][]ec2types.ArchitectureType
	// contains filtered or unexported fields
}

Store is the in-memory resource database shared by the fake clients. All access is guarded by mu; the fake client methods lock it at entry, so the unexported record/failure/nextID helpers assume the lock is already held.

func (*Store) CallsTo

func (s *Store) CallsTo(method string) int

CallsTo returns how many times method has been invoked on the fake.

func (*Store) Empty

func (s *Store) Empty() bool

Empty reports whether all live resource counts are zero.

func (*Store) FailNext

func (s *Store) FailNext(method string, err error)

FailNext queues a one-shot error for the next call to method. Multiple calls queue FIFO. The method name is the EC2/ELBv2/SSM API name (e.g. "CreateSubnet").

func (*Store) Inputs

func (s *Store) Inputs(method string) []any

Inputs returns, in call order, the input parameters recorded for method. Every fake client method records its params, so this is the observable equivalent of the per-method capture closures the provider unit tests previously used. Each element is the concrete *ec2.XxxInput / *elasticloadbalancingv2.XxxInput / *ssm.XxxInput passed by the caller; it is nil if method was never called.

func (*Store) ResourceCounts

func (s *Store) ResourceCounts() map[string]int

ResourceCounts returns the number of live (non-terminated/non-deleted) resources per kind. Seed data (images, instance types, SSM parameters) is excluded. Keys are stable and consumed by the E2E suite.

func (*Store) SeedDrainingENI

func (s *Store) SeedDrainingENI(vpcID string, blockingPolls int) string

SeedDrainingENI adds an in-use network interface to vpcID that DescribeNetworkInterfaces reports as in-use (blocking) for the first blockingPolls observations, then removes — driving waitForENIsDrained's re-poll loop. It returns the interface id.

func (*Store) SeedImage

func (s *Store) SeedImage(img ec2types.Image)

SeedImage adds an image to the catalog returned by DescribeImages.

func (*Store) SeedInstanceType

func (s *Store) SeedInstanceType(name string)

SeedInstanceType adds an instance type to the no-filter catalog returned by DescribeInstanceTypes (architecture inferred from the type prefix).

func (*Store) SeedInstanceTypeAbsent

func (s *Store) SeedInstanceTypeAbsent(name string)

SeedInstanceTypeAbsent marks an instance type as not offered, so a filtered DescribeInstanceTypes query for it returns no results — the region-unavailable case the provider treats as "instance type not found".

func (*Store) SeedInstanceTypeArchs

func (s *Store) SeedInstanceTypeArchs(name string, archs ...ec2types.ArchitectureType)

SeedInstanceTypeArchs registers explicit supported architectures for an instance type, overriding the prefix heuristic in DescribeInstanceTypes' filtered (InstanceTypes) responses. It models types whose architecture the heuristic cannot infer, e.g. mac variants or multi-architecture types.

func (*Store) SeedNextNatGatewayDeleteState

func (s *Store) SeedNextNatGatewayDeleteState(deletingPolls int)

SeedNextNatGatewayDeleteState scripts the next DeleteNatGateway so the gateway lingers in "deleting" for deletingPolls DescribeNatGateways observations before it is removed (subsequent describes report it gone), driving deleteNATGateway's wait-for-deleted poll loop. Without it, DeleteNatGateway removes the gateway immediately.

func (*Store) SeedNextNatGatewayState

func (s *Store) SeedNextNatGatewayState(pendingPolls int, final ec2types.NatGatewayState)

SeedNextNatGatewayState scripts the state reported by the next NAT gateway created via CreateNatGateway: it is created (and reported by DescribeNatGateways) as pending for the first pendingPolls observations, then flips to final. With pendingPolls==0 the gateway is created directly in final. The directive is one-shot; without it NAT gateways are created available. It exists to drive createNATGateway's poll loop (wait-for-available and fail-on-failed) which a single immediate-available response cannot exercise.

func (*Store) SeedParameter

func (s *Store) SeedParameter(name, value string)

SeedParameter seeds an SSM parameter value returned by GetParameter.

func (*Store) SetImages

func (s *Store) SetImages(imgs ...ec2types.Image)

SetImages replaces the DescribeImages catalog (clearing the seeded default images) so a test can present exactly the AMIs a resolution path should see.

func (*Store) SetInstanceTypeCatalog

func (s *Store) SetInstanceTypeCatalog(names ...string)

SetInstanceTypeCatalog replaces the no-filter DescribeInstanceTypes catalog (the types checkInstanceTypes scans) with exactly the given types, clearing the seeded defaults. Passing none yields an empty catalog — the region-unavailable case that makes checkInstanceTypes reject its type.

Jump to

Keyboard shortcuts

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