Skip to content

Commit ce0cfeb

Browse files
authored
conformance: add Hook in ConformanceTestSuite (#3786)
* conformance: add Hook in ConformanceTestSuite * update comment Signed-off-by: zirain <[email protected]> * add Hook in ConformanceOptions Signed-off-by: zirain <[email protected]> --------- Signed-off-by: zirain <[email protected]>
1 parent fe41f50 commit ce0cfeb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

conformance/utils/suite/suite.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type ConformanceTestSuite struct {
7474
SkipTests sets.Set[string]
7575
SkipProvisionalTests bool
7676
RunTest string
77+
Hook func(t *testing.T, test ConformanceTest, suite *ConformanceTestSuite)
7778
ManifestFS []fs.FS
7879
UsableNetworkAddresses []v1beta1.GatewaySpecAddress
7980
UnusableNetworkAddresses []v1beta1.GatewaySpecAddress
@@ -121,7 +122,7 @@ type ConformanceTestSuite struct {
121122
lock sync.RWMutex
122123
}
123124

124-
// Options can be used to initialize a ConformanceTestSuite.
125+
// ConformanceOptions can be used to initialize a ConformanceTestSuite.
125126
type ConformanceOptions struct {
126127
Client client.Client
127128
ClientOptions client.Options
@@ -152,7 +153,8 @@ type ConformanceOptions struct {
152153
SkipProvisionalTests bool
153154
// RunTest is a single test to run, mostly for development/debugging convenience.
154155
RunTest string
155-
156+
// Hook is an optional function that can be used to run custom logic after each test at suite level.
157+
Hook func(t *testing.T, test ConformanceTest, suite *ConformanceTestSuite)
156158
ManifestFS []fs.FS
157159

158160
// UsableNetworkAddresses is an optional pool of usable addresses for
@@ -268,6 +270,7 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
268270
mode: mode,
269271
apiVersion: apiVersion,
270272
apiChannel: apiChannel,
273+
Hook: options.Hook,
271274
}
272275

273276
for _, conformanceProfileName := range options.ConformanceProfiles.UnsortedList() {
@@ -470,6 +473,13 @@ func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) er
470473
if res == testSucceeded || res == testFailed {
471474
sleepForTestIsolation = true
472475
}
476+
477+
// call the hook function if it was provided,
478+
// this's useful for running custom logic after each test at suite level,
479+
// such as collecting current state of the cluster for debugging.
480+
if suite.Hook != nil {
481+
suite.Hook(t, test, suite)
482+
}
473483
}
474484

475485
// now that the tests have completed, mark the test suite as not running

0 commit comments

Comments
 (0)