aws

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 67 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEc2InstanceRunning added in v0.0.22

func AssertEc2InstanceRunning(t testing.TestingT, region, instanceID string)

AssertEc2InstanceRunning fails the test if the instance is not running.

func AssertEc2InstanceRunningE added in v0.0.22

func AssertEc2InstanceRunningE(t testing.TestingT, region, instanceID string) error

AssertEc2InstanceRunningE checks if the instance is in the "running" state.

func AssertS3BucketNotificationExists

func AssertS3BucketNotificationExists(t testing.TestingT, region string, bucketName string)

AssertS3BucketNotificationExists checks if the given S3 bucket has a notification configuration and returns an error if it does not.

func AssertS3BucketNotificationExistsE

func AssertS3BucketNotificationExistsE(t testing.TestingT, region string, bucketName string) error

AssertS3BucketVersioningExistsE checks if the given S3 bucket has a notification configuration and returns an error if it does not.

func ChangeMessageVisibility

func ChangeMessageVisibility(t testing.TestingT, awsRegion string, queueURL string, receipt string, timeoutSeconds int32)

func ChangeMessageVisibilityE

func ChangeMessageVisibilityE(t testing.TestingT, awsRegion string, queueURL string, receipt string, timeoutSeconds int32) error

func DeployUsingTerraform

func DeployUsingTerraform(t *testing.T, workingDir string, additionalRetryableErrors map[string]string)

func DescribeSfnExecution

func DescribeSfnExecution(t testing.TestingT, awsRegion string, executionArn string) *sfn.DescribeExecutionOutput

DescribeSfnExecution returns the description of the specified execution. This will fail the test if there is an error.

func DescribeSfnExecutionE

func DescribeSfnExecutionE(t testing.TestingT, awsRegion string, executionArn string) (*sfn.DescribeExecutionOutput, error)

DescribeSfnExecutionE returns the description of the specified execution.

func DescribeStream

func DescribeStream(t testing.TestingT, region string, streamName string) *types.StreamDescription

DescribeStream returns the description of a Kinesis stream.

func DescribeStreamE

func DescribeStreamE(t testing.TestingT, region string, streamName string) (*types.StreamDescription, error)

DescribeStreamE returns the description of a Kinesis stream.

func FilterLogEvents

func FilterLogEvents(t testing.TestingT, awsRegion string, logGroupName string) []string

GetCloudWatchLogEntries returns the CloudWatch log messages in the given region for the given log stream and log group.

func FilterLogEventsE

func FilterLogEventsE(t testing.TestingT, awsRegion string, logGroupName string) ([]string, error)

GetCloudWatchLogEntriesE returns the CloudWatch log messages in the given region for the given log stream and log group.

func FindResourceByType added in v0.1.1

func FindResourceByType(t *testing.T, workingDir, resourceType, resourceName string) string

FindResourceByType searches for a resource of a specific type in the given output from terraform list command. resourceName is optional and can be used to further filter the results. It returns the first matching resource or fails the test if no matching resource is found.

func ForwardingLogger

func ForwardingLogger(t *testing.T, targetLogger *loggers.Logger) *zap.Logger

ForwardingLogger returns a zap logger that forwards all log messages to terratestLogger

func GetAcmCertificateStatus

func GetAcmCertificateStatus(t testing.TestingT, awsRegion string, certArn string) types.CertificateStatus

Get Certificate Status

func GetAcmCertificateStatusE

func GetAcmCertificateStatusE(t testing.TestingT, awsRegion string, certArn string) (types.CertificateStatus, error)

GetAcmCertificateStatusE gets the ACM certificate status for the given certificate ARN in the given region.

func GetAlarmE

func GetAlarmE(t testing.TestingT, awsRegion string, alarmName string, alarmType types.AlarmType) (*cloudwatch.DescribeAlarmsOutput, error)

GetMetricAlarmE returns the details of the specified alarm.

func GetCompositeAlarm

func GetCompositeAlarm(t testing.TestingT, awsRegion string, alarmName string) *types.CompositeAlarm

GetMetricAlarm returns the details of the specified metric alarm.

func GetCompositeAlarmE

func GetCompositeAlarmE(t testing.TestingT, awsRegion string, alarmName string) (*types.CompositeAlarm, error)

GetMetricAlarmE returns the details of the specified alarm.

func GetDashboardBody

func GetDashboardBody(t testing.TestingT, awsRegion string, dashboardName string) *string

GetDashboardBody returns the body of the specified dashboard.

func GetDashboardBodyE

func GetDashboardBodyE(t testing.TestingT, awsRegion string, dashboardName string) (*string, error)

GetDashboardBodyE returns the body of the specified dashboard.

func GetDataProtectionPolicyDocument

func GetDataProtectionPolicyDocument(t testing.TestingT, awsRegion string, logGroupName string) string

GetDataProtectionPolicyDocument returns the policy of the specified log group data protection policy.

func GetDataProtectionPolicyDocumentE

func GetDataProtectionPolicyDocumentE(t testing.TestingT, awsRegion string, logGroupName string) (*string, error)

GetDataProtectionPolicyDocumentE returns the details of the specified log group data protection policy.

func GetDistributionE added in v0.0.10

func GetDistributionE(t testing.TestingT, region string, distributionId string) (*types.Distribution, error)

GetDistributionE returns the configuration of a CloudFront Distribution

func GetDynamoDbClientWithRole added in v0.0.25

func GetDynamoDbClientWithRole(t *testing.T, awsRegion, roleArn string) *dynamodb.Client

GetDynamoDbClientWithRole creates a new DynamoDB client that assumes the specified IAM role and fails the test if there's an error.

func GetDynamoDbClientWithRoleE added in v0.0.25

