Skip to content

Commit

Permalink
Add regression test for type check warnings (#2389)
Browse files Browse the repository at this point in the history
This adds a regression test for the warnings we issue to users when a
property has the wrong type. This could result in panics down the line,
so we need to catch them early.

Testing this in the bridge is currently quite hard as we can't use YAML
for this because it is too strict in type-checking. We only have unit
tests which indirectly test this but these break under PRC.

This was introduced in
pulumi/pulumi-terraform-bridge#1987
original GCP issue:
pulumi/pulumi-terraform-bridge#1979

Bridge issue for integration tests for the feature:
pulumi/pulumi-terraform-bridge#2418
  • Loading branch information
VenelinMartinov authored Sep 17, 2024
1 parent a1f7fa3 commit 99484f2
Show file tree
Hide file tree
Showing 8 changed files with 3,724 additions and 0 deletions.
17 changes: 17 additions & 0 deletions provider/provider_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,20 @@ func TestCloudrunServicePanicRegress2155(t *testing.T) {
test.Up()
test.Up()
}

func TestCloudfunctionWrongType(t *testing.T) {
if testing.Short() {
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without GCP creds")
}

cwd, err := os.Getwd()
require.NoError(t, err)
test := pulumitest.NewPulumiTest(t, filepath.Join("test-programs", "cloudfunction-wrong-type"),
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")),
)

_, err = test.CurrentStack().Up(test.Context())
require.Error(t, err)

require.Contains(t, err.Error(), `Unexpected type at field "environmentVariables"`)
}
2 changes: 2 additions & 0 deletions provider/test-programs/cloudfunction-wrong-type/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/node_modules/
10 changes: 10 additions & 0 deletions provider/test-programs/cloudfunction-wrong-type/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: cloudfunction-wrong-type
runtime:
name: nodejs
options:
packagemanager: npm
description: A minimal Google Cloud TypeScript Pulumi program
config:
pulumi:tags:
value:
pulumi:template: gcp-typescript
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello, world!");
26 changes: 26 additions & 0 deletions provider/test-programs/cloudfunction-wrong-type/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

// Create a GCP resource (Storage Bucket)
const bucket = new gcp.storage.Bucket("my-bucket", {
location: "US"
});

const archive = new gcp.storage.BucketObject("archive", {
name: "index.zip",
bucket: bucket.name,
source: new pulumi.asset.FileArchive("./fn"),
});

new gcp.cloudfunctions.Function(
`a-function`,
{
runtime: 'nodejs20',
sourceArchiveBucket: bucket.name,
sourceArchiveObject: archive.name,
entryPoint: "main",
name: 'name',
environmentVariables: [{ a_key: 'A value'}] as any,
triggerHttp: true,
},
);
Loading

0 comments on commit 99484f2

Please sign in to comment.