testing

package
v0.0.0-...-b0bff92 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Pending      = types.InstanceState{aws.Int32(0), "pending"}
	Running      = types.InstanceState{aws.Int32(16), "running"}
	ShuttingDown = types.InstanceState{aws.Int32(32), "shutting-down"}
	Terminated   = types.InstanceState{aws.Int32(16), "terminated"}
	Stopped      = types.InstanceState{aws.Int32(16), "stopped"}
)

Recognized AWS instance states.

Functions

This section is empty.

Types

type IAMServer

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

IAMServer implements an IAM simulator for use in testing

func NewIAMServer

func NewIAMServer() (*IAMServer, error)

func (*IAMServer) AddRoleToInstanceProfile

func (i *IAMServer) AddRoleToInstanceProfile(
	ctx context.Context,
	input *iam.AddRoleToInstanceProfileInput,
	opts ...func(*iam.Options),
) (*iam.AddRoleToInstanceProfileOutput, error)

func (*IAMServer) CreateInstanceProfile

func (i *IAMServer) CreateInstanceProfile(
	ctx context.Context,
	input *iam.CreateInstanceProfileInput,
	opts ...func(*iam.Options),
) (*iam.CreateInstanceProfileOutput, error)

func (*IAMServer) CreateRole

func (i *IAMServer) CreateRole(
	ctx context.Context,
	input *iam.CreateRoleInput,
	opts ...func(*iam.Options),
) (*iam.CreateRoleOutput, error)

func (*IAMServer) DeleteInstanceProfile

func (i *IAMServer) DeleteInstanceProfile(
	ctx context.Context,
	input *iam.DeleteInstanceProfileInput,
	opts ...func(*iam.Options),
) (*iam.DeleteInstanceProfileOutput, error)

func (*IAMServer) DeleteRole

func (i *IAMServer) DeleteRole(
	ctx context.Context,
	input *iam.DeleteRoleInput,
	opts ...func(*iam.Options),
) (*iam.DeleteRoleOutput, error)

func (*IAMServer) DeleteRolePolicy

func (i *IAMServer) DeleteRolePolicy(
	ctx context.Context,
	input *iam.DeleteRolePolicyInput,
	opts ...func(*iam.Options),
) (*iam.DeleteRolePolicyOutput, error)

func (*IAMServer) GetInstanceProfile

func (i *IAMServer) GetInstanceProfile(
	ctx context.Context,
	input *iam.GetInstanceProfileInput,
	opts ...func(*iam.Options),
) (*iam.GetInstanceProfileOutput, error)

func (*IAMServer) GetRole

func (i *IAMServer) GetRole(
	ctx context.Context,
	input *iam.GetRoleInput,
	opts ...func(*iam.Options),
) (*iam.GetRoleOutput, error)

func (*IAMServer) PutRolePolicy

func (i *IAMServer) PutRolePolicy(
	ctx context.Context,
	input *iam.PutRolePolicyInput,
	opts ...func(*iam.Options),
) (*iam.PutRolePolicyOutput, error)

func (*IAMServer) RemoveRoleFromInstanceProfile

func (i *IAMServer) RemoveRoleFromInstanceProfile(
	ctx context.Context,
	input *iam.RemoveRoleFromInstanceProfileInput,
	opts ...func(*iam.Options),
) (*iam.RemoveRoleFromInstanceProfileOutput, error)

func (*IAMServer) Reset

func (i *IAMServer) Reset()

type InlinePolicy

type InlinePolicy struct {
	PolicyDocument *string
	PolicyName     *string
}

type Instance

type Instance struct {

	// UserData holds the data that was passed to the RunInstances request
	// when the instance was started.
	UserData []byte
	// contains filtered or unexported fields
}

Instance holds a fake ec2 instance

type Server

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

Server implements an EC2 simulator for use in testing.

func NewServer

func NewServer() (*Server, error)

NewServer returns a new server.

func (*Server) AddDefaultVpcAndSubnets

func (srv *Server) AddDefaultVpcAndSubnets() (defaultVpc types.Vpc, err error)

AddDefaultVpcAndSubnets makes it easy to simulate a default Vpc is present in the test server. Calling this method is more or less an equivalent of calling the following methods as described:

