Skip to content

Commit

Permalink
Merge #11646
Browse files Browse the repository at this point in the history
11646: Add test for codegen error initialization  r=aq17 a=aq17

Adds test for #11643

Co-authored-by: aq17 <aqiu@pulumi.com>
  • Loading branch information
bors[bot] and aq17 committed Dec 14, 2022
2 parents 5ec798e + af8e87b commit 6bdca3c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/codegen/go/gen_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,12 @@ func (g *generator) genLocalVariable(w io.Writer, v *pcl.LocalVariable) {
g.Fgenf(w, "%s %s %.3v;\n", name, assignment, expr)
case fromBase64Fn:
tmpVar := fmt.Sprintf("%s%d", "tmpVar", g.tmpVarCount)
g.Fgenf(w, "%s, _ %s %.3v;\n", tmpVar, assignment, expr)
g.Fgenf(w, "%s, _ := %.3v;\n", tmpVar, expr)
if name == "_" {
assignment = ":="
assignment = "="
}
g.Fgenf(w, "%s %s string(%s)\n", name, assignment, tmpVar)
g.tmpVarCount++
g.isErrAssigned = true
default:
g.Fgenf(w, "%s := %.3v;\n", name, expr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"2",
});
var zone = Aws.GetAvailabilityZones.Invoke();
var zone2 = Aws.GetAvailabilityZones.Invoke();
var bucket = new Aws.S3.Bucket("bucket");
var encoded2 = bucket.Id.Apply(id => Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(id)));
Expand Down
4 changes: 4 additions & 0 deletions pkg/codegen/testing/test/testdata/functions-pp/functions.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

joined = join("-", [encoded, decoded, "2"])

# tests that we initialize "var, err" with ":=" first, then "=" subsequently (Go specific)
zone = invoke("aws:index:getAvailabilityZones", {})
zone2 = invoke("aws:index:getAvailabilityZones", {})

resource bucket "aws:s3:Bucket" {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/base64"
"strings"

"github.com/pulumi/pulumi-aws/sdk/v5/go/aws"
"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/s3"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
Expand All @@ -18,6 +19,14 @@ func main() {
decoded,
"2",
}, "-")
_, err := aws.GetAvailabilityZones(ctx, nil, nil)
if err != nil {
return err
}
_, err = aws.GetAvailabilityZones(ctx, nil, nil)
if err != nil {
return err
}
bucket, err := s3.NewBucket(ctx, "bucket", nil)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const joined = [
decoded,
"2",
].join("-");
const zone = aws.getAvailabilityZones({});
const zone2 = aws.getAvailabilityZones({});
const bucket = new aws.s3.Bucket("bucket", {});
const encoded2 = bucket.id.apply(id => Buffer.from(id).toString("base64"));
const decoded2 = bucket.id.apply(id => Buffer.from(id, "base64").toString("utf8"));
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
decoded,
"2",
])
zone = aws.get_availability_zones()
zone2 = aws.get_availability_zones()
bucket = aws.s3.Bucket("bucket")
encoded2 = bucket.id.apply(lambda id: base64.b64encode(id.encode()).decode())
decoded2 = bucket.id.apply(lambda id: base64.b64decode(id.encode()).decode())

0 comments on commit 6bdca3c

Please sign in to comment.