Skip to content

Commit

Permalink
Expose ProviderServerFromInfo for use in GRPC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Dec 10, 2024
1 parent 9c34f9e commit 6333631
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/internal/tests/cross-tests/upgrade_state_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func runPulumiUpgrade(t T, res1, res2 *schema.Resource, config1, config2 cty.Val
err := os.WriteFile(p, yamlProgram, 0o600)
require.NoErrorf(t, err, "writing Pulumi.yaml")

handle, err := pulcheck.StartPulumiProvider(context.Background(), defProviderShortName, defProviderVer, prov2)
handle, err := pulcheck.StartPulumiProvider(context.Background(), prov2)
require.NoError(t, err)
pt.CurrentStack().Workspace().SetEnvVar("PULUMI_DEBUG_PROVIDERS", fmt.Sprintf("%s:%d", defProviderShortName, handle.Port))
pt.Up(t)
Expand Down
15 changes: 11 additions & 4 deletions pkg/tests/pulcheck/pulcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ func EnsureProviderValid(t T, tfp *schema.Provider) {
require.NoError(t, tfp.InternalValidate())
}

// This is an experimental API.
func StartPulumiProvider(ctx context.Context, name, version string, providerInfo tfbridge.ProviderInfo) (*rpcutil.ServeHandle, error) {
func ProviderServerFromInfo(ctx context.Context, providerInfo tfbridge.ProviderInfo) (pulumirpc.ResourceProviderServer, error) {
sink := pulumidiag.DefaultSink(io.Discard, io.Discard, pulumidiag.FormatOptions{
Color: colors.Never,
})
Expand All @@ -102,7 +101,15 @@ func StartPulumiProvider(ctx context.Context, name, version string, providerInfo
return nil, fmt.Errorf("json.MarshalIndent(schema, ..) failed: %w", err)
}

prov := tfbridge.NewProvider(ctx, nil, name, version, providerInfo.P, providerInfo, schemaBytes)
return tfbridge.NewProvider(ctx, nil, providerInfo.Name, providerInfo.Version, providerInfo.P, providerInfo, schemaBytes), nil
}

// This is an experimental API.
func StartPulumiProvider(ctx context.Context, providerInfo tfbridge.ProviderInfo) (*rpcutil.ServeHandle, error) {
prov, err := ProviderServerFromInfo(ctx, providerInfo)
if err != nil {
return nil, fmt.Errorf("ProviderServerFromInfo failed: %w", err)
}

handle, err := rpcutil.ServeWithOptions(rpcutil.ServeOptions{
Init: func(srv *grpc.Server) error {
Expand Down Expand Up @@ -227,7 +234,7 @@ func PulCheck(t T, bridgedProvider info.Provider, program string, opts ...opttes
opttest.AttachProvider(
bridgedProvider.Name,
func(ctx context.Context, pt providers.PulumiTest) (providers.Port, error) {
handle, err := StartPulumiProvider(ctx, bridgedProvider.Name, bridgedProvider.Version, bridgedProvider)
handle, err := StartPulumiProvider(ctx, bridgedProvider)
require.NoError(t, err)
return providers.Port(handle.Port), nil
},
Expand Down

0 comments on commit 6333631

Please sign in to comment.