Skip to content

Commit

Permalink
test(dao): Add tests for empty projects and packages
Browse files Browse the repository at this point in the history
Add tests to verify that the deduplication works also for projects and
packages with empty metadata.

The test for projects is currently failing, this will be fixed as part
of the next commit which reimplements the deduplication checks.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Jan 22, 2025
1 parent c226ae6 commit 59d0a6f
Showing 1 changed file with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,61 @@ class DaoAnalyzerRunRepositoryTest : StringSpec({
dbEntry shouldBe expectedRun
}

"create should deduplicate packages" {
"create should deduplicate packages with empty metadata" {
val pkg = Package(
identifier = Identifier("","","",""),
purl = "",
cpe = null,
authors = emptySet(),
declaredLicenses = emptySet(),
processedDeclaredLicense = ProcessedDeclaredLicense(null, emptyMap(), emptySet()),
description = "",
homepageUrl = "",
binaryArtifact = RemoteArtifact("", "", ""),
sourceArtifact = RemoteArtifact("", "", ""),
vcs = VcsInfo(RepositoryType.UNKNOWN, "", "", ""),
vcsProcessed = VcsInfo(RepositoryType.UNKNOWN, "", "", "")
)

val analyzerRunWithEmptyPackage = analyzerRun.copy(packages = setOf(pkg))

analyzerRunRepository.create(analyzerJobId, analyzerRunWithEmptyPackage)
analyzerRunRepository.create(analyzerJobId, analyzerRunWithEmptyPackage)

dbExtension.db.dbQuery { PackagesTable.selectAll().count() } shouldBe 1
}

"create should deduplicate packages with full metadata" {
analyzerRunRepository.create(analyzerJobId, analyzerRun)
analyzerRunRepository.create(analyzerJobId, analyzerRun)

dbExtension.db.dbQuery { PackagesTable.selectAll().count() } shouldBe 1
}

"create should deduplicate projects" {
"create should deduplicate projects with empty metadata" {
val project = Project(
identifier = Identifier("","","",""),
cpe = null,
definitionFilePath = "",
authors = emptySet(),
declaredLicenses = emptySet(),
processedDeclaredLicense = ProcessedDeclaredLicense(null, emptyMap(), emptySet()),
vcs = VcsInfo(RepositoryType.UNKNOWN, "", "", ""),
vcsProcessed = VcsInfo(RepositoryType.UNKNOWN, "", "", ""),
description = "",
homepageUrl = "",
scopeNames = emptySet()
)

val analyzerRunWithEmptyProject = analyzerRun.copy(projects = setOf(project))

analyzerRunRepository.create(analyzerJobId, analyzerRunWithEmptyProject)
analyzerRunRepository.create(analyzerJobId, analyzerRunWithEmptyProject)

dbExtension.db.dbQuery { ProjectsTable.selectAll().count() } shouldBe 1
}

"create should deduplicate projects with full metadata" {
analyzerRunRepository.create(analyzerJobId, analyzerRun)
analyzerRunRepository.create(analyzerJobId, analyzerRun)

Expand Down

0 comments on commit 59d0a6f

Please sign in to comment.