func GetDynamoDbClientWithRoleE(t *testing.T, awsRegion, roleArn string) (*dynamodb.Client, error)

GetDynamoDbClientWithRoleE creates a new DynamoDB client that assumes the specified IAM role.

func GetDynamoDbItemWithRole added in v0.0.25

func GetDynamoDbItemWithRole(t *testing.T, client *dynamodb.Client, tableName string, key map[string]types.AttributeValue, out interface{})

GetDynamoDbItemWithRole gets an item from a DynamoDB table using the given client. The result is unmarshalled into the 'out' interface.

func GetEc2ImageDetails added in v0.0.22

func GetEc2ImageDetails(t testing.TestingT, region, imageID string) *types.Image

GetEc2ImageDetails fetches the details of the image or fails the test.

func GetEc2ImageDetailsE added in v0.0.22

func GetEc2ImageDetailsE(t testing.TestingT, region, imageID string) (*types.Image, error)

GetEc2ImageDetailsE fetches the details of the image by image ID.

func GetEc2InstanceDetails added in v0.0.22

func GetEc2InstanceDetails(t testing.TestingT, region, instanceID string) *types.Instance

GetEc2InstanceDetails fetches the details of the instance or fails the test.

func GetEc2InstanceDetailsE added in v0.0.22

func GetEc2InstanceDetailsE(t testing.TestingT, region, instanceID string) (*types.Instance, error)

GetEc2InstanceDetailsE fetches the details of the instance with the given ID.

func GetEc2InstancesByTag added in v0.0.22

func GetEc2InstancesByTag(t testing.TestingT, region, tagName, tagValue string) []types.Instance

GetEc2InstancesByTag fails the test if there is an error.

func GetEc2InstancesByTagE added in v0.0.22

func GetEc2InstancesByTagE(t testing.TestingT, region, tagName, tagValue string) ([]types.Instance, error)

GetEc2InstancesByTagE returns all instances matching the tag filter.

func GetKmsAlias

func GetKmsAlias(t testing.TestingT, region string, aliasName string) types.AliasListEntry

GetKmsAlias gets the KMS alias or panic if not found.

func GetKmsAliasE

func GetKmsAliasE(t testing.TestingT, region string, aliasName string) (*types.AliasListEntry, error)

GetKmsAliasE gets the KMS alias

func GetKmsKey

func GetKmsKey(t testing.TestingT, region string, cmkID string) *types.KeyMetadata

GetKmsKey gets the KMS key

func GetKmsKeyE

func GetKmsKeyE(t testing.TestingT, region string, cmkID string) (*types.KeyMetadata, error)

GetKmsKeyE gets the metadata for KMS Customer Master Key (CMK) in the given region with the given ID. The ID can be an alias, such as as "alias/my-cmk".

func GetKmsKeyPolicy

func GetKmsKeyPolicy(t testing.TestingT, region string, cmkID string) string

GetKmsKeyPolicy gets the key policy document in JSON format.

func GetKmsKeyPolicyE

func GetKmsKeyPolicyE(t testing.TestingT, region string, cmkID string) (*string, error)

GetKmsKeyPolicyE gets the key policy document in JSON format.

func GetLaunchTemplateLatestVersion added in v0.0.22

func GetLaunchTemplateLatestVersion(t testing.TestingT, region, launchTemplateID string) *types.LaunchTemplateVersion

GetLaunchTemplateLatestVersion fetches the "$Latest" version and fails the test if there is an error.

func GetLaunchTemplateLatestVersionE added in v0.0.22

func GetLaunchTemplateLatestVersionE(t testing.TestingT, region, launchTemplateID string) (*types.LaunchTemplateVersion, error)

GetLaunchTemplateLatestVersionE describes the "$Latest" version of the launch template.

func GetLaunchTemplateVersionE added in v0.0.22

func GetLaunchTemplateVersionE(t testing.TestingT, region, launchTemplateID, version string) (*types.LaunchTemplateVersion, error)

GetLaunchTemplateVersionE describes a specific version of the launch template.

func GetLogGroup

func GetLogGroup(t testing.TestingT, awsRegion string, logGroupName string) *logtypes.LogGroup

GetLogGroup returns the details of the specified log group.

func GetLogGroupE

func GetLogGroupE(t testing.TestingT, awsRegion string, logGroupName string) (*logtypes.LogGroup, error)

GetLogGroupE returns the details of the specified log group.

func GetMetricAlarm

func GetMetricAlarm(t testing.TestingT, awsRegion string, alarmName string) *types.MetricAlarm

GetMetricAlarm returns the details of the specified alarm.

func GetMetricAlarmE

func GetMetricAlarmE(t testing.TestingT, awsRegion string, alarmName string) (*types.MetricAlarm, error)

GetMetricAlarmE returns the details of the specified composite alarm.

func GetS3BucketNotificationE

func GetS3BucketNotificationE(t testing.TestingT, region string, bucketName string) (*s3.GetBucketNotificationConfigurationOutput, error)

GetS3BucketNotificationE fetches the given bucket's notification configuration

func GetScalableTargets added in v0.0.24

func GetScalableTargets(t testing.TestingT, region string, serviceNamespace string) []types.ScalableTarget

GetScalableTargets gets the Application Auto Scaling scalable targets for the given service namespace

func GetScalableTargetsByResourceId added in v0.0.24

func GetScalableTargetsByResourceId(t testing.TestingT, region string, serviceNamespace string, resourceId string) []types.ScalableTarget

GetScalableTargetsByResourceId gets scalable targets filtered by resource ID

func GetScalableTargetsByResourceIdE added in v0.0.24

