Don't capture T within the PulumiTest structure as this breaks various aspects of how Go's testing is designed:
Sub-tests are given their own T instance so if we create a copy of a pulumitest instance for a sub-test, we don't want logs reported to the parent.
Logs are incorrectly reported back to the wrong line number. The logs are tracked back to the construction of the pulumitest rather than the line of the operation that failed.
Fixes #104
Why pass in T?
Logging: We can automatically log significant context in case of failure.
Clean-up: When creating directories and stacks, we automatically register them for deletion after the test has passed.
Assertions: We automatically assert that operations are successful.
Solution
Pass T as the first parameter for any method which does asserts internally as is the pattern in Go.
Write an automated migration to update all existing usages of the library.
It's a little messy but correctly migrates all usages within this package.
~gofmt seems unable to migrate the pt.Run() because it can't match inline functions~. Re-testing shows this works.
The Import migration isn't idempotent due to the variable number of arguments so should be run once manually when upgrading to the new version and the changes committed.
This doesn't handle any instances of passing additional functional argument, but I doubt we use many of these in practice.
⚠️ Breaking change ⚠️
Don't capture T within the PulumiTest structure as this breaks various aspects of how Go's testing is designed:
T
instance so if we create a copy of apulumitest
instance for a sub-test, we don't want logs reported to the parent.pulumitest
rather than the line of the operation that failed.Fixes #104
Why pass in
T
?Solution
Migration Script
We can fix pretty much all usages using
gofmt
.gofmt
seems unable to migrate thept.Run()
because it can't match inline functions~. Re-testing shows this works.Import
migration isn't idempotent due to the variable number of arguments so should be run once manually when upgrading to the new version and the changes committed.