From a7eea94b416392a24136022da7fe960f0304d8cb Mon Sep 17 00:00:00 2001 From: Bharath KKB Date: Tue, 12 Dec 2023 23:24:53 -0600 Subject: [PATCH] chore: run all bpt tests (#2001) Co-authored-by: Andrew Peabody --- .pre-commit-config.yaml | 3 ++- infra/blueprint-test/build/int.cloudbuild.yaml | 4 ++++ infra/blueprint-test/pkg/golden/golden_test.go | 10 +++++----- .../pkg/golden/testdata/TestUpdate-with-prev-data.json | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4fa3dc19205..04f7ce6875a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,8 @@ exclude: | dm/.*| reports/.*| cli/testdata/.*| - cli/bptest/.* + cli/bptest/.*| + infra/blueprint-test/.*.json )$ repos: - repo: https://github.com/renovatebot/pre-commit-hooks diff --git a/infra/blueprint-test/build/int.cloudbuild.yaml b/infra/blueprint-test/build/int.cloudbuild.yaml index 7a0c095bad3..53563f1c9dc 100644 --- a/infra/blueprint-test/build/int.cloudbuild.yaml +++ b/infra/blueprint-test/build/int.cloudbuild.yaml @@ -17,6 +17,10 @@ steps: name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && prepare_environment'] dir: 'infra/blueprint-test' +- id: pkg-test + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'go test ./... -v'] + dir: 'infra/blueprint-test/pkg' - id: test name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' args: ['/bin/bash', '-c', 'git config --global user.name "cft-test"; git config --global user.email "<>"; go test -v'] diff --git a/infra/blueprint-test/pkg/golden/golden_test.go b/infra/blueprint-test/pkg/golden/golden_test.go index 9529194f379..c72f22e4269 100644 --- a/infra/blueprint-test/pkg/golden/golden_test.go +++ b/infra/blueprint-test/pkg/golden/golden_test.go @@ -27,7 +27,7 @@ import ( "github.com/stretchr/testify/assert" ) -const testProjectIDEnvVar = "TEST_GCLOUD_PROJECT" +const testProjectID = "foo" func TestUpdate(t *testing.T) { tests := []struct { @@ -93,7 +93,7 @@ func TestJSONEq(t *testing.T) { }, { name: "sanitize projectID", - data: fmt.Sprintf("{\"foo\":\"bar\",\"baz\":{\"qux\":\"%s\"}}", os.Getenv(testProjectIDEnvVar)), + data: fmt.Sprintf("{\"foo\":\"bar\",\"baz\":{\"qux\":\"%s\"}}", testProjectID), opts: []goldenFileOption{WithSanitizer(ProjectIDSanitizer(t))}, setProjectID: true, eqPath: "baz", @@ -101,10 +101,10 @@ func TestJSONEq(t *testing.T) { }, { name: "no gcloud projectID set", - data: fmt.Sprintf("{\"foo\":\"bar\",\"baz\":{\"qux\":\"%s\"}}", os.Getenv(testProjectIDEnvVar)), + data: fmt.Sprintf("{\"foo\":\"bar\",\"baz\":{\"qux\":\"%s\"}}", testProjectID), opts: []goldenFileOption{WithSanitizer(ProjectIDSanitizer(t))}, eqPath: "baz", - want: fmt.Sprintf("{\"qux\":\"%s\"}", os.Getenv(testProjectIDEnvVar)), + want: fmt.Sprintf("{\"qux\":\"%s\"}", testProjectID), }, { name: "multiple sanitizers quz", @@ -121,7 +121,7 @@ func TestJSONEq(t *testing.T) { t.Run(tt.name, func(t *testing.T) { assert := assert.New(t) if tt.setProjectID { - gcloud.Runf(t, "config set project %s", os.Getenv(testProjectIDEnvVar)) + gcloud.Runf(t, "config set project %s", testProjectID) defer gcloud.Run(t, "config unset project") } os.Setenv(gfUpdateEnvVar, "true") diff --git a/infra/blueprint-test/pkg/golden/testdata/TestUpdate-with-prev-data.json b/infra/blueprint-test/pkg/golden/testdata/TestUpdate-with-prev-data.json index 2393cd01d4b..9f5dd4e3d9f 100755 --- a/infra/blueprint-test/pkg/golden/testdata/TestUpdate-with-prev-data.json +++ b/infra/blueprint-test/pkg/golden/testdata/TestUpdate-with-prev-data.json @@ -1 +1 @@ -{"foo":"bar"} +{"foo":"bar"} \ No newline at end of file