Skip to content

Commit

Permalink
Consolidate testing of service sweeper builds, refactor `getSubProjec…
Browse files Browse the repository at this point in the history
…t` to return non-nullable value
  • Loading branch information
SarahFrench committed Feb 9, 2024
1 parent c401615 commit 4a3f822
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NightlyTestProjectsTests {
var betaNightlyTestProject = getSubProject(project, betaProjectName, nightlyTestsProjectName)

// Make assertions about builds in both nightly test projects
(gaNightlyTestProject!!.buildTypes + betaNightlyTestProject!!.buildTypes).forEach{bt ->
(gaNightlyTestProject.buildTypes + betaNightlyTestProject.buildTypes).forEach{bt ->
assertTrue("Build configuration `${bt.name}` contains at least one trigger", bt.triggers.items.isNotEmpty())
// Look for at least one CRON trigger
var found: Boolean = false
Expand Down
54 changes: 22 additions & 32 deletions mmv1/third_party/terraform/.teamcity/tests/sweepers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import projects.googleCloudRootProject

class SweeperTests {
@Test
fun projectSweeperProjectDoesNotSkipProjectSweep() {
fun projectSweeperDoesNotSkipProjectSweep() {
val project = googleCloudRootProject(testContextParameters())

// Find Project sweeper project
Expand All @@ -31,42 +31,32 @@ class SweeperTests {
}

@Test
fun gaNightlyProjectServiceSweeperSkipsProjectSweep() {
fun serviceSweepersSkipProjectSweeper() {
val project = googleCloudRootProject(testContextParameters())

// Find GA nightly test project
var gaNightlyTestProject = getSubProject(project, gaProjectName, nightlyTestsProjectName)

// Find sweeper inside
val sweeper: BuildType? = gaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName}
if (sweeper == null) {
Assert.fail("Could not find the sweeper build in the Google (GA) Nightly Test project")
}

// For the project sweeper to be skipped, SKIP_PROJECT_SWEEPER needs a value
// See https://github.com/GoogleCloudPlatform/magic-modules/blob/501429790939717ca6dce76dbf4b1b82aef4e9d9/mmv1/third_party/terraform/services/resourcemanager/resource_google_project_sweeper.go#L18-L26

val value = sweeper!!.params.findRawParam("env.SKIP_PROJECT_SWEEPER")!!.value
assertTrue("env.SKIP_PROJECT_SWEEPER is set to a non-empty string, so project sweepers are skipped. Value = `${value}` ", value != "")
}

@Test
fun betaNightlyProjectServiceSweeperSkipsProjectSweep() {
val project = googleCloudRootProject(testContextParameters())
val gaNightlyTestProject = getSubProject(project, gaProjectName, nightlyTestsProjectName)
// Find GA MM Upstream project
val gaMmUpstreamProject = getSubProject(project, gaProjectName, mmUpstreamProjectName)

// Find Beta nightly test project
var betaNightlyTestProject = getSubProject(project, betaProjectName, nightlyTestsProjectName)

// Find sweeper inside
val sweeper: BuildType? = betaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName}
if (sweeper == null) {
Assert.fail("Could not find the sweeper build in the Google (GA) Nightly Test project")
val betaNightlyTestProject = getSubProject(project, betaProjectName, nightlyTestsProjectName)
// Find Beta MM Upstream project
val betaMmUpstreamProject = getSubProject(project, betaProjectName, mmUpstreamProjectName)

val allProjects: ArrayList<Project> = arrayListOf(gaNightlyTestProject, gaMmUpstreamProject, betaNightlyTestProject, betaMmUpstreamProject)
allProjects.forEach{ project ->
// Find sweeper inside
val sweeper: BuildType? = project.buildTypes.find { p-> p.name == ServiceSweeperName}
if (sweeper == null) {
Assert.fail("Could not find the sweeper build in the ${project.name} project")
}

// For the project sweeper to be skipped, SKIP_PROJECT_SWEEPER needs a value
// See https://github.com/GoogleCloudPlatform/magic-modules/blob/501429790939717ca6dce76dbf4b1b82aef4e9d9/mmv1/third_party/terraform/services/resourcemanager/resource_google_project_sweeper.go#L18-L26

val value = sweeper!!.params.findRawParam("env.SKIP_PROJECT_SWEEPER")!!.value
assertTrue("env.SKIP_PROJECT_SWEEPER is set to a non-empty string in the sweeper build in the ${project.name} project. This means project sweepers are skipped. Value = `${value}` ", value != "")
}

// For the project sweeper to be skipped, SKIP_PROJECT_SWEEPER needs a value
// See https://github.com/GoogleCloudPlatform/magic-modules/blob/501429790939717ca6dce76dbf4b1b82aef4e9d9/mmv1/third_party/terraform/services/resourcemanager/resource_google_project_sweeper.go#L18-L26

val value = sweeper!!.params.findRawParam("env.SKIP_PROJECT_SWEEPER")!!.value
assertTrue("env.SKIP_PROJECT_SWEEPER is set to a non-empty string, so project sweepers are skipped. Value = `${value}` ", value != "")
}
}
5 changes: 3 additions & 2 deletions mmv1/third_party/terraform/.teamcity/tests/test_utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.junit.Assert
const val gaProjectName = "Google"
const val betaProjectName = "Google Beta"
const val nightlyTestsProjectName = "Nightly Tests"
const val mmUpstreamProjectName = "MM Upstream Testing"
const val projectSweeperProjectName = "Project Sweeper"

fun testContextParameters(): AllContextParameters {
Expand Down Expand Up @@ -48,7 +49,7 @@ fun testContextParameters(): AllContextParameters {
"vcrBucketName")
}

fun getSubProject(rootProject: Project, parentProjectName: String, subProjectName: String): Project? {
fun getSubProject(rootProject: Project, parentProjectName: String, subProjectName: String): Project {
// Find parent project within root
var parentProject: Project? = rootProject.subProjects.find { p-> p.name == parentProjectName}
if (parentProject == null) {
Expand All @@ -60,5 +61,5 @@ fun getSubProject(rootProject: Project, parentProjectName: String, subProjectNam
Assert.fail("Could not find the $subProjectName project")
}

return subProject
return subProject!!
}

0 comments on commit 4a3f822

Please sign in to comment.