Testing

Unit Tests

While developing Sparta lambda functions it may be useful to test them locally without needing to provision each new code change. You can test your lambda functions using standard go test functionality.

To create proper event types, consider:

Acceptance Tests

The cloudtest package provides a BDD-style interface to represent tests that verify Lambda behavior that is asynchronously triggered. For instance, to verify that a direct LambdaInvocation with a known payload also produces a known CloudWatch log output:

func TestCloudLiteralLogOutputTest(t *testing.T) {
  NewTest().
    Given(NewLambdaInvokeTrigger(helloWorldJSON)).
    Against(NewLambdaLiteralSelector(fmt.Sprintf("MyOCIStack-%s_Hello_World", accountID))).
    Ensure(NewLogOutputEvaluator(regexp.MustCompile("Accessing"))).
    Run(t)
}

Tests can also use lambda invocation metrics using JMESPath selectors against the functions GetFunctionOutput JSON representation:

func TestCloudMetricsTest(t *testing.T) {
  NewTest().
    Given(NewLambdaInvokeTrigger(helloWorldJSON)).
    Against(
      NewStackLambdaSelector(fmt.Sprintf("MyOCIStack-%s", accountID),
        "[Configuration][?contains(FunctionName,'Hello_World')].FunctionName | [0]")).
    Ensure(NewLambdaInvocationMetricEvaluator(DefaultLambdaFunctionMetricQueries(),
      IsSuccess),
    ).
    Run(t)
}

The cloudtest package also provides S3, SQS, and other event source triggers. Clients can define their own cloudtest.Trigger compliant instance to extend the test scenarios.