1. AddVpc(), using 10.10.0.0/16 as CIDR and sane defaults. 2. AddInternetGateway(), attached to the default Vpc. 3. AddRouteTable(), attached to the default Vpc, with sane defaults and using the IGW above as default route. 4. AddSubnet(), once per defined AZ, with 10.10.X.0/24 CIDR (X is a zero-based index). Each subnet has both DefaultForAZ and MapPublicIPOnLaunch attributes set. 5. SetAccountAttributes(), with "supported-platforms" set to "EC2", "Vpc"; and "default-vpc" set to the added default Vpc.

NOTE: If no AZs are set on the test server, this method fails.

func (*Server) AddInternetGateway

func (srv *Server) AddInternetGateway(igw types.InternetGateway) (types.InternetGateway, error)

AddInternetGateway inserts the given internet gateway in the test server, as if it was created using the simulated AWS API. The Id field of igw is ignored and replaced by the next igwId counter value, prefixed by "igw-". When set, the VPCId field must refer to a VPC the test server knows about. If VPCId is empty the IGW is considered not attached.

func (*Server) AddRouteTable

func (srv *Server) AddRouteTable(t types.RouteTable) (types.RouteTable, error)

AddRouteTable inserts the given route table in the test server, as if it was created using the simulated AWS API. The Id field of t is ignored and replaced by the next rtbId counter value, prefixed by "rtb-". When IsMain is true, the table becomes the main route table for its VPC.

Any empty TableId field of an item in the Associations list will be set to the added table's Id automatically.

func (*Server) AddSubnet

func (srv *Server) AddSubnet(sub types.Subnet) (types.Subnet, error)

AddSubnet inserts the given subnet in the test server, as if it was created using the simulated AWS API. The Id field of v is ignored and replaced by the next subnetId counter value, prefixed by "subnet-". The VPCId field of sub must be contain an existing VPC id, and the AvailZone field must contain an existing AZ, otherwise errors are returned. Finally, if AvailableIPCount is negative it is

func (*Server) AddVpc

func (srv *Server) AddVpc(v types.Vpc) types.Vpc

AddVpc inserts the given Vpc in the test server, as if it was created using the simulated AWS API. The Id field of v is ignored and replaced by the next vpcId counter value, prefixed by "vpc-". When IsDefault is true, the Vpc becomes the default Vpc for the simulated region.

func (*Server) AssociateIamInstanceProfile

func (srv *Server) AssociateIamInstanceProfile(
	ctx context.Context,
	params *ec2.AssociateIamInstanceProfileInput,
	opts ...func(*ec2.Options),
) (*ec2.AssociateIamInstanceProfileOutput, error)

func (*Server) AttachVolume

func (srv *Server) AttachVolume(ctx context.Context, in *ec2.AttachVolumeInput, opts ...func(*ec2.Options)) (*ec2.AttachVolumeOutput, error)

AttachVolume implements ec2.Client.

func (*Server) AuthorizeSecurityGroupIngress

func (srv *Server) AuthorizeSecurityGroupIngress(ctx context.Context, in *ec2.AuthorizeSecurityGroupIngressInput, opts ...func(*ec2.Options)) (*ec2.AuthorizeSecurityGroupIngressOutput, error)

AuthorizeSecurityGroupIngress implements ec2.Client.

func (*Server) CreateSecurityGroup

func (srv *Server) CreateSecurityGroup(ctx context.Context, in *ec2.CreateSecurityGroupInput, opts ...func(*ec2.Options)) (*ec2.CreateSecurityGroupOutput, error)

CreateSecurityGroup implements ec2.Client.

func (*Server) CreateTags

func (srv *Server) CreateTags(ctx context.Context, in *ec2.CreateTagsInput, opts ...func(*ec2.Options)) (*ec2.CreateTagsOutput, error)

CreateTags implements ec2.Client.

func (*Server) CreateVolume

func (srv *Server) CreateVolume(ctx context.Context, in *ec2.CreateVolumeInput, opts ...func(*ec2.Options)) (*ec2.CreateVolumeOutput, error)

CreateVolume implements ec2.Client.

func (*Server) DeleteSecurityGroup

func (srv *Server) DeleteSecurityGroup(ctx context.Context, in *ec2.DeleteSecurityGroupInput, opts ...func(*ec2.Options)) (*ec2.DeleteSecurityGroupOutput, error)

DeleteSecurityGroup implements ec2.Client.

func (*Server) DeleteVolume

func (srv *Server) DeleteVolume(ctx context.Context, in *ec2.DeleteVolumeInput, opts ...func(*ec2.Options)) (*ec2.DeleteVolumeOutput, error)

DeleteVolume implements ec2.Client.

