Skip to content

Commit

Permalink
Avoid a partially nil host as sink in test muxed providers
Browse files Browse the repository at this point in the history
This change prevents test providers from being initialized with partially nil logging
sinks, which panicked in tests. Happily, the problem is restricted to `MakeMuxedServer`, a
testing API. This was never present in production code.

Fixes #2697

---

This is [my least favorite go feature](https://www.iwahbe.com/blog/go-pointers-considered-confusing/).
  • Loading branch information
iwahbe committed Dec 9, 2024
1 parent 0852d64 commit 0fa1f8d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/pf/tfbridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"

"github.com/pulumi/pulumi-terraform-bridge/v3/internal/logging"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf"
pfmuxer "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/internal/muxer"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
Expand Down Expand Up @@ -126,7 +127,7 @@ func MainWithMuxer(ctx context.Context, pkg string, info tfbridge.ProviderInfo,
// of pulumi-terraform-bridge. This is an experimental API.
func MakeMuxedServer(
ctx context.Context, pkg string, info tfbridge.ProviderInfo, schema []byte,
) func(host *rprovider.HostClient) (pulumirpc.ResourceProviderServer, error) {
) func(*rprovider.HostClient) (pulumirpc.ResourceProviderServer, error) {
shim, ok := info.P.(*pfmuxer.ProviderShim)
contract.Assertf(ok, "MainWithMuxer must have a ProviderInfo.P created with AugmentShimWithPF")
_, err := shim.ResolveDispatch(&info)
Expand Down Expand Up @@ -172,7 +173,15 @@ func MakeMuxedServer(
Server: func(host *rprovider.HostClient) (pulumirpc.ResourceProviderServer, error) {
infoCopy := info
infoCopy.P = prov
return NewProviderServer(ctx, host,

// https://github.com/pulumi/pulumi-terraform-bridge/issues/2697:
// Avoid accidentally casting (*rprovider.HostClient)(nil) to
// (logging.Sink)((*rprovider.HostClient)(nil)).
var sink logging.Sink
if host != nil {
sink = host
}
return NewProviderServer(ctx, sink,
infoCopy, ProviderMetadata{PackageSchema: schema})
},
})
Expand Down

0 comments on commit 0fa1f8d

Please sign in to comment.