@@ -6,11 +6,9 @@ import (
66 "encoding/json"
77 "fmt"
88 "os"
9- "os/exec"
109 "path/filepath"
1110 "runtime"
1211 "strings"
13- "sync"
1412 "testing"
1513
1614 "github.com/hexops/autogold/v2"
@@ -53,7 +51,7 @@ func TestStacktraceDisplayed(t *testing.T) {
5351 skipWindows (t )
5452
5553 ctx := context .Background ()
56- grpc := pfProviderTestServer (ctx , t )
54+ grpc := parameterizedTestServer (ctx , t , pfProviderPath )
5755
5856 _ , err := grpc .Create (ctx , & pulumirpc.CreateRequest {
5957 Urn : string (resource .NewURN (
@@ -366,30 +364,12 @@ func assertGRPC(t *testing.T, msg proto.Message, v autogold.Value) {
366364// pfProviderPath returns the path the the PF provider binary for use in testing.
367365//
368366// It builds the binary running "go build" once per session.
369- var pfProviderPath = func () func (t * testing.T ) string {
370- mkBin := sync .OnceValues (func () (string , error ) {
371- wd , err := os .Getwd ()
372- if err != nil {
373- return "" , err
374- }
375-
376- out := filepath .Join (globalTempDir , "terraform-provider-pfprovider" )
377- cmd := exec .Command ("go" , "build" , "-o" , out , "github.com/pulumi/pulumi-terraform-bridge/dynamic/tests/pfprovider" )
378- cmd .Dir = filepath .Join (wd , "test" , "pfprovider" )
379- stdoutput , err := cmd .CombinedOutput ()
380- if err != nil {
381- return "" , fmt .Errorf ("failed to build provider: %w:\n %s" , err , string (stdoutput ))
382- }
383- return out , nil
384- })
385-
386- return func (t * testing.T ) string {
387- t .Helper ()
388- path , err := mkBin ()
389- require .NoErrorf (t , err , "failed find provider path" )
390- return path
391- }
392- }()
367+ var (
368+ pfProviderPath = helper .BuildOnce (& globalTempDir ,
369+ "test/pfprovider" , "terraform-provider-pfprovider" )
370+ sdkv1ProviderPath = helper .BuildOnce (& globalTempDir ,
371+ "test/sdkv1provider" , "terraform-provider-sdkv1" )
372+ )
393373
394374// grpcTestServer returns an unparameterized in-memory gRPC server.
395375func grpcTestServer (ctx context.Context , t * testing.T ) pulumirpc.ResourceProviderServer {
@@ -400,14 +380,15 @@ func grpcTestServer(ctx context.Context, t *testing.T) pulumirpc.ResourceProvide
400380 return s
401381}
402382
403- // pfProviderTestServer returns an in-memory gRPC server already parameterized by the
404- // pfprovider test Terraform provider.
405- func pfProviderTestServer (ctx context.Context , t * testing.T ) pulumirpc.ResourceProviderServer {
383+ func parameterizedTestServer (
384+ ctx context.Context , t * testing.T ,
385+ pathHelper func (t * testing.T ) string ,
386+ ) pulumirpc.ResourceProviderServer {
406387 grpc := grpcTestServer (ctx , t )
407388 t .Run ("parameterize" , assertGRPCCall (grpc .Parameterize , & pulumirpc.ParameterizeRequest {
408389 Parameters : & pulumirpc.ParameterizeRequest_Args {
409390 Args : & pulumirpc.ParameterizeRequest_ParametersArgs {
410- Args : []string {pfProviderPath (t )},
391+ Args : []string {pathHelper (t )},
411392 },
412393 },
413394 }, noParallel ))
@@ -536,6 +517,30 @@ func TestRandomCreate(t *testing.T) {
536517 })
537518}
538519
520+ func TestSDKv1Provider (t * testing.T ) {
521+ t .Parallel ()
522+ helper .Integration (t )
523+ skipWindows (t )
524+
525+ ctx := context .Background ()
526+
527+ server := parameterizedTestServer (ctx , t , sdkv1ProviderPath )
528+
529+ const typ = "sdkv1:index/res:Res"
530+ urn := string (resource .NewURN (
531+ "test" , "test" , "" , typ , "res" ,
532+ ))
533+
534+ t .Run ("delete" , assertGRPCCall (server .Delete , & pulumirpc.DeleteRequest {
535+ Id : "example-id-delete" ,
536+ Urn : urn ,
537+ Properties : marshal (resource.PropertyMap {
538+ "f0" : resource .NewProperty ("123" ),
539+ "f1" : resource .NewProperty (123.0 ),
540+ }),
541+ }))
542+ }
543+
539544func must [T any ](v T , err error ) T {
540545 if err != nil {
541546 panic (err )
0 commit comments