You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Json test in our codebase sometimes fails and sometimes passes. This is probably due to the nested struct arrays root.seatbid[i].bid[j] because the same thing happens with another JSON test in our repo.
╰─➤ go test
+-- 5 lines: E0925 15:16:30.083508 -----------------------------------------------------
PASS
ok github.com/prebid/prebid-server/endpoints/openrtb2 3.318s
In summary, this is the test that I've been using:
func diffJson(t *testing.T, description string, actual []byte, expected []byte) {
t.Helper()
diff, err := gojsondiff.New().Compare(actual, expected)
if err != nil {
t.Fatalf("%s json diff failed. %v", description, err)
}
if diff.Modified() {
var left interface{}
if err := json.Unmarshal(actual, &left); err != nil {
t.Fatalf("%s json did not match, but unmarshalling failed. %v", description, err)
}
printer := formatter.NewAsciiFormatter(left, formatter.AsciiFormatterConfig{
ShowArrayIndex: true,
})
output, err := printer.Format(diff)
if err != nil {
t.Errorf("%s did not match, but diff formatting failed. %v", description, err)
} else {
t.Errorf("%s json did not match expected.\n\n%s", description, output)
}
}
}
And these are the actual (left) and expected (right):
A Json test in our codebase sometimes fails and sometimes passes. This is probably due to the nested struct arrays
root.seatbid[i].bid[j]
because the same thing happens with another JSON test in our repo.But if we are lucky we get:
In summary, this is the test that I've been using:
And these are the actual (left) and expected (right):
I'm using the latest version.
The text was updated successfully, but these errors were encountered: