From 7cda527af95dac73c9cdc8116968036852d04229 Mon Sep 17 00:00:00 2001 From: Sarah French Date: Thu, 21 Mar 2024 23:31:28 +0100 Subject: [PATCH] Changes to test utils originally added in https://github.com/GoogleCloudPlatform/magic-modules/pull/10233 --- .../terraform/.teamcity/tests/test_utils.kt | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/mmv1/third_party/terraform/.teamcity/tests/test_utils.kt b/mmv1/third_party/terraform/.teamcity/tests/test_utils.kt index 162a38eccf5c..d2cc224b63c5 100644 --- a/mmv1/third_party/terraform/.teamcity/tests/test_utils.kt +++ b/mmv1/third_party/terraform/.teamcity/tests/test_utils.kt @@ -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" @@ -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!! } \ No newline at end of file