- Determine variable types for ranged resources by typechecking an equivalent expression - Detect top-level await in NodeJS and generate an async main - Fix `pulumi.all` generation for NodeJS - Fix a bug in the lowering of relative traversals in Python
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package python
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2"
|
|
"github.com/pulumi/pulumi/sdk/v2/go/common/util/contract"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestLowerPropertyAccess(t *testing.T) {
|
|
|
|
const source = `zones = invoke("aws:index:getAvailabilityZones", {})
|
|
|
|
resource vpcSubnet "aws:ec2:Subnet" {
|
|
options { range = zones.names }
|
|
|
|
cidrBlock = "10.100.${range.key}.0/24"
|
|
availabilityZone = range.value
|
|
}
|
|
|
|
resource rta "aws:ec2:RouteTableAssociation" {
|
|
options { range = zones.names }
|
|
|
|
subnetId = vpcSubnet[range.key].id
|
|
}
|
|
`
|
|
program, diags := parseAndBindProgram(t, source, "lower_property_access.pp")
|
|
contract.Ignore(diags)
|
|
|
|
g, err := newGenerator(program)
|
|
assert.NoError(t, err)
|
|
|
|
var rta *hcl2.Resource
|
|
for _, n := range g.program.Nodes {
|
|
if r, ok := n.(*hcl2.Resource); ok && r.Name() == "rta" {
|
|
rta = r
|
|
break
|
|
}
|
|
}
|
|
assert.NotNil(t, rta)
|
|
|
|
// Lower the "subnetId" property of the resource.
|
|
prop, ok := rta.Definition.Body.Attribute("subnetId")
|
|
assert.True(t, ok)
|
|
|
|
x, temps := g.lowerExpression(prop.Value)
|
|
assert.Len(t, temps, 0)
|
|
|
|
x.SetLeadingTrivia(nil)
|
|
x.SetTrailingTrivia(nil)
|
|
assert.Equal(t, "vpcSubnet[range[key]].id", fmt.Sprintf("%v", x))
|
|
}
|