Skip to content

Commit

Permalink
#1236 Environment build count (0) if not deployed anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Dec 15, 2024
1 parent 40f0fff commit 7d547e8
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class EnvironmentsBuildPromotionInfoExtension(
val slotPipeline = slotService.findSlotPipelinesWhereBuildIsLastDeployed(build).firstOrNull()
if (slotPipeline != null) {
items.add(0, buildPromotionInfoItemForDeployedSlotPipeline(slotPipeline))
} else {
items.add(0, buildPromotionInfoItemForDeployedSlotCount(build, 0))
}
}

Expand All @@ -62,9 +64,13 @@ class EnvironmentsBuildPromotionInfoExtension(
build: Build
) {
val slotPipelines = slotService.findSlotPipelinesWhereBuildIsLastDeployed(build)
items.addAll(0, slotPipelines.map { slotPipeline ->
buildPromotionInfoItemForDeployedSlotPipeline(slotPipeline)
})
if (slotPipelines.isNotEmpty()) {
items.addAll(0, slotPipelines.map { slotPipeline ->
buildPromotionInfoItemForDeployedSlotPipeline(slotPipeline)
})
} else {
items.add(0, buildPromotionInfoItemForDeployedSlotCount(build, 0))
}
}

private fun buildPromotionInfoItemForDeployedSlotPipeline(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class EnvironmentsBuildPromotionInfoExtensionIT : AbstractDSLTestSupport() {

info.items[index++].apply {
assertNull(promotionLevel)
assertEquals(eligibleSlotWithSilverPromotionRulePipeline.id, (data as SlotPipeline).id)
assertEquals(eligibleSlotWithSilverPromotionRulePipeline?.id, (data as SlotPipeline).id)
}

info.items[index++].apply {
assertNull(promotionLevel)
assertEquals(eligibleSlotWithNoPromotionRulePipeline.id, (data as SlotPipeline).id)
assertEquals(eligibleSlotWithNoPromotionRulePipeline?.id, (data as SlotPipeline).id)
}

// Then the promotions & their promotion runs
Expand Down Expand Up @@ -105,7 +105,65 @@ class EnvironmentsBuildPromotionInfoExtensionIT : AbstractDSLTestSupport() {

info.items[index++].apply {
assertEquals(null, promotionLevel)
assertEquals(eligibleSlotWithSilverPromotionRulePipeline.id, (data as SlotPipeline).id)
assertEquals(eligibleSlotWithSilverPromotionRulePipeline?.id, (data as SlotPipeline).id)
}

// Then the promotions & their promotion runs

info.items[index++].apply {
assertEquals(gold, promotionLevel)
assertEquals(gold, data)
}

info.items[index++].apply {
assertEquals(silver, promotionLevel)
assertEquals(runSilver.id, (data as PromotionRun).id)
}

info.items[index++].apply {
assertEquals(bronze, promotionLevel)
assertEquals(runBronze2.id, (data as PromotionRun).id)
}

info.items[index].apply {
assertEquals(bronze, promotionLevel)
assertEquals(runBronze1.id, (data as PromotionRun).id)
}
}
}

@Test
fun `Getting the promotion info for a build with display option being HIGHEST and not deployed anywhere`() {
environmentsBuildPromotionInfoExtensionTestSupport.withSetup(
buildDisplayOption = EnvironmentsSettingsBuildDisplayOption.HIGHEST,
deployed = false,
) { test ->

val (
build,
info,
bronze,
silver,
gold,
runBronze1,
runBronze2,
runSilver,
_,
_,
_,
_,
) = test


// Checking all items have been collected
assertEquals(5, info.items.size)
var index = 0

// First, the slot where the build is deployed

info.items[index++].apply {
assertEquals(null, promotionLevel)
assertEquals(EnvironmentBuildCount(build, count = 0), data)
}

// Then the promotions & their promotion runs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class EnvironmentsBuildPromotionInfoExtensionTestSupport : AbstractDSLTestSuppor

fun withSetup(
buildDisplayOption: EnvironmentsSettingsBuildDisplayOption,
deployed: Boolean = true,
test: (info: TestInfo) -> Unit,
) {
asAdmin {
Expand Down Expand Up @@ -80,24 +81,32 @@ class EnvironmentsBuildPromotionInfoExtensionTestSupport : AbstractDSLTestSuppor
val runBronze2 = promote(bronze)
val runSilver = promote(silver)

val eligibleSlotWithNoPromotionRulePipeline = slotService.startPipeline(
slot = eligibleSlotWithNoPromotionRule,
build = this,
).apply {
slotTestSupport.startAndDeployPipeline(this)
val eligibleSlotWithNoPromotionRulePipeline = if (deployed) {
slotService.startPipeline(
slot = eligibleSlotWithNoPromotionRule,
build = this,
).apply {
slotTestSupport.startAndDeployPipeline(this)
}
} else {
null
}

val eligibleSlotWithSilverPromotionRulePipeline =
val eligibleSlotWithSilverPromotionRulePipeline = if (deployed) {
slotService.startPipeline(
slot = eligibleSlotWithSilverPromotionRule,
build = this,
).apply {
slotTestSupport.startAndDeployPipeline(this)
}
} else {
null
}

// Checking that everything is marked as deployed
val pipelines = slotService.findSlotPipelinesWhereBuildIsLastDeployed(this)
assertEquals(2, pipelines.size, "All pipelines deployed")
val count = if (deployed) 2 else 0
assertEquals(count, pipelines.size, "All pipelines deployed")

val info = buildPromotionInfoService.getBuildPromotionInfo(this)

Expand Down Expand Up @@ -135,9 +144,9 @@ class EnvironmentsBuildPromotionInfoExtensionTestSupport : AbstractDSLTestSuppor
val runBronze2: PromotionRun,
val runSilver: PromotionRun,
val eligibleSlotWithNoPromotionRule: Slot,
val eligibleSlotWithNoPromotionRulePipeline: SlotPipeline,
val eligibleSlotWithNoPromotionRulePipeline: SlotPipeline?,
val eligibleSlotWithSilverPromotionRule: Slot,
val eligibleSlotWithSilverPromotionRulePipeline: SlotPipeline,
val eligibleSlotWithSilverPromotionRulePipeline: SlotPipeline?,
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class EnvironmentsBuildPromotionInfoExtensionGraphQLIT : AbstractQLKTITSupport()
"promotionLevel" to null,
"data" to mapOf(
"__typename" to "SlotPipeline",
"id" to eligibleSlotWithSilverPromotionRulePipeline.id
"id" to eligibleSlotWithSilverPromotionRulePipeline?.id
)
),
mapOf(
Expand Down

0 comments on commit 7d547e8

Please sign in to comment.