Skip to content

Commit

Permalink
revised2
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Nov 21, 2024
1 parent 7a78267 commit 1bac8df
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions infra/blueprint-test/pkg/golden/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: true,
},
{
name: "false",
data: "{\"foo\":\"bar\",\"baz\":{\"qux\":\"quz\"},\"fizz\":\"pop\"}",
eqPaths: []string{"foo","baz"},
want: "{\"foo\":\"bar\",\"baz\":{\"qux\":\"quz1\"}}",
hasError: false,
},
}
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)
})
}
}

0 comments on commit 1bac8df

Please sign in to comment.