Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(node): Cover textual repository nodes #8512

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions model/src/main/kotlin/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ val EMPTY_JSON_NODE: JsonNode = MissingNode.getInstance()
inline fun <reified T> String.fromYaml(): T = yamlMapper.readValue(this)

fun Any?.toYaml(): String = yamlMapper.writeValueAsString(this)

fun String.readJsonTree(): JsonNode = jsonMapper.readTree(this)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message: s/programatical/programatic/

Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import io.kotest.core.spec.style.WordSpec
import io.kotest.inspectors.forAll
import io.kotest.matchers.shouldBe

import org.ossreviewtoolkit.model.HashAlgorithm
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.readJsonTree

class NpmSupportTest : WordSpec({
"expandNpmShortcutUrl" should {
"expandNpmShortcutUrl()" should {
"do nothing for empty URLs" {
expandNpmShortcutUrl("") shouldBe ""
}
Expand Down Expand Up @@ -80,7 +80,7 @@ class NpmSupportTest : WordSpec({
}
}

"fixNpmDownloadUrl" should {
"fixNpmDownloadUrl()" should {
"replace HTTP with HTTPS for the NPM registry only" {
fixNpmDownloadUrl("http://registry.npmjs.org/babel-cli/-/babel-cli-6.26.0.tgz") shouldBe
"https://registry.npmjs.org/babel-cli/-/babel-cli-6.26.0.tgz"
Expand All @@ -93,7 +93,7 @@ class NpmSupportTest : WordSpec({
}
}

"parseNpmAuthors" should {
"parseNpmAuthors()" should {
"get authors from a text node" {
val node = ObjectMapper().run {
createObjectNode().apply {
Expand All @@ -118,7 +118,7 @@ class NpmSupportTest : WordSpec({
}
}

"parseNpmLicenses" should {
"parseNpmLicenses()" should {
"get a singular 'license' from a text node" {
val node = ObjectMapper().run {
createObjectNode().apply {
Expand Down Expand Up @@ -191,30 +191,44 @@ class NpmSupportTest : WordSpec({
}
}

"parseNpmVcsInfo" should {
"get VCS information from an object node" {
@Suppress("Wrapping")
val node = ObjectMapper().run {
createObjectNode().apply {
replace("gitHead", TextNode(HashAlgorithm.SHA1GIT.emptyValue))
replace("repository", createObjectNode().apply {
replace("type", TextNode("Git"))
replace("url", TextNode("https://example.com/"))
replace("directory", TextNode("foo"))
})
"parseNpmVcsInfo()" should {
"get VCS information from an object node containing a repository node which is an object" {
val node = """
Copy link
Member

@sschuberth sschuberth Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be some work, but I guess ideally this should be done for all tests in this file now, or? That would nicely decouple the test from Jackson as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do a follow up PR for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you go: #8518

{
"gitHead": "bar",
"repository": {
"type": "Git",
"url": "https://example.com/",
"directory": "foo"
}
}
""".readJsonTree()

parseNpmVcsInfo(node) shouldBe VcsInfo(
VcsType.GIT,
"https://example.com/",
HashAlgorithm.SHA1GIT.emptyValue,
"bar",
"foo"
)
}

"get VCS information from an object node containing a repository node which is textual" {
val node = """
{
"gitHead": "bar",
"repository": "git+ssh://example.com/a/b.git"
}
""".readJsonTree()

parseNpmVcsInfo(node) shouldBe VcsInfo(
VcsType.UNKNOWN,
"git+ssh://example.com/a/b.git",
"bar"
)
}
}

"splitNpmNamespaceAndName" should {
"splitNpmNamespaceAndName()" should {
"return the namespace and name separately" {
splitNpmNamespaceAndName("@babel/core") shouldBe Pair("@babel", "core")
splitNpmNamespaceAndName("check-if-windows") shouldBe Pair("", "check-if-windows")
Expand Down
Loading