func GetScalableTargetsByResourceIdE(t testing.TestingT, region string, serviceNamespace string, resourceId string) ([]types.ScalableTarget, error)

GetScalableTargetsByResourceIdE gets scalable targets filtered by resource ID

func GetScalableTargetsE added in v0.0.24

func GetScalableTargetsE(t testing.TestingT, region string, serviceNamespace string) ([]types.ScalableTarget, error)

GetScalableTargetsE gets the Application Auto Scaling scalable targets for the given service namespace

func GetScalingPolicies added in v0.0.24

func GetScalingPolicies(t testing.TestingT, region string, serviceNamespace string) []types.ScalingPolicy

GetScalingPolicies gets the Application Auto Scaling scaling policies for the given service namespace

func GetScalingPoliciesE added in v0.0.24

func GetScalingPoliciesE(t testing.TestingT, region string, serviceNamespace string) ([]types.ScalingPolicy, error)

GetScalingPoliciesE gets the Application Auto Scaling scaling policies for the given service namespace

func GetScheduledActions added in v0.0.24

func GetScheduledActions(t testing.TestingT, region string, serviceNamespace string) []types.ScheduledAction

GetScheduledActions gets the Application Auto Scaling scheduled actions for the given service namespace

func GetScheduledActionsByResourceId added in v0.0.24

func GetScheduledActionsByResourceId(t testing.TestingT, region string, serviceNamespace string, resourceId string) []types.ScheduledAction

GetScheduledActionsByResourceId gets scheduled actions filtered by resource ID

func GetScheduledActionsByResourceIdE added in v0.0.24

func GetScheduledActionsByResourceIdE(t testing.TestingT, region string, serviceNamespace string, resourceId string) ([]types.ScheduledAction, error)

GetScheduledActionsByResourceIdE gets scheduled actions filtered by resource ID

func GetScheduledActionsE added in v0.0.24

func GetScheduledActionsE(t testing.TestingT, region string, serviceNamespace string) ([]types.ScheduledAction, error)

GetScheduledActionsE gets the Application Auto Scaling scheduled actions for the given service namespace

func GetStreamResourcePolicy

func GetStreamResourcePolicy(t testing.TestingT, region string, streamArn string) string

GetStreamResourcePolicy returns the Kinesis stream resource policy as a JSON string

func GetStreamResourcePolicyE

func GetStreamResourcePolicyE(t testing.TestingT, region string, streamArn string) (*string, error)

GetStreamResourcePolicy returns the Kinesis stream resource policy as a JSON string or an error

func GetSubscriptionAttributesE added in v0.0.22

func GetSubscriptionAttributesE(t testing.TestingT, region, subArn string) (map[string]string, error)

GetSubscriptionAttributesE fetches the attributes for a subscription ARN using Terratest SNS client.

func GetTableTrackingPolicy added in v0.0.24

func GetTableTrackingPolicy(t testing.TestingT, awsRegion string, resourceId string) *types.ScalingPolicy

GetTableTrackingPolicy gets the target tracking policy for a DynamoDB table or errors if not found

func GetTableTrackingPolicyE added in v0.0.24

func GetTableTrackingPolicyE(t testing.TestingT, awsRegion string, resourceId string) (*types.ScalingPolicy, error)

GetTableTrackingPolicy gets the target tracking policy for a DynamoDB table or returns an error if not found

func GetTestItem added in v0.0.25

func GetTestItem(t *testing.T, client *dynamodb.Client, tableName, partitionKeyName, itemId string) dynamoDBTestItem

GetTestItem retrieves a standard test item from the specified table and returns it.

func InvokeFunctionSync added in v0.1.5

func InvokeFunctionSync(t testing.TestingT, region, functionName string) *terratestaws.LambdaOutput

InvokeFunctionSync invokes a lambda function synchronously. Keep the connection open until the function returns a response or times out. Checks for failure using "require".

func InvokeFunctionWithParams

func InvokeFunctionWithParams(t testing.TestingT, region, functionName string, input *LambdaOptions) *terratestaws.LambdaOutput

InvokeFunctionWithParams invokes a lambda function using parameters supplied in the LambdaOptions struct and returns values in a LambdaOutput struct. Checks for failure using "require".

func InvokeFunctionWithParamsE

func InvokeFunctionWithParamsE(t testing.TestingT, region, functionName string, input *LambdaOptions) (*terratestaws.LambdaOutput, error)

InvokeFunctionWithParamsE invokes a lambda function using parameters supplied in the LambdaOptions struct. Returns the status code and payload in a LambdaOutput struct and the error. A non-nil error will either reflect a problem with the parameters supplied to this function or an error returned by the Lambda.

func LoadOutputAttribute

func LoadOutputAttribute(t *testing.T, terraformOptions *terraform.Options, key, attribute string) string

LoadOutputAttribute loads the attribute of a output key from Terraform outputs and ensures it is not empty.

func LoadSynthDependencies

func LoadSynthDependencies(t *testing.T, testFolder string, dependencies *map[string]string)

LoadSynthDependencies reads a saved map of dependencies at synth time to the given path.

func MakeDynamoDBStringKey added in v0.0.25

func MakeDynamoDBStringKey(keyName, keyValue string) map[string]types.AttributeValue

MakeDynamoDBStringKey creates a simple DynamoDB key map for a single string attribute. This is a convenience helper to avoid boilerplate in tests.

func NewApplicationAutoScalingClient added in v0.0.24

func NewApplicationAutoScalingClient(t testing.TestingT, region string) *applicationautoscaling.Client

NewApplicationAutoScalingClient creates a new Application Auto Scaling client

func NewApplicationAutoScalingClientE added in v0.0.24

func NewApplicationAutoScalingClientE(t testing.TestingT, region string) (*applicationautoscaling.Client, error)

