Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeamCity: Refactor config tests #17460

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/9956.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
21 changes: 4 additions & 17 deletions .teamcity/tests/nightly_tests_project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,13 @@ class NightlyTestProjectsTests {
val project = googleCloudRootProject(testContextParameters())

// Find GA nightly test project
var gaProject: Project? = project.subProjects.find { p-> p.name == gaProjectName}
if (gaProject == null) {
Assert.fail("Could not find the Google (GA) project")
}
var gaNightlyTestProject: Project? = gaProject!!.subProjects.find { p-> p.name == nightlyTestsProjectName}
if (gaNightlyTestProject == null) {
Assert.fail("Could not find the Google (GA) Nightly Test project")
}
var gaNightlyTestProject = getSubProject(project, gaProjectName, nightlyTestsProjectName)

// Find Beta nightly test project
var betaProject: Project? = project.subProjects.find { p-> p.name == betaProjectName}
if (betaProject == null) {
Assert.fail("Could not find the Google (Beta) project")
}
var betaNightlyTestProject: Project? = betaProject!!.subProjects.find { p-> p.name == nightlyTestsProjectName}
if (betaNightlyTestProject == null) {
Assert.fail("Could not find the Google (GA) Nightly Test project")
}
var betaNightlyTestProject = getSubProject(project, betaProjectName, nightlyTestsProjectName)

(gaNightlyTestProject!!.buildTypes + betaNightlyTestProject!!.buildTypes).forEach{bt ->
// Make assertions about builds in both nightly test projects
(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
89 changes: 26 additions & 63 deletions .teamcity/tests/sweepers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import projects.googleCloudRootProject

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

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

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

// Find GA nightly test project
val gaProject: Project? = project.subProjects.find { p-> p.name == gaProjectName}
if (gaProject == null) {
Assert.fail("Could not find the Google (GA) project")
}
val gaNightlyTestProject: Project? = gaProject!!.subProjects.find { p-> p.name == nightlyTestsProjectName}
if (gaNightlyTestProject == null) {
Assert.fail("Could not find the Google (GA) Nightly Test project")
}
val gaNightlyTestProject = getSubProject(project, gaProjectName, nightlyTestsProjectName)
// Find GA MM Upstream project
val gaMmUpstreamProject = getSubProject(project, gaProjectName, mmUpstreamProjectName)

// 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")
// Find Beta 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 != "")
}

@Test
fun gaNightlyProjectServiceSweeperRunsInGoogle() {
val project = googleCloudRootProject(testContextParameters())

// Find GA nightly test project
val gaProject: Project? = project.subProjects.find { p-> p.name == gaProjectName}
if (gaProject == null) {
Assert.fail("Could not find the Google (GA) project")
}
val gaNightlyTestProject: Project? = gaProject!!.subProjects.find { p-> p.name == nightlyTestsProjectName}
if (gaNightlyTestProject == null) {
Assert.fail("Could not find the Google (GA) Nightly Test project")
}
val gaNightlyTestProject = getSubProject(project, gaProjectName, nightlyTestsProjectName)


// Find sweeper inside
val sweeper: BuildType? = gaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName}
Expand All @@ -88,46 +85,12 @@ class SweeperTests {
assertEquals("./google/sweeper", value)
}

@Test
fun betaNightlyProjectServiceSweeperSkipsProjectSweep() {
val project = googleCloudRootProject(testContextParameters())

// Find Beta nightly test project
val betaProject: Project? = project.subProjects.find { p-> p.name == betaProjectName}
if (betaProject == null) {
Assert.fail("Could not find the Google (GA) project")
}
val betaNightlyTestProject: Project? = betaProject!!.subProjects.find { p-> p.name == nightlyTestsProjectName}
if (betaNightlyTestProject == null) {
Assert.fail("Could not find the Google (GA) Nightly Test project")
}

// 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")
}

// 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 betaNightlyProjectServiceSweeperRunsInGoogleBeta() {
val project = googleCloudRootProject(testContextParameters())

// Find Beta nightly test project
val betaProject: Project? = project.subProjects.find { p-> p.name == betaProjectName}
if (betaProject == null) {
Assert.fail("Could not find the Google (GA) project")
}
val betaNightlyTestProject: Project? = betaProject!!.subProjects.find { p-> p.name == nightlyTestsProjectName}
if (betaNightlyTestProject == null) {
Assert.fail("Could not find the Google (GA) Nightly Test project")
}
val betaNightlyTestProject = getSubProject(project, betaProjectName, nightlyTestsProjectName)

// Find sweeper inside
val sweeper: BuildType? = betaNightlyTestProject!!.buildTypes.find { p-> p.name == ServiceSweeperName}
Expand Down
18 changes: 18 additions & 0 deletions .teamcity/tests/test_utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
package tests

import builds.AllContextParameters
import jetbrains.buildServer.configs.kotlin.Project
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 @@ -49,4 +52,19 @@ fun testContextParameters(): AllContextParameters {
"zone",
"infraProject",
"vcrBucketName")
}

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) {
Assert.fail("Could not find the $parentProjectName project")
}
// Find subproject within parent identified above
var subProject: Project? = parentProject!!.subProjects.find { p-> p.name == subProjectName}
if (subProject == null) {
Assert.fail("Could not find the $subProjectName project")
}

return subProject!!
}
Loading