Skip to content

Commit

Permalink
refactor(model): Move purl-related tests to PurlExtensionsTest
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Oct 24, 2024
1 parent 4814301 commit 7f07648
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 93 deletions.
93 changes: 0 additions & 93 deletions model/src/test/kotlin/IdentifierTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ import io.kotest.inspectors.forAll
import io.kotest.matchers.maps.containExactly
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldNotContain
import io.kotest.matchers.string.shouldNotStartWith
import io.kotest.matchers.string.shouldStartWith

import org.ossreviewtoolkit.model.utils.createPurl
import org.ossreviewtoolkit.model.utils.toPurl

class IdentifierTest : WordSpec({
"String representations" should {
Expand Down Expand Up @@ -124,93 +118,6 @@ class IdentifierTest : WordSpec({
}
}

"purl representations" should {
"not suffix the scheme with '//'" {
val purl = Identifier("type", "namespace", "name", "version").toPurl()

purl shouldStartWith "pkg:"
purl shouldNotStartWith "pkg://"
}

"not percent-encode the type" {
val purl = Identifier("azAZ09.+-", "namespace", "name", "version").toPurl()

purl shouldNotContain "%"
}

"ignore case in type" {
val purl = Identifier("MaVeN", "namespace", "name", "version").toPurl()

purl shouldBe purl.lowercase()
}

"use the generic type if it is not a known package manager" {
val purl = Identifier("FooBar", "namespace", "name", "version").toPurl()

purl shouldStartWith "pkg:generic"
}

"not use '/' for empty namespaces" {
val purl = Identifier("generic", "", "name", "version").toPurl()

purl shouldBe "pkg:generic/name@version"
}

"percent-encode namespaces with segments" {
val purl = Identifier("generic", "name/space", "name", "version").toPurl()

purl shouldBe "pkg:generic/name%2Fspace/name@version"
}

"percent-encode the name" {
val purl = Identifier("generic", "namespace", "fancy name", "version").toPurl()

purl shouldBe "pkg:generic/namespace/fancy%20name@version"
}

"percent-encode the version" {
val purl = Identifier("generic", "namespace", "name", "release candidate").toPurl()

purl shouldBe "pkg:generic/namespace/name@release%20candidate"
}

"allow qualifiers" {
val purl = createPurl(
"type",
"namespace",
"name",
"version",
mapOf("argName" to "argValue")
)

purl shouldBe "pkg:type/namespace/name@version?argName=argValue"
}

"allow multiple qualifiers" {
val purl = createPurl(
"type",
"namespace",
"name",
"version",
mapOf("argName1" to "argValue1", "argName2" to "argValue2")
)

purl shouldBe "pkg:type/namespace/name@version?argName1=argValue1&argName2=argValue2"
}

"allow subpath" {
val purl = createPurl(
"type",
"namespace",
"name",
"version",
subpath = "value1/value2"
)

purl shouldBe "pkg:type/namespace/name@version#value1/value2"
}
}

"Checking the organization" should {
"work as expected" {
assertSoftly {
Expand Down
90 changes: 90 additions & 0 deletions model/src/test/kotlin/utils/PurlExtensionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ package org.ossreviewtoolkit.model.utils

import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldNotContain
import io.kotest.matchers.string.shouldNotStartWith
import io.kotest.matchers.string.shouldStartWith

import org.ossreviewtoolkit.model.ArtifactProvenance
import org.ossreviewtoolkit.model.Hash
Expand All @@ -33,6 +36,93 @@ import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType

class PurlExtensionsTest : WordSpec({
"purl representations" should {
"not suffix the scheme with '//'" {
val purl = Identifier("type", "namespace", "name", "version").toPurl()

purl shouldStartWith "pkg:"
purl shouldNotStartWith "pkg://"
}

"not percent-encode the type" {
val purl = Identifier("azAZ09.+-", "namespace", "name", "version").toPurl()

purl shouldNotContain "%"
}

"ignore case in type" {
val purl = Identifier("MaVeN", "namespace", "name", "version").toPurl()

purl shouldBe purl.lowercase()
}

"use the generic type if it is not a known package manager" {
val purl = Identifier("FooBar", "namespace", "name", "version").toPurl()

purl shouldStartWith "pkg:generic"
}

"not use '/' for empty namespaces" {
val purl = Identifier("generic", "", "name", "version").toPurl()

purl shouldBe "pkg:generic/name@version"
}

"percent-encode namespaces with segments" {
val purl = Identifier("generic", "name/space", "name", "version").toPurl()

purl shouldBe "pkg:generic/name%2Fspace/name@version"
}

"percent-encode the name" {
val purl = Identifier("generic", "namespace", "fancy name", "version").toPurl()

purl shouldBe "pkg:generic/namespace/fancy%20name@version"
}

"percent-encode the version" {
val purl = Identifier("generic", "namespace", "name", "release candidate").toPurl()

purl shouldBe "pkg:generic/namespace/name@release%20candidate"
}

"allow qualifiers" {
val purl = createPurl(
"type",
"namespace",
"name",
"version",
mapOf("argName" to "argValue")
)

purl shouldBe "pkg:type/namespace/name@version?argName=argValue"
}

"allow multiple qualifiers" {
val purl = createPurl(
"type",
"namespace",
"name",
"version",
mapOf("argName1" to "argValue1", "argName2" to "argValue2")
)

purl shouldBe "pkg:type/namespace/name@version?argName1=argValue1&argName2=argValue2"
}

"allow subpath" {
val purl = createPurl(
"type",
"namespace",
"name",
"version",
subpath = "value1/value2"
)

purl shouldBe "pkg:type/namespace/name@version#value1/value2"
}
}

"Provenance conversion" should {
"work for extras of an artifact's provenance" {
val provenance = ArtifactProvenance(
Expand Down

0 comments on commit 7f07648

Please sign in to comment.