From a37437cab951e9d3b67789433859180661c591cb Mon Sep 17 00:00:00 2001 From: Andrew Peabody Date: Thu, 21 Nov 2024 17:54:35 +0000 Subject: [PATCH] revised2 --- .../blueprint-test/pkg/golden/golden_test.go | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/infra/blueprint-test/pkg/golden/golden_test.go b/infra/blueprint-test/pkg/golden/golden_test.go index 86e5ffc3cdc..e501a05a851 100644 --- a/infra/blueprint-test/pkg/golden/golden_test.go +++ b/infra/blueprint-test/pkg/golden/golden_test.go @@ -25,6 +25,8 @@ import ( "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud" "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils" "github.com/stretchr/testify/assert" + + gotest "github.com/mitchellh/go-testing-interface" ) const testProjectID = "foo" @@ -136,29 +138,40 @@ func TestJSONEq(t *testing.T) { func TestJSONEqs(t *testing.T) { tests := []struct { - name string - data string - eqPaths []string - opts []goldenFileOption - want string + name string + data string + eqPaths []string + opts []goldenFileOption + want string + hasError bool }{ { - name: "simple", - data: "{\"foo\":\"bar\",\"baz\":{\"qux\":\"quz\"},\"fizz\":\"pop\"}", - eqPaths: []string{"foo","baz"}, - want: "{\"foo\":\"bar\",\"baz\":{\"qux\":\"quz\"}}", + name: "simple", + data: "{\"foo\":\"bar\",\"baz\":{\"qux\":\"quz\"},\"fizz\":\"pop\"}", + eqPaths: []string{"foo","baz"}, + want: "{\"foo\":\"bar\",\"baz\":{\"qux\":\"quz\"}}", + hasError: false, + }, + { + name: "false", + data: "{\"foo\":\"bar\",\"baz\":{\"qux\":\"quz\"},\"fizz\":\"pop\"}", + eqPaths: []string{"foo","baz"}, + want: "{\"foo\":\"bar\",\"baz\":{\"qux\":\"quz1\"}}", + hasError: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert := assert.New(t) + innerT := &gotest.RuntimeT{} + innerAssert := assert.New(innerT) os.Setenv(gfUpdateEnvVar, "true") defer os.Unsetenv(gfUpdateEnvVar) got := NewOrUpdate(t, tt.data, tt.opts...) defer os.Remove(got.GetName()) - got.JSONPathEqs(assert, utils.ParseJSONResult(t, tt.data), tt.eqPaths) - multipathQuery := fmt.Sprintf("{%s}", strings.Join(tt.eqPaths, ",")) - assert.JSONEq(tt.want, got.GetJSON().Get(multipathQuery).String()) + got.JSONPathEqs(innerAssert, utils.ParseJSONResult(t, tt.want), tt.eqPaths) + + assert := assert.New(t) + assert.True(innerT.Failed() == tt.hasError) }) } }