Skip to content

Commit

Permalink
test(osv): Make the test resilient WRT trailing slashes in URLs
Browse files Browse the repository at this point in the history
Recently, the tests failed because the results kept on alternating
between URLs with and without trailing slashes. So, make the test
tolerate both in order to reduce the flakyness.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau authored and sschuberth committed Feb 22, 2024
1 parent d1c4e0e commit f62b6b9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions clients/osv/src/funTest/kotlin/OsvServiceFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ private fun Vulnerability.patchIgnorableFields() =
}
)

private fun Vulnerability.normalizeUrls(): Vulnerability {
val references = references.mapTo(mutableSetOf()) { it.copy(url = it.url.removeSuffix("/")) }
return copy(references = references)
}

private val emptyJsonObject = JsonObject(emptyMap())

private fun List<Vulnerability>.patchIgnorableFields() = map { it.patchIgnorableFields() }
private fun List<Vulnerability>.patchFields() = map { it.patchIgnorableFields().normalizeUrls() }

class OsvServiceFunTest : StringSpec({

Check warning on line 65 in clients/osv/src/funTest/kotlin/OsvServiceFunTest.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "OsvServiceFunTest" is never used
"getVulnerabilitiesForPackage() returns the expected vulnerability when queried by commit" {
Expand All @@ -65,7 +70,7 @@ class OsvServiceFunTest : StringSpec({

result.shouldBeSuccess { actualData ->
val expectedData = OsvApiClient.JSON.decodeFromString<List<Vulnerability>>(expectedResult)
actualData.patchIgnorableFields() shouldContainExactlyInAnyOrder expectedData.patchIgnorableFields()
actualData.patchFields() shouldContainExactlyInAnyOrder expectedData.patchFields()
}
}

Expand All @@ -76,7 +81,7 @@ class OsvServiceFunTest : StringSpec({

result.shouldBeSuccess { actualData ->
val expectedData = OsvApiClient.JSON.decodeFromString<List<Vulnerability>>(expectedResult)
actualData.patchIgnorableFields() shouldContainExactlyInAnyOrder expectedData.patchIgnorableFields()
actualData.patchFields() shouldContainExactlyInAnyOrder expectedData.patchFields()
}
}

Expand Down

0 comments on commit f62b6b9

Please sign in to comment.