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 functional tests error message #698

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
inver order of arrays and rename properly
  • Loading branch information
nelsitoPuglisi committed Apr 11, 2024
commit bfc83cdb15f6c3904eb5557220897b64064a3526
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
{
"key": "emb.type",
"value": "ux.session"
},
{
"key": "emb.private",
"value": "true"
}
],
"events": "__EMBRACE_TEST_IGNORE__",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,33 @@ internal object JsonValidator {
}

private fun areJsonElementsEquals(
jsonElement1: JsonElement,
jsonElement2: JsonElement,
expectedJson: JsonElement,
observedJson: JsonElement,
sb: StringBuilder
): Boolean {
when {
jsonElement1.isIgnored() || jsonElement2.isIgnored() -> return true
jsonElement1.isJsonObject && jsonElement2.isJsonObject -> {
expectedJson.isIgnored() || observedJson.isIgnored() -> return true
expectedJson.isJsonObject && observedJson.isJsonObject -> {
return areJsonObjectsEquals(
jsonElement1.asJsonObject,
jsonElement2.asJsonObject,
expectedJson.asJsonObject,
observedJson.asJsonObject,
sb
)
}

jsonElement1.isJsonArray && jsonElement2.isJsonArray -> {
return areJsonArraysEquals(jsonElement1.asJsonArray, jsonElement2.asJsonArray, sb)
expectedJson.isJsonArray && observedJson.isJsonArray -> {
return areJsonArraysEquals(expectedJson.asJsonArray, observedJson.asJsonArray, sb)
}

jsonElement1.isJsonPrimitive && jsonElement2.isJsonPrimitive -> {
expectedJson.isJsonPrimitive && observedJson.isJsonPrimitive -> {
return areJsonPrimitiveEquals(
jsonElement1.asJsonPrimitive,
jsonElement2.asJsonPrimitive,
expectedJson.asJsonPrimitive,
observedJson.asJsonPrimitive,
sb
)
}

jsonElement1.isJsonNull && jsonElement2.isJsonNull -> {
expectedJson.isJsonNull && observedJson.isJsonNull -> {
return true
}

Expand Down Expand Up @@ -122,25 +122,25 @@ internal object JsonValidator {
* Arrays ordered in a different way are considered different.
*/
private fun areJsonArraysEquals(
jsonArray1: JsonArray,
jsonArray2: JsonArray,
expectedJsonArray: JsonArray,
observedJsonArray: JsonArray,
sb: StringBuilder
): Boolean {
if (jsonArray1.size() != jsonArray2.size()) {
if (expectedJsonArray.size() != observedJsonArray.size()) {
sb.append("Different arrays size. ")
return false
}

jsonArray1.forEach { array1Entry ->
observedJsonArray.forEach { observedEntry ->
var found = false
jsonArray2.forEach { array2Entry ->
expectedJsonArray.forEach { expectedEntry ->
// use another string builder to avoid appending to the main one
if (areJsonElementsEquals(array1Entry, array2Entry, StringBuilder())) {
if (areJsonElementsEquals(expectedEntry, observedEntry, StringBuilder())) {
found = true
}
}
if (!found) {
sb.append("Array element not found in observed array: $array1Entry.")
sb.append("Array element not found in observed array: $observedEntry.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inverted the order to have access to the observedEntry.

return false
}
}
Expand Down
Loading