NewApplicationAutoScalingClientE creates a new Application Auto Scaling client

func NewCloudFrontclient

func NewCloudFrontclient(t testing.TestingT) *cloudfront.Client

NewCloudFrontclient returns a client for CloudFront. This will fail the test and stop execution if there is an error.

func NewCloudFrontclientE

func NewCloudFrontclientE(t testing.TestingT) (*cloudfront.Client, error)

NewCloudFrontclientE returns a client for CloudFront.

func NewCloudWatchClient

func NewCloudWatchClient(t testing.TestingT, region string) *cloudwatch.Client

NewCloudWatchEventsClient creates a new CloudWatch Events client.

func NewCloudWatchClientE

func NewCloudWatchClientE(t testing.TestingT, region string) (*cloudwatch.Client, error)

NewCloudWatchEventsClientE creates a new CloudWatch Logs client.

func NewCloudWatchEventsClient

func NewCloudWatchEventsClient(t testing.TestingT, region string) *cloudwatchevents.Client

NewCloudWatchEventsClient creates a new CloudWatch Events client.

func NewCloudWatchEventsClientE

func NewCloudWatchEventsClientE(t testing.TestingT, region string) (*cloudwatchevents.Client, error)

NewCloudWatchEventsClientE creates a new CloudWatch Logs client.

func NewEc2Client added in v0.0.22

func NewEc2Client(t testing.TestingT, region string) *ec2.Client

NewEc2Client returns a client for EC2 in the given region or fails the test.

func NewEc2ClientE added in v0.0.22

func NewEc2ClientE(t testing.TestingT, region string) (*ec2.Client, error)

NewEc2ClientE returns a client for EC2 in the given region.

func NewEventBridgeClient

func NewEventBridgeClient(t testing.TestingT, region string) *eventbridge.Client

NewEventBridgeClient creates an RDS client.

func NewEventBridgeClientE

func NewEventBridgeClientE(t testing.TestingT, region string) (*eventbridge.Client, error)

NewEventBridgeClientE creates an RDS client.

func NewKinesisClient

func NewKinesisClient(t testing.TestingT, region string) *kinesis.Client

NewKinesisClient creates a kinesis client.

func NewKinesisClientE

func NewKinesisClientE(t testing.TestingT, region string) (*kinesis.Client, error)

NewKinesisClientE creates a kinesis client.

func NewSfnclient

func NewSfnclient(t testing.TestingT, awsRegion string) *sfn.Client

NewSfnclient returns a client for StepFunctions. This will fail the test if there is an error.

func NewSfnclientE

func NewSfnclientE(t testing.TestingT, awsRegion string) (*sfn.Client, error)

NewSfnclientE returns a client for StepFunctions.

func ParseFilterPolicy added in v0.0.22

func ParseFilterPolicy(raw string) (map[string]interface{}, error)

ParseFilterPolicy parses a FilterPolicy JSON string into a map for assertions.

func PingHost added in v0.0.22

func PingHost(t testing.TestingT, host string, timeout time.Duration)

PingHost performs an ICMP ping to the specified host and fails the test if it doesn't respond.

func PingHostE added in v0.0.22

func PingHostE(t testing.TestingT, host string, timeout time.Duration) error

PingHostE performs an ICMP ping to the specified host using the system ping command. This approach is simpler than raw ICMP sockets since the ping command has setuid permissions on most Unix systems, avoiding privilege requirements.

func PrettyPrintBeforeAfter

func PrettyPrintBeforeAfter(before interface{}, after interface{}) (string, error)

func PrettyPrintResourceChange

func PrettyPrintResourceChange(rc *tfjson.ResourceChange) (string, error)

func PublishMessage added in v0.0.22

func PublishMessage(t testing.TestingT, region, topicArn, body string, attrs map[string]types.MessageAttributeValue)

PublishMessage publishes a message to an SNS Topic, failing the test on error.

func PublishMessageE added in v0.0.22

func PublishMessageE(t testing.TestingT, region, topicArn, body string, attrs map[string]types.MessageAttributeValue) error

PublishMessageE publishes a message to an SNS topic with attributes, using Terratest SNS client.

func PutDynamoDbItemWithRole added in v0.0.25

func PutDynamoDbItemWithRole(t *testing.T, client *dynamodb.Client, tableName string, item interface{})

PutDynamoDbItemWithRole puts an item into a DynamoDB table using the given client. The item is a struct that will be marshalled into a DynamoDB attribute map.

func PutEvents

func PutEvents(t testing.TestingT, region string, entries []types.PutEventsRequestEntry)

PutEvents sends custom events to Amazon EventBridge so that they can be matched to rules.

func PutEventsE

func PutEventsE(t testing.TestingT, region string, entries []types.PutEventsRequestEntry) error

PutEventsE sends custom events to Amazon EventBridge so that they can be matched to rules.

func PutTestItem added in v0.0.25

func PutTestItem(t *testing.T, client *dynamodb.Client, tableName, itemId, itemContent string)

PutTestItem creates a standard test item with the given ID and content and puts it into the specified table.

func ReplaceTerraformResource added in v0.1.1

func ReplaceTerraformResource(t *testing.T, workingDir, resourceType, resourceName string)

ReplaceTerraformResource replaces a Terraform resource in the given working directory by running a terraform apply command with the -replace flag. This is useful for triggering a re-deployment of a resource without changing its configuration. It fails the test if the resource cannot be found or if the apply command fails.

func SaveSynthDependencies

func SaveSynthDependencies(t *testing.T, testFolder string, dependencies *map[string]string)

SaveSynthDependencies serializes and saves map of dependencies at test time to the given path.

func SendMessageFifoToQueueWithDeduplicationId

