@@ -8,27 +8,43 @@ https://github.com/openshift-eng/openshift-tests-extension/blob/main/cmd/example
88package main
99
1010import (
11- "context "
11+ "fmt "
1212 "os"
13+ "strings"
1314
15+ otecmd "github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
16+ oteextension "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
17+ et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
18+ g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
1419 "github.com/spf13/cobra"
1520 "k8s.io/component-base/cli"
21+ "k8s.io/klog/v2"
1622
17- otecmd "github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
18- oteextension "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
1923 "github.com/openshift/cluster-kube-apiserver-operator/pkg/version"
2024
21- "k8s.io/klog/v2"
25+ // Import test packages to register Ginkgo tests
26+ _ "github.com/openshift/cluster-kube-apiserver-operator/test/e2e"
27+ _ "github.com/openshift/cluster-kube-apiserver-operator/test/e2e-encryption"
28+ _ "github.com/openshift/cluster-kube-apiserver-operator/test/e2e-encryption-perf"
29+ _ "github.com/openshift/cluster-kube-apiserver-operator/test/e2e-encryption-rotation"
30+ _ "github.com/openshift/cluster-kube-apiserver-operator/test/e2e-sno-disruptive"
2231)
2332
2433func main () {
25- command := newOperatorTestCommand (context .Background ())
26- code := cli .Run (command )
34+ cmd , err := newOperatorTestCommand ()
35+ if err != nil {
36+ klog .Fatal (err )
37+ }
38+
39+ code := cli .Run (cmd )
2740 os .Exit (code )
2841}
2942
30- func newOperatorTestCommand (ctx context.Context ) * cobra.Command {
31- registry := prepareOperatorTestsRegistry ()
43+ func newOperatorTestCommand () (* cobra.Command , error ) {
44+ registry , err := prepareOperatorTestsRegistry ()
45+ if err != nil {
46+ return nil , fmt .Errorf ("failed to prepare test registry: %w" , err )
47+ }
3248
3349 cmd := & cobra.Command {
3450 Use : "cluster-kube-apiserver-operator-tests" ,
@@ -49,18 +65,90 @@ func newOperatorTestCommand(ctx context.Context) *cobra.Command {
4965
5066 cmd .AddCommand (otecmd .DefaultExtensionCommands (registry )... )
5167
52- return cmd
68+ return cmd , nil
5369}
5470
5571// prepareOperatorTestsRegistry creates the OTE registry for this operator.
5672//
5773// Note:
5874//
5975// This method must be called before adding the registry to the OTE framework.
60- func prepareOperatorTestsRegistry () * oteextension.Registry {
76+ func prepareOperatorTestsRegistry () ( * oteextension.Registry , error ) {
6177 registry := oteextension .NewRegistry ()
6278 extension := oteextension .NewExtension ("openshift" , "payload" , "cluster-kube-apiserver-operator" )
6379
80+ // Suite: conformance/parallel (fast, parallel-safe)
81+ // Rule: Tests without [Serial] or [Slow] tags run in parallel
82+ // [Timeout:] tag is allowed - it just means the test needs more time
83+ extension .AddSuite (oteextension.Suite {
84+ Name : "openshift/cluster-kube-apiserver-operator/conformance/parallel" ,
85+ Parents : []string {"openshift/conformance/parallel" },
86+ Qualifiers : []string {
87+ `!(name.contains("[Serial]") || name.contains("[Slow]"))` ,
88+ },
89+ })
90+
91+ // Suite: conformance/serial (explicitly serial tests, but NOT slow tests)
92+ // Rule: Tests with [Serial] but NOT [Slow]
93+ // [Serial][Timeout:] tests go here (serial test that needs extra time)
94+ extension .AddSuite (oteextension.Suite {
95+ Name : "openshift/cluster-kube-apiserver-operator/conformance/serial" ,
96+ Parents : []string {"openshift/conformance/serial" },
97+ Qualifiers : []string {
98+ `name.contains("[Serial]") && !name.contains("[Slow]")` ,
99+ },
100+ })
101+
102+ // Suite: optional/slow (long-running tests marked with [Slow] tag)
103+ // Rule: Only tests with [Slow] tag
104+ // Can be [Slow], [Slow][Serial], [Slow][Timeout:60m], etc.
105+ extension .AddSuite (oteextension.Suite {
106+ Name : "openshift/cluster-kube-apiserver-operator/optional/slow" ,
107+ Parents : []string {"openshift/optional/slow" },
108+ Qualifiers : []string {
109+ `name.contains("[Slow]")` ,
110+ },
111+ })
112+
113+ // Suite: all (includes everything)
114+ extension .AddSuite (oteextension.Suite {
115+ Name : "openshift/cluster-kube-apiserver-operator/all" ,
116+ })
117+
118+ // Build Ginkgo test specs from test/e2e package
119+ // This includes all tests wrapped with Ginkgo (operator_ginkgo_test.go)
120+ specs , err := g .BuildExtensionTestSpecsFromOpenShiftGinkgoSuite ()
121+ if err != nil {
122+ return nil , fmt .Errorf ("couldn't build extension test specs from ginkgo: %w" , err )
123+ }
124+
125+ // Extract timeout from test name if present (e.g., [Timeout:50m])
126+ specs = specs .Walk (func (spec * et.ExtensionTestSpec ) {
127+ // Look for [Timeout:XXm] or [Timeout:XXh] pattern in test name
128+ if strings .Contains (spec .Name , "[Timeout:" ) {
129+ start := strings .Index (spec .Name , "[Timeout:" )
130+ if start != - 1 {
131+ end := strings .Index (spec .Name [start :], "]" )
132+ if end != - 1 {
133+ // Extract the timeout value (e.g., "50m" from "[Timeout:50m]")
134+ timeoutTag := spec .Name [start + len ("[Timeout:" ) : start + end ]
135+ if spec .Tags == nil {
136+ spec .Tags = make (map [string ]string )
137+ }
138+ spec .Tags ["timeout" ] = timeoutTag
139+ }
140+ }
141+ }
142+ })
143+
144+ // Ignore obsolete tests (for update command validation only)
145+ extension .IgnoreObsoleteTests (
146+ // "[sig-api-machinery] kube-apiserver operator TestOldTest",
147+ )
148+
149+ // Add the discovered test specs to the extension
150+ extension .AddSpecs (specs )
151+
64152 registry .Register (extension )
65- return registry
153+ return registry , nil
66154}
0 commit comments