Skip to content

Commit

Permalink
test(workers): Simplify OrtRunServiceTest
Browse files Browse the repository at this point in the history
Do not assign the `RepositoryConfigurationRepository` to a variable
because it is only needed in one place which already has access to the
`fixtures` object which provides the repository.

Also, do not assign `ResolvedConfigurationRepository` to a variable
because it is only needed in a single test which can also get it from
the fixtures.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Dec 9, 2024
1 parent 2673286 commit 9e99a4a
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions workers/common/src/test/kotlin/common/OrtRunServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import org.eclipse.apoapsis.ortserver.model.Hierarchy
import org.eclipse.apoapsis.ortserver.model.JobStatus
import org.eclipse.apoapsis.ortserver.model.RepositoryType
import org.eclipse.apoapsis.ortserver.model.Severity
import org.eclipse.apoapsis.ortserver.model.repositories.RepositoryConfigurationRepository
import org.eclipse.apoapsis.ortserver.model.repositories.ResolvedConfigurationRepository
import org.eclipse.apoapsis.ortserver.model.resolvedconfiguration.PackageCurationProviderConfig
import org.eclipse.apoapsis.ortserver.model.resolvedconfiguration.ResolvedConfiguration
import org.eclipse.apoapsis.ortserver.model.resolvedconfiguration.ResolvedPackageCurations
Expand Down Expand Up @@ -122,18 +120,12 @@ class OrtRunServiceTest : WordSpec({
lateinit var db: Database
lateinit var fixtures: Fixtures

lateinit var repositoryConfigRepository: RepositoryConfigurationRepository
lateinit var resolvedConfigurationRepository: ResolvedConfigurationRepository

lateinit var service: OrtRunService

beforeEach {
db = dbExtension.db
fixtures = dbExtension.fixtures

repositoryConfigRepository = dbExtension.fixtures.repositoryConfigurationRepository
resolvedConfigurationRepository = dbExtension.fixtures.resolvedConfigurationRepository

service = OrtRunService(
db,
fixtures.advisorJobRepository,
Expand All @@ -147,9 +139,9 @@ class OrtRunServiceTest : WordSpec({
fixtures.reporterRunRepository,
fixtures.notifierJobRepository,
fixtures.notifierRunRepository,
repositoryConfigRepository,
fixtures.repositoryConfigurationRepository,
fixtures.repositoryRepository,
resolvedConfigurationRepository,
fixtures.resolvedConfigurationRepository,
fixtures.scannerJobRepository,
fixtures.scannerRunRepository
)
Expand Down Expand Up @@ -406,8 +398,7 @@ class OrtRunServiceTest : WordSpec({
processedVcsInfo,
nestedVcsInfo1,
nestedVcsInfo2,
fixtures,
repositoryConfigRepository
fixtures
)

service.getOrtRepositoryInformation(ortRun) shouldBe Repository(
Expand All @@ -429,8 +420,7 @@ class OrtRunServiceTest : WordSpec({
processedVcsInfo,
nestedVcsInfo1,
nestedVcsInfo2,
fixtures,
repositoryConfigRepository
fixtures
)

val exception = shouldThrow<IllegalArgumentException> {
Expand All @@ -451,8 +441,7 @@ class OrtRunServiceTest : WordSpec({
null,
nestedVcsInfo1,
nestedVcsInfo2,
fixtures,
repositoryConfigRepository
fixtures
)

val exception = shouldThrow<IllegalArgumentException> {
Expand Down Expand Up @@ -525,20 +514,20 @@ class OrtRunServiceTest : WordSpec({
val id = Identifier("type", "namespace", "name", "version")

val packageConfigurations = listOf(PackageConfiguration(id = id))
resolvedConfigurationRepository.addPackageConfigurations(ortRun.id, packageConfigurations)
fixtures.resolvedConfigurationRepository.addPackageConfigurations(ortRun.id, packageConfigurations)

val packageCurations = listOf(
ResolvedPackageCurations(
provider = PackageCurationProviderConfig(name = "name"),
curations = listOf(PackageCuration(id = id, PackageCurationData()))
)
)
resolvedConfigurationRepository.addPackageCurations(ortRun.id, packageCurations)
fixtures.resolvedConfigurationRepository.addPackageCurations(ortRun.id, packageCurations)

val resolutions = Resolutions(
issues = listOf(IssueResolution(message = "message", reason = "reason", comment = "comment"))
)
resolvedConfigurationRepository.addResolutions(ortRun.id, resolutions)
fixtures.resolvedConfigurationRepository.addResolutions(ortRun.id, resolutions)

service.getResolvedConfiguration(ortRun) shouldBe
ResolvedConfiguration(packageConfigurations, packageCurations, resolutions)
Expand Down Expand Up @@ -1037,8 +1026,7 @@ class OrtRunServiceTest : WordSpec({
processedVcsInfo,
nestedVcsInfo1,
nestedVcsInfo2,
fixtures,
repositoryConfigRepository
fixtures
)

service.generateOrtResult(ortRun).let { ortResult ->
Expand Down Expand Up @@ -1121,8 +1109,7 @@ private fun createOrtRun(
processedVcsInfo: VcsInfo?,
nestedVcsInfo1: VcsInfo,
nestedVcsInfo2: VcsInfo,
fixtures: Fixtures,
repositoryConfigurationRepository: RepositoryConfigurationRepository
fixtures: Fixtures
) = db.blockingQuery {
val vcs = vcsInfo?.let(VcsInfoDao::getOrPut)
val vcsProcessed = processedVcsInfo?.let(VcsInfoDao::getOrPut)
Expand All @@ -1144,7 +1131,7 @@ private fun createOrtRun(

val repositoryConfiguration = OrtTestData.repository.config.mapToModel(fixtures.ortRun.id)

repositoryConfigurationRepository.create(
fixtures.repositoryConfigurationRepository.create(
ortRunId = ortRunDao.id.value,
analyzerConfig = repositoryConfiguration.analyzerConfig,
excludes = repositoryConfiguration.excludes,
Expand Down

0 comments on commit 9e99a4a

Please sign in to comment.