-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass
T
explicitly to all methods (#102)
#⚠️ Breaking change⚠️ Don't capture T within the PulumiTest structure as this breaks various aspects of how Go's testing is designed: 1. 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. 2. 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`? 1. Logging: We can automatically log significant context in case of failure. 2. Clean-up: When creating directories and stacks, we automatically register them for deletion after the test has passed. 3. 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. ### Migration Script We can fix pretty much all usages using `gofmt`. ```bash gofmt -r 'a.Convert(b) -> a.Convert(t, b)' -w ./**/*_test.go gofmt -r 'a.CopyTo(b) -> a.CopyTo(t, b)' -w ./**/*_test.go gofmt -r 'a.CopyToTempDir() -> a.CopyToTempDir(t)' -w ./**/*_test.go gofmt -r 'a.Destroy() -> a.Destroy(t)' -w ./**/*_test.go gofmt -r 'a.ExportStack() -> a.ExportStack(t)' -w ./**/*_test.go gofmt -r 'a.GrpcLog() -> a.GrpcLog(t)' -w ./**/*_test.go gofmt -r 'a.ClearGrpcLog() -> a.ClearGrpcLog(t)' -w ./**/*_test.go gofmt -r 'a.Import(b, c, d, e, f, g) -> a.Import(t, b, c, d, e, f, g)' -w ./**/*_test.go gofmt -r 'a.Import(b, c, d, e, f) -> a.Import(t, b, c, d, e, f)' -w ./**/*_test.go gofmt -r 'a.Import(b, c, d, e) -> a.Import(t, b, c, d, e)' -w ./**/*_test.go gofmt -r 'a.Import(b, c, d) -> a.Import(t, b, c, d)' -w ./**/*_test.go gofmt -r 'a.Import(b, c) -> a.Import(t, b, c)' -w ./**/*_test.go gofmt -r 'a.Import(b) -> a.Import(t, b)' -w ./**/*_test.go gofmt -r 'a.ImportStack(b) -> a.ImportStack(t, b)' -w ./**/*_test.go gofmt -r 'a.Install() -> a.Install(t)' -w ./**/*_test.go gofmt -r 'a.InstallStack(b) -> a.InstallStack(t, b)' -w ./**/*_test.go gofmt -r 'a.Preview() -> a.Preview(t)' -w ./**/*_test.go gofmt -r 'a.Refresh() -> a.Refresh(t)' -w ./**/*_test.go gofmt -r 'a.SetConfig(b, c) -> a.SetConfig(t, b, c)' -w ./**/*_test.go gofmt -r 'a.Up() -> a.Up(t)' -w ./**/*_test.go gofmt -r 'a.UpdateSource(b) -> a.UpdateSource(t, b)' -w ./**/*_test.go gofmt -r 'a.NewStack(b) -> a.NewStack(t, b)' -w ./**/*_test.go gofmt -r 'a.Run(b) -> a.Run(t, b)' -w ./**/*_test.go ``` - 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.
- Loading branch information
1 parent
af0614e
commit be10035
Showing
31 changed files
with
216 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.