@@ -24,6 +24,7 @@ import com.typesafe.config.ConfigFactory
2424import io.kotest.core.spec.style.StringSpec
2525import io.kotest.extensions.system.withEnvironment
2626import io.kotest.matchers.comparables.shouldBeLessThan
27+ import io.kotest.matchers.shouldBe
2728
2829import io.mockk.coEvery
2930import io.mockk.coVerify
@@ -35,11 +36,18 @@ import kotlin.time.Clock
3536import kotlin.time.Duration.Companion.days
3637import kotlin.time.Instant
3738
39+ import kotlinx.serialization.json.int
40+ import kotlinx.serialization.json.jsonPrimitive
41+
3842import org.eclipse.apoapsis.ortserver.config.ConfigManager
3943import org.eclipse.apoapsis.ortserver.model.util.ProcessingResult
4044import org.eclipse.apoapsis.ortserver.services.ortrun.OrtRunService
45+ import org.eclipse.apoapsis.ortserver.utils.logging.JobStatusLogging
46+ import org.eclipse.apoapsis.ortserver.utils.logging.StatusLoggingTestExtension
4147
4248class DeleteOldOrtRunsTaskTest : StringSpec ({
49+ val logExtension = extension(StatusLoggingTestExtension ())
50+
4351 " Old ORT runs should be deleted according to the configured retention policy" {
4452 val ortRunRetentionDays = 77
4553 val configMap = mapOf("dataRetention.ortRunDays" to ortRunRetentionDays.toString())
@@ -67,14 +75,32 @@ class DeleteOldOrtRunsTaskTest : StringSpec({
6775 checkDeleteInvocation(ortRunService, ortRunRetentionDays)
6876 }
6977 }
78+
79+ " A status log entry should be created for the execution of the task" {
80+ val configMap = mapOf("dataRetention.ortRunDays" to "100")
81+ val configManager = ConfigManager .create(ConfigFactory .parseMap(configMap))
82+ val ortRunService = createOrtRunService()
83+
84+ val task = DeleteOldOrtRunsTask .create(configManager, ortRunService)
85+ task.execute()
86+
87+ val status = logExtension.statusLog()
88+
89+ status[JobStatusLogging .STATUS_KEY ]?.jsonPrimitive?.content shouldBe JobStatusLogging .STATUS_SUCCESS
90+ status[JobStatusLogging .PROCESSED_COUNT_KEY ]?.jsonPrimitive?.int shouldBe deletionResult.totalCount
91+ status[JobStatusLogging .FAILED_COUNT_KEY ]?.jsonPrimitive?.int shouldBe deletionResult.failedCount
92+ }
7093})
7194
95+ /* * The result to be returned by the [OrtRunService] mock when it is invoked to delete old ORT runs. */
96+ private val deletionResult = ProcessingResult (16 , 1 )
97+
7298/* *
7399 * Create a mock for [OrtRunService] and prepare it to expect a call to delete old ORT runs.
74100 */
75101private fun createOrtRunService (): OrtRunService =
76102 mockk<OrtRunService > {
77- coEvery { deleteRunsCreatedBefore(any()) } returns ProcessingResult ( 10 , 0 )
103+ coEvery { deleteRunsCreatedBefore(any()) } returns deletionResult
78104}
79105
80106/* *
0 commit comments