GoogleCloudPlatform / k8s-config-connector

GCP Config Connector, a Kubernetes add-on for managing GCP resources
https://cloud.google.com/config-connector/docs/overview
Apache License 2.0
861 stars 202 forks source link

tests: add periodic tests that run one service per test #2204

Open justinsb opened 4 days ago

google-oss-prow[bot] commented 4 days ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Once this PR has been reviewed and has the lgtm label, please ask for approval from justinsb. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files: - **[OWNERS](https://github.com/GoogleCloudPlatform/k8s-config-connector/blob/master/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
gemmahou commented 4 days ago

I had something similar months ago(cl) to be able to run fixtures tests by services(and then run multiple services in parallel).

The code looks like(might need revise):

t.Run("fixtures", func(t *testing.T) {
  fixtures := resourcefixture.Load(t)

  groups := sets.NewString()
  for _, fixture := range fixtures {
      groups.Insert(fixture.GVK.Group)
  }

  for _, group := range groups.List() {
      group := group
      groupTestName := strings.TrimSuffix(group, ".cnrm.cloud.google.com")
      t.Run(groupTestName, func(t *testing.T) {
          // t.Parallel()
          for _, fixture := range fixtures {
              if fixture.GVK.Group != group {
                  continue
              }
              runTests(ctx, t, fixture, false)
          }
      })
  }
})

This way, we can use the parameter TestAllInSeries/fixtures/logging to run tests in one service, which would avoid adding an extra environment variable ONLY_TEST_APIGROUP. However, the downside is that we need to always include the service name even when running a single test case, such as TestAllInSeries/fixtures/logging/logginglogmetric.