Skip to content

Commit

Permalink
✨ : add upToDate property
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Jun 9, 2021
1 parent 21f17ed commit adede7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/io/gaia_app/stacks/bo/Plan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ data class Plan(val id:String = UUID.randomUUID().toString(),
fun getDeleteCount() = resource_changes.count { it.change.actions.contains(ChangesTypes.DELETE) }
fun getNoOpCount() = resource_changes.count { it.change.actions.contains(ChangesTypes.NOOP) }

fun isUpToDate() = getCreateCount() == 0 && getUpdateCount() == 0 && getDeleteCount() == 0

}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/io/gaia_app/stacks/bo/PlanTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,28 @@ internal class PlanTest {
assertThat(plan.resource_changes).containsAll(listOf(container, image))
}

@Test
fun `a plan with no changes should be 'up to date'`() {
val plan = Plan(terraform_version = "0", resource_changes = listOf())
assertThat(plan.isUpToDate()).isTrue
}

@Test
fun `a plan with only no-op changes should be 'up to date'`() {
val noOpChange = ResourceChange("address", "provider", "type", Change(listOf(ChangesTypes.NOOP)))
val plan = Plan(terraform_version = "0", resource_changes = listOf(noOpChange))
assertThat(plan.isUpToDate()).isTrue
}

@Test
fun `a plan with at least one create,update, or delete should not be 'up to date'`() {
val createChange = ResourceChange("address", "provider", "type", Change(listOf(ChangesTypes.CREATE)))
val updateChange = ResourceChange("address", "provider", "type", Change(listOf(ChangesTypes.UPDATE)))
val deleteChange = ResourceChange("address", "provider", "type", Change(listOf(ChangesTypes.DELETE)))

assertThat(Plan(terraform_version = "0", resource_changes = listOf(createChange)).isUpToDate()).isFalse
assertThat(Plan(terraform_version = "0", resource_changes = listOf(updateChange)).isUpToDate()).isFalse
assertThat(Plan(terraform_version = "0", resource_changes = listOf(deleteChange)).isUpToDate()).isFalse
}

}

0 comments on commit adede7a

Please sign in to comment.