func SendMessageFifoToQueueWithDeduplicationId(t testing.TestingT, awsRegion string, queueURL string, message string, messageGroupID string, messageDeduplicationId string)

SendMessageToFifoQueue sends the given message to the FIFO SQS queue with the given URL.

func SendMessageToFifoQueueWithDeduplicationIdE

func SendMessageToFifoQueueWithDeduplicationIdE(t testing.TestingT, awsRegion string, queueURL string, message string, messageGroupID string, messageDeduplicationId string) error

SendMessageToFifoQueueWithDeduplicationIdE sends the given message to the FIFO SQS queue with the given URL.

func StartSfnExecution

func StartSfnExecution(t testing.TestingT, awsRegion string, stateMachineArn string, input interface{}) *string

StartSfnExecution starts a new execution of the specified state machine and returns the execution ARN. This will fail the test if there is an error.

func StartSfnExecutionE

func StartSfnExecutionE(t testing.TestingT, awsRegion string, stateMachineArn string, input interface{}) (*string, error)

StartSfnExecutionE starts a new execution of the specified state machine and returns the execution ARN.

func StopSfnExecution

func StopSfnExecution(t testing.TestingT, awsRegion string, executionArn string)

StopSfnExecution stops the specified execution. This will fail the test if there is an error.

func StopSfnExecutionE

func StopSfnExecutionE(t testing.TestingT, awsRegion string, executionArn string) error

StopSfnExecutionE stops the specified execution.

func SynthApp

func SynthApp(t *testing.T, testApp, tfWorkingDir string, env map[string]string, additionalAsset ...string)

Synth app relative to the integration namespace

func TestCloudFrontFunction

func TestCloudFrontFunction(t testing.TestingT, name string, stage string, event CloudFrontFunctionEvent, expectedError string, expectedOutput *map[string]interface{}) error

Tests a CloudFront function.

To test a function, you provide an event object that represents an HTTP request or response that your CloudFront distribution could receive in production. CloudFront runs the function, passing it the event object that you provided, and returns the function's result (the modified event object) in the response. The response also contains function logs and error messages, if any exist. For more information about testing functions, see Testing functionsin the Amazon CloudFront Developer Guide.

To test a function, you provide the function's name and stage (DEVELOPMENT or LIVE) along with the event object. To get the function's name and version, you can use ListFunctions and DescribeFunction.

func TestCloudFrontFunctionWithCustomValidation

func TestCloudFrontFunctionWithCustomValidation(t testing.TestingT, name string, stage string, event CloudFrontFunctionEvent, validateResponse responseValidator) error

TestCloudFrontFunctionWithCustomValidation performs a Function test and validate the response. Fails the test if there is an error.

func TestCloudFrontFunctionWithCustomValidationE

func TestCloudFrontFunctionWithCustomValidationE(t testing.TestingT, name string, stage types.FunctionStage, event CloudFrontFunctionEvent, validateResponse responseValidator) error

TestCloudFrontFunctionWithCustomValidationE performs a Function test and validate the response.

func URLDecode

func URLDecode(encoded string) (string, error)

URLDecode decodes a URL-encoded string.

func UndeployUsingTerraform

func UndeployUsingTerraform(t *testing.T, workingDir string)

func UploadS3File

func UploadS3File(t testing.TestingT, awsRegion string, s3BucketName string, key string, body string)

UploadS3File uploads a file to the given S3 bucket with the given key and body and fails the test if there is any error.

func UploadS3FileE

func UploadS3FileE(t testing.TestingT, awsRegion string, s3BucketName string, key string, body string) error

UploadS3FileE uploads a file to the given S3 bucket with the given key and body and returns an error if there is any.

func WaitForCertificateIssued

func WaitForCertificateIssued(
	t testing.TestingT,
	certArn string,
	region string,
	maxRetries int,
	sleepBetweenRetries time.Duration,
)

WaitForCertificateIssued waits for the certificate to be issued

func WaitForCertificateIssuedE

func WaitForCertificateIssuedE(
	t testing.TestingT,
	certArn string,
	region string,
	maxRetries int,
	sleepBetweenRetries time.Duration,
) error

WaitForCertificateIssuedE waits for the ACM Certificate to be issued

func WaitForDistributionDeployed added in v0.0.10

func WaitForDistributionDeployed(t testing.TestingT, region string, distributionId string, maxRetries int, sleepBetweenRetries time.Duration)

WaitForDistributionDeployed waits for a CloudFront distribution to be deployed.

func WaitForDistributionStatus added in v0.0.10

func WaitForDistributionStatus(
	t testing.TestingT,
	region string,
	distributionId string,
	status string,
	maxRetries int,
	sleepBetweenRetries time.Duration,
)

WaitForDistributionStatus waits for a CloudFront distribution to have the specified status.

func WaitForDistributionStatusE added in v0.0.10

func WaitForDistributionStatusE(
	t testing.TestingT,
	region string,
	distributionId string,
	status string,
	maxRetries int,
	sleepBetweenRetries time.Duration,
) error

WaitForDistributionStatusE waits for a CloudFront distribution to have the specified status.

func WaitForEc2InstanceRunning added in v0.0.22

func WaitForEc2InstanceRunning(t testing.TestingT, region, instanceID string, maxRetries int, sleepBetweenRetries time.Duration)

WaitForEc2InstanceRunning waits for the instance to be in the running state.

func WaitForEc2InstanceStateE added in v0.0.22

func WaitForEc2InstanceStateE(t testing.TestingT, region, instanceID string, desired types.InstanceStateName, maxRetries int, sleepBetweenRetries time.Duration) error

WaitForEc2InstanceStateE waits until the instance reaches the desired state.

func WaitForLogEvents