func (*Server) DescribeAccountAttributes

func (srv *Server) DescribeAccountAttributes(ctx context.Context, in *ec2.DescribeAccountAttributesInput, opts ...func(*ec2.Options)) (*ec2.DescribeAccountAttributesOutput, error)

DescribeAccountAttributes implements ec2.Client.

func (*Server) DescribeAvailabilityZones

func (srv *Server) DescribeAvailabilityZones(ctx context.Context, in *ec2.DescribeAvailabilityZonesInput, opts ...func(*ec2.Options)) (*ec2.DescribeAvailabilityZonesOutput, error)

DescribeAvailabilityZones implements ec2.Client

func (*Server) DescribeIamInstanceProfileAssociations

func (srv *Server) DescribeIamInstanceProfileAssociations(
	ctx context.Context,
	params *ec2.DescribeIamInstanceProfileAssociationsInput,
	opts ...func(*ec2.Options),
) (*ec2.DescribeIamInstanceProfileAssociationsOutput, error)

func (*Server) DescribeInstanceTypeOfferings

DescribeInstanceTypeOfferings implements ec2.Client.

func (*Server) DescribeInstanceTypes

func (*Server) DescribeInstanceTypes(_ context.Context, _ *ec2.DescribeInstanceTypesInput, _ ...func(*ec2.Options)) (*ec2.DescribeInstanceTypesOutput, error)

DescribeInstanceTypes implements ec2.Client.

func (*Server) DescribeInstances

func (srv *Server) DescribeInstances(ctx context.Context, in *ec2.DescribeInstancesInput, opts ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error)

DescribeInstances implements ec2.Client.

func (*Server) DescribeInternetGateways

func (srv *Server) DescribeInternetGateways(ctx context.Context, in *ec2.DescribeInternetGatewaysInput, opts ...func(*ec2.Options)) (*ec2.DescribeInternetGatewaysOutput, error)

DescribeInternetGateways implements ec2.Client.

func (*Server) DescribeNetworkInterfaces

func (srv *Server) DescribeNetworkInterfaces(ctx context.Context, in *ec2.DescribeNetworkInterfacesInput, opts ...func(*ec2.Options)) (*ec2.DescribeNetworkInterfacesOutput, error)

DescribeNetworkInterfaces implements ec2.Client.

func (*Server) DescribeRouteTables

func (srv *Server) DescribeRouteTables(ctx context.Context, in *ec2.DescribeRouteTablesInput, opts ...func(*ec2.Options)) (*ec2.DescribeRouteTablesOutput, error)

DescribeRouteTables implements ec2.Client.

func (*Server) DescribeSecurityGroups

func (srv *Server) DescribeSecurityGroups(ctx context.Context, in *ec2.DescribeSecurityGroupsInput, opts ...func(*ec2.Options)) (*ec2.DescribeSecurityGroupsOutput, error)

func (*Server) DescribeSpotPriceHistory

func (*Server) DescribeSpotPriceHistory(_ context.Context, _ *ec2.DescribeSpotPriceHistoryInput, _ ...func(*ec2.Options)) (*ec2.DescribeSpotPriceHistoryOutput, error)

DescribeSpotPriceHistory implements ec2.Client.

func (*Server) DescribeSubnets

func (srv *Server) DescribeSubnets(ctx context.Context, in *ec2.DescribeSubnetsInput, opts ...func(*ec2.Options)) (*ec2.DescribeSubnetsOutput, error)

DescribeSubnets implements ec2.Client.

func (*Server) DescribeVolumes

func (srv *Server) DescribeVolumes(ctx context.Context, in *ec2.DescribeVolumesInput, opts ...func(*ec2.Options)) (*ec2.DescribeVolumesOutput, error)

DescribeVolumes implements ec2.Client.

func (*Server) DescribeVpcs

func (srv *Server) DescribeVpcs(ctx context.Context, in *ec2.DescribeVpcsInput, opts ...func(*ec2.Options)) (*ec2.DescribeVpcsOutput, error)

DescribeVpcs implements ec2.Client.

func (*Server) DetachVolume

func (srv *Server) DetachVolume(ctx context.Context, in *ec2.DetachVolumeInput, opts ...func(*ec2.Options)) (*ec2.DetachVolumeOutput, error)

DetachVolume implements ec2.Client.

func (*Server) Instance

func (srv *Server) Instance(id string) *Instance

Instance returns the instance for the given instance id. It returns nil if there is no such instance.

func (*Server) NewInstances

