Skip to content

Commit e7060ff

Browse files
committed
test(model): Increase test coverage for declared license mappings
Relates to #10759. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 0e43ee0 commit e7060ff

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

model/src/main/kotlin/OrtResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ private val logger = loggerOf(MethodHandles.lookup().lookupClass())
695695
* given [curations] to the packages they apply to. The given [curations] must be ordered highest-priority-first, which
696696
* is the inverse order of their application.
697697
*/
698-
private fun applyPackageCurations(
698+
internal fun applyPackageCurations(
699699
packages: Collection<Package>,
700700
curations: List<PackageCuration>
701701
): Set<CuratedPackage> {

model/src/test/kotlin/OrtResultTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import io.kotest.matchers.collections.containExactly
2626
import io.kotest.matchers.collections.containExactlyInAnyOrder
2727
import io.kotest.matchers.collections.haveSize
2828
import io.kotest.matchers.collections.shouldContain
29+
import io.kotest.matchers.collections.shouldContainExactly
2930
import io.kotest.matchers.collections.shouldHaveSingleElement
3031
import io.kotest.matchers.collections.shouldNotContain
3132
import io.kotest.matchers.should
@@ -46,9 +47,44 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration
4647
import org.ossreviewtoolkit.model.config.Resolutions
4748
import org.ossreviewtoolkit.model.config.RuleViolationResolution
4849
import org.ossreviewtoolkit.model.config.RuleViolationResolutionReason
50+
import org.ossreviewtoolkit.utils.ort.ProcessedDeclaredLicense
51+
import org.ossreviewtoolkit.utils.spdx.toSpdx
4952
import org.ossreviewtoolkit.utils.test.readOrtResult
5053

5154
class OrtResultTest : WordSpec({
55+
"applyPackageCurations()" should {
56+
"apply a single package curation with a declared license mapping" {
57+
val licenseUrl = "https://www.nuget.org/packages/CommandLineParser/2.9.1/license"
58+
59+
val pkg = Package.EMPTY.copy(
60+
declaredLicenses = setOf(licenseUrl)
61+
)
62+
63+
val curation = PackageCuration(
64+
id = pkg.id,
65+
data = PackageCurationData(
66+
declaredLicenseMapping = mapOf(
67+
licenseUrl to "MIT".toSpdx()
68+
)
69+
)
70+
)
71+
72+
applyPackageCurations(setOf(pkg), listOf(curation)).shouldContainExactly(
73+
CuratedPackage(
74+
metadata = Package.EMPTY.copy(
75+
declaredLicenses = setOf(licenseUrl),
76+
declaredLicensesProcessed = ProcessedDeclaredLicense(
77+
spdxExpression = "MIT".toSpdx(),
78+
mapped = mapOf(licenseUrl to "MIT".toSpdx()),
79+
unmapped = emptySet()
80+
)
81+
),
82+
curations = listOf(curation.data)
83+
)
84+
)
85+
}
86+
}
87+
5288
"getDependencies()" should {
5389
"be able to get all direct dependencies of a package" {
5490
val ortResult = readOrtResult("/sbt-multi-project-example-expected-output.yml")

model/src/test/kotlin/PackageCurationTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,21 @@ class PackageCurationTest : WordSpec({
270270
curation.isApplicable(pkgVersionInsideRange.id) shouldBe true
271271
curation.isApplicable(pkgVersionOutsideRange.id) shouldBe false
272272
}
273+
274+
"work with URLs as keys for declared license mappings" {
275+
val licenseUrl = "https://www.nuget.org/packages/CommandLineParser/2.9.1/license"
276+
277+
val pkg = Package.EMPTY.copy(declaredLicenses = setOf(licenseUrl))
278+
279+
val curation = PackageCuration(
280+
id = pkg.id,
281+
data = PackageCurationData(declaredLicenseMapping = mapOf(licenseUrl to "MIT".toSpdx()))
282+
)
283+
284+
val curatedPkg = curation.apply(pkg.toCuratedPackage())
285+
286+
curatedPkg.metadata.declaredLicensesProcessed.allLicenses.shouldContainExactly("MIT")
287+
}
273288
}
274289

275290
"Applying multiple curations" should {

0 commit comments

Comments
 (0)