func WaitForLogEvents(
	t testing.TestingT,
	awsRegion string,
	logGroupName string,
	maxRetries int,
	sleepBetweenRetries time.Duration,
) []string

WaitForLogEvents waits for log events to appear in the given CloudWatch Log group in the given region

func WaitForLogEventsE

func WaitForLogEventsE(
	t testing.TestingT,
	awsRegion string,
	logGroupName string,
	maxRetries int,
	sleepBetweenRetries time.Duration,
) ([]string, error)

WaitForLogEventsE waits for log events to appear in the given CloudWatch Log group in the given region

func WaitForStreamActive

func WaitForStreamActive(
	t testing.TestingT,
	region string,
	streamName string,
	maxRetries int,
	sleepBetweenRetries time.Duration,
)

WaitForStreamActive waits for a Kinesis stream to be active.

func WaitForStreamActiveE

func WaitForStreamActiveE(
	t testing.TestingT,
	region string,
	streamName string,
	maxRetries int,
	sleepBetweenRetries time.Duration,
) error

WaitForStreamActiveE waits for a Kinesis stream to be active.

func WaitForStreamStatus

func WaitForStreamStatus(
	t testing.TestingT,
	region string,
	streamName string,
	status types.StreamStatus,
	maxRetries int,
	sleepBetweenRetries time.Duration,
)

WaitForStreamStatus waits for a Kinesis stream to have the specified status.

func WaitForStreamStatusE

func WaitForStreamStatusE(
	t testing.TestingT,
	region string,
	streamName string,
	status types.StreamStatus,
	maxRetries int,
	sleepBetweenRetries time.Duration,
) error

WaitForStreamStatusE waits for a Kinesis stream to have the specified status.

Types

type ActivityHandler

type ActivityHandler interface {
	// Input returns the input data of the activity.
	Input() interface{}
	// SendSuccess sends a success message to the State Machine.
	SendSuccess(output interface{}) error
	// SendFailure sends a failure message to the State Machine.
	SendFailure(errCode string, cause string) error
	// SendHeartbeat sends a heartbeat message to the State Machine.
	SendHeartbeat() error
}

func GetSfnActivity

func GetSfnActivity(t testing.TestingT, awsRegion string, activityArn string, workerName *string) ActivityHandler

GetSfnActivity for a running Sate Machine. Used by workers to retrieve a task (with the specified activity ARN) which has been scheduled for execution by a running state machine.

func GetSfnActivityE

func GetSfnActivityE(t testing.TestingT, awsRegion string, activityArn string, workerName *string) (ActivityHandler, error)

GetSfnActivityE for a running Sate Machine. Used by workers to retrieve a task (with the specified activity ARN) which has been scheduled for execution by a running state machine.

func NewActivityHandler

func NewActivityHandler(sfnClient *sfn.Client, input interface{}, taskToken *string) ActivityHandler

type AttachedPermissionsBoundary

type AttachedPermissionsBoundary struct {
	PermissionsBoundaryArn  string `json:"permissionsBoundaryArn"`  // The ARN of the policy used to set the permissions boundary for the user or role.
	PermissionsBoundaryType string `json:"permissionsBoundaryType"` // The permissions boundary usage type that indicates what type of IAM resource is used as the permissions boundary for an entity. This data type can only have a value of Policy.
}

type BucketNotificationNotEnabledError

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

BucketNotificationNotEnabledError is returned when the S3 bucket notification is not enabled.

func NewBucketNotificationNotEnabledError

func NewBucketNotificationNotEnabledError(region, bucketName string) BucketNotificationNotEnabledError

func (BucketNotificationNotEnabledError) Error

type CertificateNotIssuedError

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

CertificateNotIssuedError is returned when the ACM Certificate status is not issued.

func NewCertificateNotIssuedError

func NewCertificateNotIssuedError(certArn string, currentStatus acmTypes.CertificateStatus) CertificateNotIssuedError

func (CertificateNotIssuedError) Error

func (err CertificateNotIssuedError) Error() string

type CloudFrontFunctionEvent

type CloudFrontFunctionEvent struct {
	Version  Version   `json:"version"` // The version field contains a string that specifies the version of the CloudFront Functions event object. The current version is 1.0.
	Context  Context   `json:"context"` // The context object contains contextual information about the event
	Viewer   Viewer    `json:"viewer"`
	Request  *Request  `json:"request,omitempty"`
	Response *Response `json:"response,omitempty"`
}

CloudFrontFunctionEvent represents the event object that you provide to test a CloudFront function. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html

func ReadCloudFrontEvent

func ReadCloudFrontEvent(path string) (*CloudFrontFunctionEvent, error)

type CloudFrontFunctionValidationFailed

type CloudFrontFunctionValidationFailed struct {
	FunctionName string
	Failures     error
}

CloudFrontFunctionValidationFailed is an error that occurs if response validation fails.

func (CloudFrontFunctionValidationFailed) Error

type CloudFrontTestFunctionResult

type CloudFrontTestFunctionResult struct {
	Utilization  int // The amount of time that the function took to run as a percentage of the maximum allowed time.
	ErrorMessage *string
	// The event object returned by the function. For more information about the
	// structure of the event object, see [Event object structure]in the Amazon CloudFront Developer Guide.
	//
	// [Event object structure]: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html
	Output map[string]interface{}
	// Contains the log lines that the function wrote (if any) when running the test.
	ExecutionLogs []string
}

func TestCloudFrontFunctionE

func TestCloudFrontFunctionE(t testing.TestingT, name string, stage types.FunctionStage, event CloudFrontFunctionEvent) (*CloudFrontTestFunctionResult, error)

TestCloudFrontFunctionE performs a Function test and validates the response.