func (srv *Server) NewInstances(n int, instType types.InstanceType, imageId string, state types.InstanceState, groups []types.GroupIdentifier) ([]string, error)

NewInstances creates n new instances in srv with the given instance type, image ID, initial state, and security groups. If any group does not already exist, it will be created. NewInstances returns the ids of the new instances.

func (*Server) NewInstancesVPC

func (srv *Server) NewInstancesVPC(vpcId, subnetId string, n int, instType types.InstanceType, imageId string, state types.InstanceState, groups []types.GroupIdentifier) ([]string, error)

NewInstancesVPC creates n new VPC instances in srv with the given instance type, image ID, initial state, and security groups, belonging to the given vpcId and subnetId. If any group does not already exist, it will be created. NewInstancesVPC returns the ids of the new instances.

If vpcId and subnetId are both empty, this call is equivalent to calling NewInstances.

func (*Server) RemoveInternetGateway

func (srv *Server) RemoveInternetGateway(igwId string) error

RemoveInternetGateway removes the internet gateway with the given igwId, stored in the test server. It's an error to try to remove an unknown or empty igwId.

func (*Server) RemoveRouteTable

func (srv *Server) RemoveRouteTable(rtbId string) error

RemoveRouteTable removes an route table with the given rtbId from the test server. It's an error to try to remove an unknown or empty rtbId.

func (*Server) RemoveVpc

func (srv *Server) RemoveVpc(vpcId string) error

RemoveVpc removes an existing Vpc with the given vpcId from the test server. It's an error to try to remove an unknown or empty vpcId.

NOTE: Removing a Vpc will remove all of its subnets.

func (*Server) Reset

func (srv *Server) Reset(withoutZonesOrGroups bool)

Reset is a convenient helper to remove all test entities (e.g. VPCs, subnets, instances) from the test server and reset all id counters. The, if withoutZonesOrGroups is false, a default AZ and security group will be created.

func (*Server) RevokeSecurityGroupIngress

func (srv *Server) RevokeSecurityGroupIngress(ctx context.Context, in *ec2.RevokeSecurityGroupIngressInput, opts ...func(*ec2.Options)) (*ec2.RevokeSecurityGroupIngressOutput, error)

RevokeSecurityGroupIngress implements ec2.Client.

func (*Server) RunInstances

func (srv *Server) RunInstances(ctx context.Context, in *ec2.RunInstancesInput, opts ...func(*ec2.Options)) (*ec2.RunInstancesOutput, error)

RunInstances implements ec2.Client.

func (*Server) SetAPIError

func (srv *Server) SetAPIError(apiName string, err error)

SetAPIError causes an error to be returned for the named function.

func (*Server) SetAPIModifiers

func (srv *Server) SetAPIModifiers(apiName string, f ...func(interface{}))

SetAPIModifiers calls the specified functions with the result of an api call.

func (*Server) SetAccountAttributes

func (srv *Server) SetAccountAttributes(attrs map[string][]types.AccountAttributeValue) error

SetAccountAttributes sets the given account attributes on the server. When the "default-vpc" attribute is specified, its value must match an existing VPC in the test server, otherwise it's an error. In addition, only the first value for "default-vpc", the rest (if any) are ignored.

func (*Server) SetAvailabilityZones

func (srv *Server) SetAvailabilityZones(zones []types.AvailabilityZone)

SetAvailabilityZones replaces the availability zones the test server is returning.

NOTE: If zones does not contain one or more existing zones those existing zones are removed along with any subnets that are associated with them!

func (*Server) SetCreateRootDisks

func (srv *Server) SetCreateRootDisks(create bool)

SetCreateRootDisks records whether or not the server should create root disks for each instance created. It defaults to false.

func (*Server) SetInitialInstanceState

func (srv *Server) SetInitialInstanceState(state types.InstanceState)

SetInitialInstanceState sets the state that any new instances will be started in.

func (*Server) TerminateInstances

func (srv *Server) TerminateInstances(ctx context.Context, in *ec2.TerminateInstancesInput, opts ...func(*ec2.Options)) (*ec2.TerminateInstancesOutput, error)

TerminateInstances implements ec2.Client.

func (*Server) UpdateVpc

func (srv *Server) UpdateVpc(v types.Vpc) error

UpdateVpc updates the Vpc info stored in the test server, matching the Id field of v, replacing all the other values with v's field values. It's an error to try to update a Vpc with unknown or empty Id.

Jump to

Keyboard shortcuts

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