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 4a1f28b commit acc720c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
42 changes: 42 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,45 @@ 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 := os.Getenv("GOOGLE_PROJECT")
test.SetConfig(t, "gcp:project", proj)
up := test.Up(t)

outputId := up.Outputs["id"].Value.(string)

Check failure on line 71 in provider/provider_nodejs_test.go

View workflow job for this annotation

GitHub Actions / lint / lint

var-naming: var outputId should be outputID (revive)
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)

err = exec.Command(cmd).Run()
if err != nil {
errMsg := err.(*exec.ExitError).Stderr
t.Fatal(string(errMsg))
}
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 acc720c

Please sign in to comment.