From 8e18093f567d865c64c8377c3711d7496479f6a2 Mon Sep 17 00:00:00 2001 From: Richard Shade Date: Wed, 13 Nov 2024 14:47:01 -0600 Subject: [PATCH] Adding in test code, fixes #350 --- provider/provider_nodejs_test.go | 41 +++++++++++++++++++ provider/resources.go | 2 +- .../test-programs/cloudrun-service/index.ts | 15 ++++++- upstream | 2 +- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/provider/provider_nodejs_test.go b/provider/provider_nodejs_test.go index cf5b9bd815..763b55310d 100644 --- a/provider/provider_nodejs_test.go +++ b/provider/provider_nodejs_test.go @@ -4,8 +4,11 @@ package gcp import ( + "fmt" "os" + "os/exec" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/require" @@ -46,6 +49,44 @@ func TestCloudrunServicePanicRegress2155(t *testing.T) { test.Up(t) } +func TestCloudrunServicePanicRegress2622(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) + + region := "us-central1" + t.Setenv("GOOGLE_REGION", region) + + test := pulumitest.NewPulumiTest(t, filepath.Join("test-programs", "cloudrun-service"), + opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")), + ) + + proj := getProject() + test.SetConfig(t, "gcp:project", proj) + up := test.Up(t) + + outputID := up.Outputs["id"].Value.(string) + parts := strings.Split(outputID, "/") + id := parts[len(parts)-1] + cmd := fmt.Sprintf(`gcloud run deploy %s \ + --image=us-docker.pkg.dev/cloudrun/container/hello \ + --cpu=2 \ + --no-cpu-boost \ + --region=%s \ + --project=%s \ + && gcloud run services update-traffic %s --to-latest`, id, region, proj, id) + + cmdErr := exec.Command(cmd).Run() + if cmdErr != nil { + t.Fatal(cmdErr.Error()) + } + test.SetConfig(t, "cpu", "2") + test.Up(t) +} + func TestCloudfunctionWrongType(t *testing.T) { if testing.Short() { t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without GCP creds") diff --git a/provider/resources.go b/provider/resources.go index 2f7a29235c..4d95e9fff4 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -1783,7 +1783,7 @@ func Provider() tfbridge.ProviderInfo { // program, and since pulumi does not refresh by default. See the following urls for more information: // https://cloud.google.com/run/docs/reference/rpc/google.cloud.run.meta.v1#google.cloud.run.meta.v1.ObjectMeta // https://github.com/pulumi/pulumi-gcp/issues/350 - TransformFromState: func(ctx context.Context, state resource.PropertyMap) (resource.PropertyMap, error) { + TransformFromState: func(_ context.Context, state resource.PropertyMap) (resource.PropertyMap, error) { if _, md := state["metadata"]; md { if state["metadata"].IsObject() { metadata := state["metadata"].ObjectValue() diff --git a/provider/test-programs/cloudrun-service/index.ts b/provider/test-programs/cloudrun-service/index.ts index 71713f3078..5c2ba48b35 100644 --- a/provider/test-programs/cloudrun-service/index.ts +++ b/provider/test-programs/cloudrun-service/index.ts @@ -1,12 +1,23 @@ +import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; -new gcp.cloudrun.Service("my-service", { +const pulumiConfig = new pulumi.Config() +const cpu = pulumiConfig.get("cpu") || "1" + +const cloudRunService = new gcp.cloudrun.Service("my-service", { location: "us-central1", template: { spec: { containers: [{ image: "us-docker.pkg.dev/cloudrun/container/hello", + resources: { + limits: { + cpu: cpu, + }, + }, }], }, }, -}); \ No newline at end of file +}); + +export const id = cloudRunService.id \ No newline at end of file diff --git a/upstream b/upstream index 018f83bfba..feb3ef42ea 160000 --- a/upstream +++ b/upstream @@ -1 +1 @@ -Subproject commit 018f83bfbaaa5bd2e8c26d40cb6bb29ec3c1a624 +Subproject commit feb3ef42ead9e94c1b865e1f8fa90bb46c863dc9