Skip to content

Commit

Permalink
Add reusible test util that pulls a given build from a project, refac…
Browse files Browse the repository at this point in the history
…tor test
  • Loading branch information
SarahFrench committed Mar 19, 2024
1 parent 37d5287 commit eed3b30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
24 changes: 7 additions & 17 deletions mmv1/third_party/terraform/.teamcity/tests/sweepers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,20 @@ class SweeperTests {
val project = googleCloudRootProject(testContextParameters())

// Find GA nightly test project's service sweeper
val gaNightlyTestProject = getSubProject(project, gaProjectName, nightlyTestsProjectName)
val sweeperGa: BuildType? = gaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName}
if (sweeperGa == null) {
Assert.fail("Could not find the sweeper build in the Google (GA) Nightly Test project")
}
val gaNightlyTests: Project = getSubProject(project, gaProjectName, nightlyTestsProjectName)
val sweeperGa: BuildType = getBuildFromProject(gaNightlyTests, ServiceSweeperName)

// Find Beta nightly test project's service sweeper
val betaNightlyTestProject = getSubProject(project, betaProjectName, nightlyTestsProjectName)
val sweeperBeta: BuildType? = betaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName}
if (sweeperBeta == null) {
Assert.fail("Could not find the sweeper build in the Google (Beta) Nightly Test project")
}
val betaNightlyTests : Project = getSubProject(project, betaProjectName, nightlyTestsProjectName)
val sweeperBeta: BuildType = getBuildFromProject(betaNightlyTests, ServiceSweeperName)

// Find Project sweeper project's build
val projectSweeperProject: Project? = project.subProjects.find { p-> p.name == projectSweeperProjectName}
val projectSweeperProject : Project? = project.subProjects.find { p-> p.name == projectSweeperProjectName}
if (projectSweeperProject == null) {
Assert.fail("Could not find the Project Sweeper project")
}
val projectSweeper: BuildType? = projectSweeperProject!!.buildTypes.find { p-> p.name == ProjectSweeperName}
if (projectSweeper == null) {
Assert.fail("Could not find the sweeper build in the Google (Beta) Nightly Test project")
}


val projectSweeper: BuildType = getBuildFromProject(projectSweeperProject!!, ProjectSweeperName)

// Check only one schedule trigger is on the builds in question
assertTrue(sweeperGa!!.triggers.items.size == 1)
assertTrue(sweeperBeta!!.triggers.items.size == 1)
Expand Down
15 changes: 13 additions & 2 deletions mmv1/third_party/terraform/.teamcity/tests/test_utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
package tests

import builds.AllContextParameters
import jetbrains.buildServer.BuildProject
import jetbrains.buildServer.configs.kotlin.BuildType
import jetbrains.buildServer.configs.kotlin.Project
import org.junit.Assert

Expand Down Expand Up @@ -56,15 +58,24 @@ fun testContextParameters(): AllContextParameters {

fun getSubProject(rootProject: Project, parentProjectName: String, subProjectName: String): Project {
// Find parent project within root
var parentProject: Project? = rootProject.subProjects.find { p-> p.name == parentProjectName}
val parentProject: Project? = rootProject.subProjects.find { p-> p.name == parentProjectName}
if (parentProject == null) {
Assert.fail("Could not find the $parentProjectName project")
}
// Find subproject within parent identified above
var subProject: Project? = parentProject!!.subProjects.find { p-> p.name == subProjectName}
val subProject: Project? = parentProject!!.subProjects.find { p-> p.name == subProjectName}
if (subProject == null) {
Assert.fail("Could not find the $subProjectName project")
}

return subProject!!
}

fun getBuildFromProject(parentProject: Project, buildName: String): BuildType {
val buildType: BuildType? = parentProject!!.buildTypes.find { p-> p.name == buildName}
if (buildType == null) {
Assert.fail("Could not find the '$buildName' build in project ${parentProject.name}")
}

return buildType!!
}

0 comments on commit eed3b30

Please sign in to comment.