type CloudwatchEventsRuleInfo

type CloudwatchEventsRuleInfo struct {
	Name               string               // The name of the rule.
	Description        string               // The description of the rule.
	State              eventtypes.RuleState // Specifies whether the rule is enabled or disabled.
	EventPattern       string               // The event pattern.
	ScheduleExpression string               // The scheduling expression. For example, "cron(0 20 * * ? *)", "rate(5 minutes)".
}

func DescribeEventRule

func DescribeEventRule(t testing.TestingT, awsRegion string, ruleName string) *CloudwatchEventsRuleInfo

DescribeEventRule returns the details of the specified rule.

func DescribeEventRuleE

func DescribeEventRuleE(t testing.TestingT, awsRegion string, ruleName string) (*CloudwatchEventsRuleInfo, error)

DescribeEventRuleE returns the details of the specified rule.

type Context

type Context struct {
	DistributionDomainName string `json:"distributionDomainName"` // The CloudFront domain name (for example, d111111abcdef8.cloudfront.net) of the distribution that's associated with the event.
	DistributionID         string `json:"distributionId"`
	EventType              string `json:"eventType"`
	RequestID              string `json:"requestId"`
}

type ForwardingCore

type ForwardingCore struct {
	zapcore.Core
	// contains filtered or unexported fields
}

a simple Zap Logger which forwards all log messages to terratestLogger

func (*ForwardingCore) Check

func (*ForwardingCore) Write

func (fc *ForwardingCore) Write(entry zapcore.Entry, fields []zapcore.Field) error

type IamManagedPolicyNotFoundError

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

IamManagedPolicyNotFoundError is returned when the IAM managed policy is not found.

func NewIamManagedPolicyNotFoundError

func NewIamManagedPolicyNotFoundError(policyArn string) IamManagedPolicyNotFoundError

func (IamManagedPolicyNotFoundError) Error

type IamRoleNotFoundError

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

IamRoleNotFoundError is returned when the IAM role is not found.

func NewIamRoleNotFoundError

func NewIamRoleNotFoundError(roleName string) IamRoleNotFoundError

func (IamRoleNotFoundError) Error

func (err IamRoleNotFoundError) Error() string

type InlinePolicy

type InlinePolicy struct {
	PolicyDocument string `json:"policyDocument"` // The policy document.
	PolicyName     string `json:"policyName"`     // The name of the policy.
}

Contains decoded inline document and policy name

type InvocationTypeOption

type InvocationTypeOption string

TODO: PR "Event" Invocation Type support to terratest upstream ref: https://github.com/gruntwork-io/terratest/pull/817

const (
	InvocationTypeRequestResponse InvocationTypeOption = "RequestResponse"
	InvocationTypeDryRun          InvocationTypeOption = "DryRun"
	InvocationTypeEvent           InvocationTypeOption = "Event"
)

func (*InvocationTypeOption) Value

func (itype *InvocationTypeOption) Value() (string, error)

type LambdaOptions

type LambdaOptions struct {
	// InvocationType can be one of InvocationTypeOption values:
	//    * InvocationTypeRequestResponse (default) - Invoke the function
	//      synchronously.  Keep the connection open until the function
	//      returns a response or times out.
	//    * InvocationTypeDryRun - Validate parameter values and verify
	//      that the user or role has permission to invoke the function.
	//    * InvocationTypeEvent – Invoke the function asynchronously.
	//      Send events that fail multiple times to the function's
	//      dead-letter queue (if one is configured). The API response
	//      only includes a status code.
	InvocationType *InvocationTypeOption

	// Lambda function input; will be converted to JSON.
	Payload interface{}
}

LambdaOptions contains additional parameters for InvokeFunctionWithParams(). It contains a subset of the fields found in the lambda.InvokeInput struct.

type ManagedPolicy

type ManagedPolicy struct {
	Arn                           string      `json:"arn"`                           // The Amazon Resource Name (ARN).
	PolicyDocument                string      `json:"policyDocument"`                // The policy document.
	AttachmentCount               int32       `json:"attachmentCount"`               // The number of entities (users, groups, and roles) that the policy is attached to.
	CreateDate                    time.Time   `json:"createDate"`                    // The date and time, in ISO 8601 date-time format, when the policy was created.
	DefaultVersionId              string      `json:"defaultVersionId"`              // The identifier for the version of the policy that is set as the default version.
	Description                   string      `json:"description"`                   // A friendly description of the policy.
	IsAttachable                  bool        `json:"isAttachable"`                  // Specifies whether the policy can be attached to an IAM user, group, or role.
	Path                          string      `json:"path"`                          // The path to the policy.
	PermissionsBoundaryUsageCount int32       `json:"permissionsBoundaryUsageCount"` // The number of entities (users and roles) for which the policy is used to set the permissions boundary.
	PolicyId                      string      `json:"policyId"`                      // The stable and unique string identifying the policy.
	PolicyName                    string      `json:"policyName"`                    // The friendly name (not ARN) identifying the policy.
	Tags                          []types.Tag `json:"tags"`                          // A list of tags that are attached to the instance profile.
	UpdateDate                    time.Time   `json:"updateDate"`                    // The date and time, in ISO 8601 date-time format, when the policy was last updated.
}

Contains information about a managed policy.

func GetIamManagedPolicy

func GetIamManagedPolicy(t testing.TestingT, awsRegion string, policyArn string) *ManagedPolicy

Get IAM Managed Policy, fail on error

func GetIamManagedPolicyE

func GetIamManagedPolicyE(t testing.TestingT, awsRegion string, policyArn string) (*ManagedPolicy, error)

Get IAM Managed Policy, return result or error

type MultiValue

