Skip to content

Commit

Permalink
Adding in test code, fixes #350
Browse files Browse the repository at this point in the history
  • Loading branch information
rshade committed Nov 13, 2024
1 parent db1a975 commit 6bb68cc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
39 changes: 39 additions & 0 deletions provider/provider_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
package gcp

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -46,6 +49,42 @@ 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]

cmdDepErr := exec.Command("gcloud", "run", "deploy", id, "--image=us-docker.pkg.dev/cloudrun/container/hello", "--cpu=2", "--no-cpu-boost", fmt.Sprintf(`--region=%s`, region), fmt.Sprintf(`--project=%s`, proj)).Run()
if cmdDepErr != nil {
t.Fatal(cmdDepErr.Error())
}

cmdErr := exec.Command("gcloud", "run", "services", "update-traffic", id, "--to-latest").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")
Expand Down
2 changes: 1 addition & 1 deletion provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 13 additions & 2 deletions provider/test-programs/cloudrun-service/index.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
}],
},
},
});
});

export const id = cloudRunService.id

0 comments on commit 6bb68cc

Please sign in to comment.