Integration Testing with Automation API
Pulumi’s Automation API provides a programmatic interface for integration testing. While not a purpose-built integration testing framework, you can use Automation API in your integration tests to accomplish the same objectives of basic correctness testing, resource validation, and runtime testing. Automation API is available in all Pulumi languages except YAML and is a part of the Pulumi SDK.
Testing workflow
To write integration tests with Automation API, follow these steps:
- Create a stack using Automation API.
- Set up stack configuration and secrets.
- Deploy the stack using
up(). - Perform resource validation by examining the deployment state.
- Perform runtime checks by interacting with deployed infrastructure.
- Tear down the stack using
destroy()and clean up resources.
Validating resource and stack properties
To validate that the correct resources were created with the expected properties, you can export the stack and examine the resulting resources.
For example, in TypeScript:
export async function getDeployment(): Promise<Deployment> { const stack = await LocalWorkspace.createOrSelectStack(args); return stack.exportStack(); } You can then iterate through the Deployment object to check that the expected resources and property values are present.
Validating infrastructure correctness
Runtime validation involves interacting with your deployed infrastructure to verify it works correctly. For example, you might:
- Make HTTP requests to validate an API endpoint
- Query a database to verify data was created correctly
- Check that files exist in object storage
- Verify that VMs are responding to network requests
The Automation API gives you full access to stack outputs, which typically include endpoints, URLs, and other information needed to interact with your infrastructure.
Example
The localProgram-tsnode-mochatests example demonstrates how to:
- Set up a stack using Automation API
- Perform runtime validation checks
- Tear down the stack as part of a test
Additional resources
Integration tests written with Automation API in the Pulumi SDK repositories:
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.