type MultiValue struct {
	Value string `json:"value"`
}

type MultiValueAttrs

type MultiValueAttrs struct {
	Value      string `json:"value"`
	Attributes string `json:"attributes"`
}

type QueueMessageResponse

type QueueMessageResponse struct {
	ReceiptHandle           string
	MessageBody             string
	ApproximateReceiveCount int64
	SentTimestamp           time.Time
	Error                   error
}

QueueMessageResponse contains a queue message.

func WaitForQueueMessage

func WaitForQueueMessage(t testing.TestingT, awsRegion string, queueURL string, timeout int) QueueMessageResponse

WaitForQueueMessage waits to receive a message from on the queueURL. Since the API only allows us to wait a max 20 seconds for a new message to arrive, we must loop TIMEOUT/20 number of times to be able to wait for a total of TIMEOUT seconds

type Request

type Request struct {
	Method      string      `json:"method"`
	URI         string      `json:"uri"`
	Querystring ValueObject `json:"querystring"`
	Headers     ValueObject `json:"headers"`
	Cookies     ValueObject `json:"cookies,omitempty"`
}

type Response

type Response struct {
	StatusCode        int             `json:"statusCode"`
	StatusDescription *string         `json:"statusDescription,omitempty"`
	Headers           *ValueObject    `json:"headers,omitempty"`
	Cookies           *ResponseCookie `json:"cookies,omitempty"`
}

type ResponseCookie

type ResponseCookie map[string]ResponseCookieEntry

type ResponseCookieEntry

type ResponseCookieEntry struct {
	Value      string            `json:"value"`
	Attributes string            `json:"attributes"`
	MultiValue []MultiValueAttrs `json:"multiValue,omitempty"`
}

type Role

type Role struct {
	Arn                      string                      `json:"arn"`                      // The Amazon Resource Name (ARN) specifying the role.
	AssumeRolePolicyDocument string                      `json:"assumeRolePolicyDocument"` // The policy that grants an entity permission to assume the role.
	CreateDate               time.Time                   `json:"createDate"`               // The date and time, in ISO 8601 date-time format, when the role was created.
	Description              string                      `json:"description"`              // A description of the role that you provide.
	MaxSessionDuration       int32                       `json:"maxSessionDuration"`       // The maximum session duration (in seconds) for the specified role.
	Path                     string                      `json:"path"`                     // The path to the role.
	PermissionsBoundary      AttachedPermissionsBoundary `json:"permissionsBoundary"`      // The ARN of the policy used to set the permissions boundary for the role.
	RoleId                   string                      `json:"roleId"`                   // The stable and unique string identifying the role.
	RoleLastUsed             types.RoleLastUsed          `json:"roleLastUsed"`             // Contains information about the last time that an IAM role was used.
	RoleName                 string                      `json:"roleName"`                 // The friendly name that identifies the role.
	InlinePolicies           []InlinePolicy              `json:"inlinePolicies"`           // The inline policies of the IAM role.
	AttachedPolicyArns       []string                    `json:"attachedPolicyArns"`       // The Amazon Resource Names (ARNs) of the managed policies attached to the role.
	Tags                     []types.Tag                 `json:"tags"`                     // A list of tags that are attached to the role.
}

IAM Role struct with Inline Policies and Attached Policy ARNs

func GetIamRole

func GetIamRole(t testing.TestingT, awsRegion string, roleName string) *Role

Get IAM Role with all inline policies and attached Policy ARNs, fail on error

func GetIamRoleE

func GetIamRoleE(t testing.TestingT, awsRegion string, roleName string) (*Role, error)

Get IAM Role with all inline policies and attached Policy ARNs, return result or error

type SfnExecutionOutput

type SfnExecutionOutput struct {
	// The current status of the execution.
	Status types.ExecutionStatus
	// The cause string if the state machine execution failed.
	Cause string
	// The error string if the state machine execution failed.
	Error string
	// The JSON output data of the execution. Length constraints apply to the payload
	// size, and are expressed as bytes in UTF-8 encoding.
	//
	// This field is set only if the execution succeeds. If the execution fails, this
	// field is the string Zero value ("").
	Output string
}

ExecutionOutput contains the result of the SateMachine Execution.

func WaitForSfnExecutionStatus

func WaitForSfnExecutionStatus(
	t testing.TestingT,
	awsRegion string,
	executionArn string,
	status types.ExecutionStatus,
	maxRetries int,
	sleepBetweenRetries time.Duration,
) *SfnExecutionOutput

WaitForSfnExecutionStatus waits for the specified execution to reach the desired status. This will fail the test if there is an error.

Executions of an EXPRESS state machine aren't supported by DescribeExecution unless a Map Run dispatched them.

func WaitForSfnExecutionStatusE

func WaitForSfnExecutionStatusE(
	t testing.TestingT,
	awsRegion string,
	executionArn string,
	status types.ExecutionStatus,
	maxRetries int,
	sleepBetweenRetries time.Duration,
) (*SfnExecutionOutput, error)

WaitForSfnExecutionStatusE waits for the specified execution to reach the desired status. this will throw error on timeout or non-retryable Errors.

type ValueEntry

type ValueEntry struct {
	Value      string       `json:"value"`
	MultiValue []MultiValue `json:"multiValue,omitempty"`
}

type ValueObject

type ValueObject map[string]ValueEntry

type Variables

type Variables map[string]any

func (*Variables) Apply

func (p *Variables) Apply(contents string) (string, error)

apply the variables to the test app

type Version

type Version string
const Version1_0 Version = "1.0"

func (Version) MarshalJSON

func (v Version) MarshalJSON() ([]byte, error)

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(data []byte) error

type Viewer

type Viewer struct {
	IP string `json:"ip"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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