Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: JSONEq() handle json doc whitespace #2719

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions infra/blueprint-test/pkg/golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ func (g *GoldenFile) GetJSON() gjson.Result {
// JSONEq asserts that json content in jsonPath for got and goldenfile is the same
func (g *GoldenFile) JSONEq(a *assert.Assertions, got gjson.Result, jsonPath string) {
gf := g.GetJSON()
gotData := g.ApplySanitizers(got.Get(jsonPath).String())
gfData := gf.Get(jsonPath).String()
a.Equal(gfData, gotData, fmt.Sprintf("expected %s to match fixture %s", jsonPath, gfData))
getPath := fmt.Sprintf("%s|@tostr", jsonPath)
gotData := g.ApplySanitizers(got.Get(getPath).String())
gfData := gf.Get(getPath).String()
a.JSONEq(gfData, gotData, fmt.Sprintf("expected %s to match fixture %s", jsonPath, gfData))
}

// JSONPathEqs asserts that json content in jsonPaths for got and goldenfile are the same
Expand Down
6 changes: 6 additions & 0 deletions infra/blueprint-test/pkg/golden/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func TestJSONEq(t *testing.T) {
eqPath: "baz",
want: "{\"qux\":\"REPLACED\",\"quux\":\"NEW\"}",
},
{
name: "diff_whitespace",
data: "{\"list\":[\n \"SYSTEM_COMPONENTS\",\n \"POD\",\n \"DAEMONSET\",\n \"DEPLOYMENT\",\n \"STATEFULSET\",\n \"STORAGE\",\n \"HPA\",\n \"CADVISOR\",\n \"KUBELET\"\n ]}",
eqPath: "list",
want: "[\n \"SYSTEM_COMPONENTS\",\n \"POD\",\n \"DAEMONSET\",\n \"DEPLOYMENT\",\n \"STATEFULSET\",\n \"STORAGE\",\n \"HPA\",\n \"CADVISOR\",\n \"KUBELET\"\n ]",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading