From 7c3688b0618f51263c89941186889609189da99b Mon Sep 17 00:00:00 2001 From: Erik Burton Date: Thu, 11 Dec 2025 11:04:29 -0800 Subject: [PATCH] feat: add BelongsToCISuite test utility --- pkg/utils/tests/tests.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/utils/tests/tests.go b/pkg/utils/tests/tests.go index dd0173c89e..f4cb6b5ab6 100644 --- a/pkg/utils/tests/tests.go +++ b/pkg/utils/tests/tests.go @@ -97,3 +97,29 @@ func SkipFlakey(t *testing.T, ticketURL string) { t.Skip("Flakey", ticketURL) } } + +const envVarTestSuite = "CL_CURRENT_TEST_SUITE" + +// BelongsToCISuite declares the test's suite, and only runs the tests if the environment is configured +// to run the given suite. Usage inside a test: +// +// func TestFoo(t *testing.T) { +// testutil.BelongsToCISuite(t, "integration") +// ... +// } +// +// If CL_CURRENT_TEST_SUITE is not set, all tests are run. +// If CL_CURRENT_TEST_SUITE is set, only tests belonging to that suite are run; others are skipped. +// +// In general - this allows CI pipelines to run more targeted tests, to speed up feedback loops. +func BelongsToCISuite(t *testing.T, suite string) { + t.Helper() + + envSuite := os.Getenv(envVarTestSuite) + if envSuite == "" { + return + } + if envSuite != suite { + t.Skipf("Skipping test: suite %q does not match %s=%q", suite, envVarTestSuite, envSuite) + } +}