Skip to content

Instantly share code, notes, and snippets.

@t0yv0
Last active December 16, 2022 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t0yv0/611ea955c183718d702a596b9ca55831 to your computer and use it in GitHub Desktop.
Save t0yv0/611ea955c183718d702a596b9ca55831 to your computer and use it in GitHub Desktop.
/*
Add an option to ProgramTest framework to allow testing a Pulumi program against mock providers that
replay conversations from a previous run. Think of this as a useful way to test that P->P' program updates behave
identically in a quick-and-easy way.
- Unlike vanilla ProgramTest, on a warm cache the test does not touch the cloud.
- Unlike testing with mocks, there is no need to write mocks. Just record a successful run of the program.
- Fast.. If the program uses ec2.Cluster there is no longer a need to wait 20 min to test the program.
- If the program is non-deterministic or deviates from the recorded behavior, the trace becomes insufficient to power
a mock provider. That is explcitly out of scope (crash with a good error message). Expecting the basic support to
still cover enough pratical use cases.
Example:
*/
func TestMyStack(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: "my-stack",
ProviderTrace: &integration.ProviderTrace{
"aws": "test-data/my-stack/aws.json",
},
})
}
/*
Running the test without the trace file present runs the program against the cloud and records the trace.
Running the test again with the trace file present runs the program against the trace to replay.
Implementation notes:
- recording is available via PULUMI_DEBUG_GRPC
- replay may be built with the same format and using gRPC interceptors framework
- Ringo working in this space adapting PACT framework to the problem; opportunities to explore/compare
solutions in a shared problem-space
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment