github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/testdata/resource-property-overlap/go-extras/tests/go_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"sync"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
    10  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    11  
    12  	"resource-property-overlap/example"
    13  )
    14  
    15  // Tests that XArray{x}.ToXArrayOutput().Index(pulumi.Int(0)) == x.
    16  func TestArrayOutputIndex(t *testing.T) {
    17  	err := pulumi.RunErr(func(ctx *pulumi.Context) error {
    18  
    19  		r1, err := example.NewRec(ctx, "rec1", &example.RecArgs{})
    20  		if err != nil {
    21  			return err
    22  		}
    23  
    24  		r1o := r1.ToRecOutput()
    25  
    26  		r2o := example.RecArray{r1o}.ToRecArrayOutput().
    27  			Index(pulumi.Int(0))
    28  
    29  		wg := &sync.WaitGroup{}
    30  		wg.Add(1)
    31  
    32  		pulumi.All(r1o, r2o).ApplyT(func(xs []interface{}) int {
    33  			assert.Equal(t, xs[0], xs[1])
    34  			wg.Done()
    35  			return 0
    36  		})
    37  
    38  		wg.Wait()
    39  		return nil
    40  	}, pulumi.WithMocks("project", "stack", mocks(0)))
    41  	assert.NoError(t, err)
    42  }
    43  
    44  type mocks int
    45  
    46  func (mocks) NewResource(args pulumi.MockResourceArgs) (string, resource.PropertyMap, error) {
    47  	return args.Name + "_id", args.Inputs, nil
    48  }
    49  
    50  func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) {
    51  	return args.Args, nil
    52  }