Skip to content

Commit

Permalink
test(osv): Convert OsvFunTest to WordSpec
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Dec 4, 2024
1 parent ac270d8 commit d231d1c
Showing 1 changed file with 44 additions and 42 deletions.
86 changes: 44 additions & 42 deletions plugins/advisors/osv/src/funTest/kotlin/OsvFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.ossreviewtoolkit.plugins.advisors.osv

import io.kotest.core.spec.style.StringSpec
import io.kotest.core.spec.style.WordSpec
import io.kotest.inspectors.forAll
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
Expand All @@ -35,53 +35,55 @@ import org.ossreviewtoolkit.model.readValue
import org.ossreviewtoolkit.model.utils.toPurl
import org.ossreviewtoolkit.utils.test.getAssetFile

class OsvFunTest : StringSpec({
"retrievePackageFindings() returns vulnerabilities for the supported ecosystems" {
val osv = createOsv()
val packages = setOf(
"Crate::sys-info:0.7.0",
"Composer:thorsten:phpmyfaq:3.0.7",
"Gem::rack:2.0.4",
"Go::github.com/nats-io/nats-server/v2:2.1.0",
"Hackage::xml-conduit:0.5.0",
"Maven:com.jfinal:jfinal:1.4",
"NPM::rebber:1.0.0",
"NuGet::Bunkum:4.0.0",
"Pub::http:0.13.1",
"PyPI::django:3.2",
"Swift::github.com/apple/swift-nio:2.41.0"
).mapTo(mutableSetOf()) {
identifierToPackage(it)
}
class OsvFunTest : WordSpec({
"retrievePackageFindings()" should {
"return the vulnerabilities for the supported ecosystems" {
val osv = createOsv()
val packages = setOf(
"Crate::sys-info:0.7.0",
"Composer:thorsten:phpmyfaq:3.0.7",
"Gem::rack:2.0.4",
"Go::github.com/nats-io/nats-server/v2:2.1.0",
"Hackage::xml-conduit:0.5.0",
"Maven:com.jfinal:jfinal:1.4",
"NPM::rebber:1.0.0",
"NuGet::Bunkum:4.0.0",
"Pub::http:0.13.1",
"PyPI::django:3.2",
"Swift::github.com/apple/swift-nio:2.41.0"
).mapTo(mutableSetOf()) {
identifierToPackage(it)
}

val packageFindings = osv.retrievePackageFindings(packages)
val packageFindings = osv.retrievePackageFindings(packages)

packageFindings.keys shouldContainExactlyInAnyOrder packages
packageFindings.keys.forAll { pkg ->
packageFindings.getValue(pkg).vulnerabilities shouldNot beEmpty()
packageFindings.keys shouldContainExactlyInAnyOrder packages
packageFindings.keys.forAll { pkg ->
packageFindings.getValue(pkg).vulnerabilities shouldNot beEmpty()
}
}
}

"retrievePackageFindings() returns the expected result for the given package(s)" {
val expectedResult = getAssetFile("retrieve-package-findings-expected-result.json")
.readValue<Map<Identifier, AdvisorResult>>()
val osv = createOsv()
// The following packages have been chosen because they have only one vulnerability with the oldest possible
// modified date from the current OSV database, in order to hopefully minimize the flakiness.
val packages = setOf(
// Package with severity:
"NPM::find-my-way:3.0.0",
// Package without severity, but with severity inside the databaseSpecific JSON object:
"NPM::discord-markdown:2.3.0",
// Package without severity:
"PyPI::donfig:0.2.0"
).mapTo(mutableSetOf()) {
identifierToPackage(it)
}
"return the expected result for the given package(s)" {
val expectedResult = getAssetFile("retrieve-package-findings-expected-result.json")
.readValue<Map<Identifier, AdvisorResult>>()
val osv = createOsv()
// The following packages have been chosen because they have only one vulnerability with the oldest possible
// modified date from the current OSV database, in order to hopefully minimize the flakiness.
val packages = setOf(
// Package with severity:
"NPM::find-my-way:3.0.0",
// Package without severity, but with severity inside the databaseSpecific JSON object:
"NPM::discord-markdown:2.3.0",
// Package without severity:
"PyPI::donfig:0.2.0"
).mapTo(mutableSetOf()) {
identifierToPackage(it)
}

val packageFindings = osv.retrievePackageFindings(packages).mapKeys { it.key.id }
val packageFindings = osv.retrievePackageFindings(packages).mapKeys { it.key.id }

packageFindings.patchTimes() shouldBe expectedResult.patchTimes()
packageFindings.patchTimes() shouldBe expectedResult.patchTimes()
}
}
})

Expand Down

0 comments on commit d231d1c

Please sign in to comment.