Skip to content

Commit

Permalink
chore(fossid-webapp): Move createMarkAsIdentifiedFile to TestUtils
Browse files Browse the repository at this point in the history
This function will be used by another test in a future commit.

Signed-off-by: Nicolas Nobelis <[email protected]>
  • Loading branch information
nnobelis committed Mar 15, 2024
1 parent 494a324 commit e883345
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldStartWith

import org.ossreviewtoolkit.clients.fossid.model.identification.common.LicenseMatchType
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.File
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.License
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.LicenseFile
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.MarkedAsIdentifiedFile
import org.ossreviewtoolkit.clients.fossid.model.result.LicenseCategory
import org.ossreviewtoolkit.clients.fossid.model.result.MatchType
import org.ossreviewtoolkit.clients.fossid.model.result.Snippet
Expand All @@ -46,7 +41,7 @@ private const val FILE_PATH_SNIPPET = "filePathSnippet"
class FossIdLicenseMappingTest : WordSpec({
"FossIdScanResults" should {
"create an issue when a license in an identified file cannot be mapped" {
val sampleFile = createMarkAsIdentifiedFile("invalid license")
val sampleFile = createMarkAsIdentifiedFile("invalid license", FILE_PATH)
val issues = mutableListOf<Issue>()

val findings = listOf(sampleFile).mapSummary(emptyMap(), issues, emptyMap())
Expand Down Expand Up @@ -110,47 +105,6 @@ class FossIdLicenseMappingTest : WordSpec({
}
})

private fun createMarkAsIdentifiedFile(license: String): MarkedAsIdentifiedFile {
val fileLicense = License(
1,
LicenseMatchType.FILE,
1,
1,
1,
created = "created",
updated = "updated",
licenseId = 1
).also {
it.file = LicenseFile(
license,
null,
null,
null,
null,
null
)
}

return MarkedAsIdentifiedFile(
"comment",
emptyMap(),
1,
"copyright",
1,
1
).also {
it.file = File(
"fileId",
"fileMd5",
FILE_PATH,
"fileSha1",
"fileSha256",
0,
mutableMapOf(1 to fileLicense)
)
}
}

private fun createSnippet(license: String): RawResults {
val snippet = Snippet(
1,
Expand Down
45 changes: 45 additions & 0 deletions plugins/scanners/fossid/src/test/kotlin/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.ossreviewtoolkit.clients.fossid.model.Scan
import org.ossreviewtoolkit.clients.fossid.model.identification.common.LicenseMatchType
import org.ossreviewtoolkit.clients.fossid.model.identification.identifiedFiles.IdentifiedFile
import org.ossreviewtoolkit.clients.fossid.model.identification.ignored.IgnoredFile
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.File
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.License
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.LicenseFile
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.MarkedAsIdentifiedFile
Expand Down Expand Up @@ -341,6 +342,50 @@ private fun createMarkedIdentifiedFile(index: Int): MarkedAsIdentifiedFile {
return file
}

/**
* Create a [MarkedAsIdentifiedFile] with the give [license] and [path].
*/
internal fun createMarkAsIdentifiedFile(license: String, path: String): MarkedAsIdentifiedFile {
val fileLicense = License(
1,
LicenseMatchType.FILE,
1,
1,
1,
created = "created",
updated = "updated",
licenseId = 1
).also {
it.file = LicenseFile(
license,
null,
null,
null,
null,
null
)
}

return MarkedAsIdentifiedFile(
"comment",
emptyMap(),
1,
"copyright",
1,
1
).also {
it.file = File(
"fileId",
"fileMd5",
path,
"fileSha1",
"fileSha256",
0,
mutableMapOf(1 to fileLicense)
)
}
}

/**
* Create an [IgnoredFile] based on the given [index].
*/
Expand Down

0 comments on commit e883345

Please sign in to comment.