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

helper-cli: Test that curations are added when creating an analyzer results from package lists #9532

Merged
merged 3 commits into from
Dec 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,13 @@ analyzer:
scanner: null
advisor: null
evaluator: null
resolved_configuration: {}
resolved_configuration:
package_curations:
- provider:
id: "File"
curations:
- id: "NPM::example-dependency-one:1.0.0"
curations:
comment: "Example curation."
vcs:
revision: "v1.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ import io.kotest.core.spec.style.WordSpec
import io.kotest.engine.spec.tempdir
import io.kotest.matchers.shouldBe

import java.io.File

import org.ossreviewtoolkit.helper.HelperMain
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.ResolvedConfiguration
import org.ossreviewtoolkit.model.PackageCuration
import org.ossreviewtoolkit.model.PackageCurationData
import org.ossreviewtoolkit.model.VcsInfoCurationData
import org.ossreviewtoolkit.model.config.OrtConfiguration
import org.ossreviewtoolkit.model.config.ProviderPluginConfiguration
import org.ossreviewtoolkit.model.readValue
import org.ossreviewtoolkit.model.toYaml
import org.ossreviewtoolkit.utils.ort.Environment
import org.ossreviewtoolkit.utils.ort.createOrtTempFile
import org.ossreviewtoolkit.utils.test.getAssetFile

class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
Expand All @@ -38,9 +47,12 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
val inputFile = getAssetFile("package-list.yml")
val outputFile = tempdir().resolve("analyzer-result.yml")
val expectedOutputFile = getAssetFile("create-analyzer-result-from-pkg-list-expected-output.yml")
val ortConfigFile = createOrtConfig()

HelperMain().test(
"create-analyzer-result-from-package-list",
"--config",
ortConfigFile.absolutePath,
"--package-list-file",
inputFile.absolutePath,
"--ort-file",
Expand All @@ -53,8 +65,38 @@ class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
}
})

private fun OrtResult.patchAnalyzerResult(): OrtResult =
copy(
analyzer = analyzer?.copy(environment = Environment()),
resolvedConfiguration = ResolvedConfiguration()
private val PACKAGE_CURATION = PackageCuration(
id = Identifier("NPM::example-dependency-one:1.0.0"),
data = PackageCurationData(
comment = "Example curation.",
vcs = VcsInfoCurationData(
revision = "v1.0.0"
)
)
)

private fun createOrtConfig(): File {
val packageCurationsFile = createOrtTempFile(suffix = ".yml").apply {
writeText(listOf(PACKAGE_CURATION).toYaml())
}

val config = OrtConfiguration().copy(
packageCurationProviders = listOf(
ProviderPluginConfiguration(
type = "File",
options = mapOf(
"path" to packageCurationsFile.absolutePath,
"mustExist" to "true"
)
)
)
)

val ortConfigFile = createOrtTempFile(suffix = "config.yml").apply {
writeText(mapOf("ort" to config).toYaml())
}

return ortConfigFile
}

private fun OrtResult.patchAnalyzerResult(): OrtResult = copy(analyzer = analyzer?.copy(environment = Environment()))
Loading