Skip to content

Commit 7c3688b

Browse files
committed
feat: add BelongsToCISuite test utility
1 parent 319861e commit 7c3688b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pkg/utils/tests/tests.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,29 @@ func SkipFlakey(t *testing.T, ticketURL string) {
9797
t.Skip("Flakey", ticketURL)
9898
}
9999
}
100+
101+
const envVarTestSuite = "CL_CURRENT_TEST_SUITE"
102+
103+
// BelongsToCISuite declares the test's suite, and only runs the tests if the environment is configured
104+
// to run the given suite. Usage inside a test:
105+
//
106+
// func TestFoo(t *testing.T) {
107+
// testutil.BelongsToCISuite(t, "integration")
108+
// ...
109+
// }
110+
//
111+
// If CL_CURRENT_TEST_SUITE is not set, all tests are run.
112+
// If CL_CURRENT_TEST_SUITE is set, only tests belonging to that suite are run; others are skipped.
113+
//
114+
// In general - this allows CI pipelines to run more targeted tests, to speed up feedback loops.
115+
func BelongsToCISuite(t *testing.T, suite string) {
116+
t.Helper()
117+
118+
envSuite := os.Getenv(envVarTestSuite)
119+
if envSuite == "" {
120+
return
121+
}
122+
if envSuite != suite {
123+
t.Skipf("Skipping test: suite %q does not match %s=%q", suite, envVarTestSuite, envSuite)
124+
}
125+
}

0 commit comments

Comments
 (0)