cloudtest

package
v3.0.0-...-bcda2dc Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsSuccess = func(values map[MetricName][]*float64) (bool, error) {

	invocationsTotal := func(values []*float64) float64 {
		totalAgg := float64(0)
		for _, eachValue := range values {
			totalAgg += *eachValue
		}
		return totalAgg
	}

	errorChecks := []MetricName{MetricNameErrors, MetricNameDeadLetterErrors}
	for _, eachErr := range errorChecks {
		errValues := values[eachErr]
		totalAggregateValue := invocationsTotal(errValues)
		if totalAggregateValue != 0 {
			return true, errors.Errorf("At least one %s found for invocation. Count: %f",
				eachErr,
				totalAggregateValue)
		}
	}

	if len(values[MetricNameInvocations]) > 0 {
		return true, nil
	}

	return false, nil
}

IsSuccess is the default evaluator to see if a set of Lambda metrics indicate a successful result

Functions

func DefaultLambdaFunctionMetricQueries

func DefaultLambdaFunctionMetricQueries() []*awsv2CWTypes.MetricDataQuery

DefaultLambdaFunctionMetricQueries is the standard set of queries to issue to determine in a Lambda successfully executed

func IsJMESMatch

func IsJMESMatch(jmesSelector string, output *awsv2Lambda.GetFunctionOutput) (bool, error)

IsJMESMatch is a function that accepts a GetFunctionOutput and a JMES selector expression. The return value is (isMatch, error). It's exposed as a package public to allow for callers to write their own providers

func NewLambdaFunctionMetricQuery

func NewLambdaFunctionMetricQuery(invocationMetricName MetricName) *awsv2CWTypes.MetricDataQuery

NewLambdaFunctionMetricQuery returns a awsv2CW.MetricDataQuery that will be lazily completed in the Evaluation function

Types

type CloudEvaluator

type CloudEvaluator interface {
	Evaluate(CloudTest, *awsv2Lambda.GetFunctionOutput) error
}

CloudEvaluator is the interface used to represent a predicate applied to a function output

func NewLambdaInvocationMetricEvaluator

func NewLambdaInvocationMetricEvaluator(queries []awsv2CWTypes.MetricDataQuery,
	metricEvaluator MetricEvaluator) CloudEvaluator

NewLambdaInvocationMetricEvaluator needs a list of awsv2CW.MetricDataQuery results that need the FunctionName. Then the evaluation will take a map of metrics to values.

func NewLogOutputEvaluator

func NewLogOutputEvaluator(matcher *regexp.Regexp) CloudEvaluator

NewLogOutputEvaluator returns a CloudEvaluator that scans CloudWatchLogs for a given regexp pattern

func NewTimedNOPEvaluator

func NewTimedNOPEvaluator(timeout time.Duration) CloudEvaluator

NewTimedNOPEvaluator returns a NOP evaluator to ensure the test always passes

type CloudTest

type CloudTest interface {
	testing.TB
	Config() awsv2.Config
	ZeroLog() *zerolog.Logger
	Context() context.Context
}

CloudTest is the interface passed to testing instances

type LambdaSelector

type LambdaSelector interface {
	Select(CloudTest) (*awsv2Lambda.GetFunctionOutput, error)
}

LambdaSelector is the interface that provides the awsv2Lambda.GetFunctionOutput that will be used for the test

func NewLambdaLiteralSelector

func NewLambdaLiteralSelector(functionName string) LambdaSelector

NewLambdaLiteralSelector returns a new LambdaSelector that just uses the hardcoded name

func NewStackLambdaSelector

func NewStackLambdaSelector(stackName string, jmesSelector string) LambdaSelector

NewStackLambdaSelector returns a new LambdaSelector using the jmesSelector expression against all GetFunctionOutputs for that lambda function

type MetricEvaluator

type MetricEvaluator func(map[MetricName][]float64) (bool, error)

MetricEvaluator returns whether the evaluatoin should continue or an error occurred.

type MetricName

