Skip to content

Commit

Permalink
Fix assertions in test result validation
Browse files Browse the repository at this point in the history
The test assertion mechanism was updated in the project service validation tests. Instead of checking presence of every expected key into the result keys set individually, now the equality of sets is checked. Additionally, data for a non-existent module was added to the pkgs-test-java.json, this will help testing scenarios where the tested project doesn't have some prerequisites.
  • Loading branch information
fscarponi committed May 23, 2024
1 parent d1c38be commit c835ddf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ internal fun TestScope.validateResult(projectName: String, expectedResultPath: S
"Deserialization of test result failed or is null for project $projectName"
)

val expectedKeys = expected.value?.keys ?: emptySet()
val resultKeys = result.value?.keys ?: emptySet()

assertTrue(expected.value?.keys?.all { it in (result.value?.keys ?: emptySet()) } ?: false,
assert(expectedKeys == resultKeys) {
buildString {
appendLine("expected MODULE keys differ from result keys")
appendLine("expected: ${expected.value?.keys}")
appendLine("result: ${result.value?.keys}")
}
)
}

expected.value?.forEach { (key, value) ->
assertNotNull(
Expand Down
21 changes: 21 additions & 0 deletions plugin/src/test/resources/projects/gradle/pkgs-test-java.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@
],
"defaultScope": "implementation"
},
"non_existent_module": {
"type": "com.jetbrains.packagesearch.plugin.tests.SerializablePackageSearchModule.Base",
"name": "non_existent_module",
"identity": {
"group": "gradle",
"path": ":non_existent_module"
},
"declaredRepositories": [],
"compatiblePackageTypes": [
{
"type": "maven"
},
{
"type": "gradle"
}
],
"dependencyMustHaveAScope": true,
"declaredDependencies": [],
"availableScopes": [],
"defaultScope": null
},
"sub-module-1": {
"type": "com.jetbrains.packagesearch.plugin.tests.SerializablePackageSearchModule.Base",
"name": "sub-module-1",
Expand Down

0 comments on commit c835ddf

Please sign in to comment.