github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/python/gen_program_quotes_test.go (about) 1 package python 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/pulumi/pulumi/pkg/v3/codegen/pcl" 8 "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestLowerPropertyAccess(t *testing.T) { 13 t.Parallel() 14 15 const source = `zones = invoke("aws:index:getAvailabilityZones", {}) 16 17 resource vpcSubnet "aws:ec2:Subnet" { 18 options { range = zones.names } 19 20 cidrBlock = "10.100.${range.key}.0/24" 21 availabilityZone = range.value 22 } 23 24 resource rta "aws:ec2:RouteTableAssociation" { 25 options { range = zones.names } 26 27 subnetId = vpcSubnet[range.key].id 28 } 29 ` 30 program, diags := parseAndBindProgram(t, source, "lower_property_access.pp") 31 contract.Ignore(diags) 32 33 g, err := newGenerator(program) 34 assert.NoError(t, err) 35 36 var rta *pcl.Resource 37 for _, n := range g.program.Nodes { 38 if r, ok := n.(*pcl.Resource); ok && r.Name() == "rta" { 39 rta = r 40 break 41 } 42 } 43 assert.NotNil(t, rta) 44 45 // Lower the "subnetId" property of the resource. 46 prop, ok := rta.Definition.Body.Attribute("subnetId") 47 assert.True(t, ok) 48 49 x, temps := g.lowerExpression(prop.Value, prop.Type()) 50 assert.Len(t, temps, 0) 51 52 x.SetLeadingTrivia(nil) 53 x.SetTrailingTrivia(nil) 54 assert.Equal(t, "vpcSubnet[range[key]].id", fmt.Sprintf("%v", x)) 55 }