type MetricName string

MetricName is tha alias type for the reserved Lambda invocation metrics defined at https://docs.awsv2.amazon.com/lambda/latest/dg/monitoring-metrics.html

const (
	// MetricNameInvocations is the Lambda invocation
	MetricNameInvocations MetricName = "Invocations"
	// MetricNameErrors is the number of invocations that result in a function error
	MetricNameErrors MetricName = "Errors"
	// MetricNameDeadLetterErrors the number of times Lambda attempts to send an event to a
	// dead-letter queue but fails
	MetricNameDeadLetterErrors MetricName = "DeadLetterErrors"
	// MetricNameDestinationDeliveryFailures the number of times Lambda attempts
	// to send an event to a destination but fails
	MetricNameDestinationDeliveryFailures MetricName = "DestinationDeliveryFailures"
	// MetricNameThrottles is the number of invocation requests that are throttled
	MetricNameThrottles MetricName = "Throttles"
	// MetricNameProvisionedConcurrencyInvocations is the number of times your
	// function code is executed on provisioned concurrency.
	MetricNameProvisionedConcurrencyInvocations MetricName = "ProvisionedConcurrencyInvocations"
	// MetricNameProvisionedConcurrencySpilloverInvocations is the number of times
	// your function code is executed on standard concurrency when all provisioned
	// concurrency is in use
	MetricNameProvisionedConcurrencySpilloverInvocations MetricName = "ProvisionedConcurrencySpilloverInvocations"
)

type Test

type Test struct {
}

Test is the initial type used to build up a Lambda integration test

func NewTest

func NewTest() *Test

NewTest returns a Test pointer

func (*Test) Given

func (ct *Test) Given(trigger Trigger) *TestTrigger

Given associates the provided Mutator with the Test

type TestEvaluator

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

TestEvaluator is the type that stores the Trigger and LambdaSelector

func (*TestEvaluator) Ensure

func (cte *TestEvaluator) Ensure(evaluators ...CloudEvaluator) *TestScenario

Ensure applies the predicates to the results of the Lambda function and returns a TestScenario instance

type TestScenario

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

TestScenario is the final type that encapsulates all the state associated with a given test

func (*TestScenario) Run

func (cts *TestScenario) Run(t *testing.T)

Run actually runs the test in question

func (*TestScenario) Within

func (cts *TestScenario) Within(duration time.Duration)

Within sets the timeout for the test

type TestTrigger

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

TestTrigger is the intermediate type that stores the Trigger reference

func (*TestTrigger) Against

func (ct *TestTrigger) Against(selector LambdaSelector) *TestEvaluator

Against accepts the selector against the provided Trigger and returns a TestEvaluator

type Trigger

type Trigger interface {
	Send(CloudTest, *awsv2Lambda.GetFunctionOutput) (interface{}, error)
	Cleanup(CloudTest, *awsv2Lambda.GetFunctionOutput)
}

Trigger is the interface that represents a struct that can trigger an event

func NewLambdaInvokeTrigger

func NewLambdaInvokeTrigger(event []byte) Trigger

NewLambdaInvokeTrigger returns a Trigger instance that directly invokes a Lambda function

func NewNOPTrigger

func NewNOPTrigger() Trigger

NewNOPTrigger is an empty trigger that does nothing

func NewS3FileMessageTrigger

func NewS3FileMessageTrigger(s3Bucket string, s3Key string, localFilePath string) Trigger

NewS3FileMessageTrigger returns an S3 Trigger that posts a payload to the given bucket, key

func NewS3MessageTrigger

func NewS3MessageTrigger(s3Bucket string, s3Key string, body io.ReadSeeker) Trigger

NewS3MessageTrigger returns an S3 Trigger that posts a payload to the given bucket, key

func NewSQSMessageTrigger

func NewSQSMessageTrigger(sqsURL string, messageBody string) Trigger

NewSQSMessageTrigger is a trigger that submits a message to an SQS URL

Jump to

Keyboard shortcuts

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