pulumi / providertest

Incubating facilities for testing Pulumi providers
Apache License 2.0
5 stars 0 forks source link

Pass `T` explicitly to all methods #102

Closed danielrbradley closed 2 months ago

danielrbradley commented 2 months ago

⚠️ 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

Migration Script

We can fix pretty much all usages using gofmt.

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
pulumi-bot commented 2 months ago

This PR has been shipped in release v0.1.0.