Skip to content

Commit

Permalink
Changes to test utils originally added in #10233
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahFrench committed Mar 26, 2024
1 parent f94fe59 commit 7cda527
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions mmv1/third_party/terraform/.teamcity/tests/test_utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
package tests

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

const val gaProjectName = "Google"
const val betaProjectName = "Google Beta"
Expand Down Expand Up @@ -54,17 +55,32 @@ fun testContextParameters(): AllContextParameters {
"vcrBucketName")
}

fun getSubProject(rootProject: Project, parentProjectName: String, subProjectName: String): Project {
// getNestedProjectFromRoot allows you to retrieve a project that's 2 levels deep from the root project,
// Using the names of the parent and desired project.
// E.g. Root > Project A > Project B - you need to supply the inputs "Project A" and "Project B"
fun getNestedProjectFromRoot(root: Project, parentName: String, nestedProjectName: String): Project {
// Find parent project within root
var 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 parent: Project = getSubProject(root, parentName)
return getSubProject(parent, nestedProjectName)
}

// getSubProject allows you to retrieve a project nested inside a given project you've already identified,
// using its name.
fun getSubProject(parent: Project, subProjectName: String): Project {
// Find parent project within root
val subProject: Project? = parent.subProjects.find { p-> p.name == subProjectName}
if (subProject == null) {
Assert.fail("Could not find the $subProjectName project")
fail("Could not find the $subProjectName project inside ${parent.name}")
}

return subProject!!
}

// getBuildFromProject allows you to retrieve a build configuration from an identified project using its name
fun getBuildFromProject(parentProject: Project, buildName: String): BuildType {
val buildType: BuildType? = parentProject!!.buildTypes.find { p-> p.name == buildName}
if (buildType == null) {
fail("Could not find the '$buildName' build in project ${parentProject.name}")
}

return buildType!!
}

0 comments on commit 7cda527

Please sign in to comment.