@@ -18,6 +18,7 @@ import (
1818 g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
1919 "github.com/spf13/cobra"
2020 "k8s.io/component-base/cli"
21+ "k8s.io/klog/v2"
2122
2223 "github.com/openshift/cluster-kube-apiserver-operator/pkg/version"
2324
@@ -26,15 +27,28 @@ import (
2627)
2728
2829func main () {
29- registry := prepareOperatorTestsRegistry ()
30+ cmd , err := newOperatorTestCommand ()
31+ if err != nil {
32+ klog .Fatal (err )
33+ }
34+
35+ code := cli .Run (cmd )
36+ os .Exit (code )
37+ }
38+
39+ func newOperatorTestCommand () (* cobra.Command , error ) {
40+ registry , err := prepareOperatorTestsRegistry ()
41+ if err != nil {
42+ return nil , fmt .Errorf ("failed to prepare test registry: %w" , err )
43+ }
44+
3045 cmd := & cobra.Command {
3146 Use : "cluster-kube-apiserver-operator-tests" ,
3247 Short : "A binary used to run cluster-kube-apiserver-operator tests as part of OTE." ,
3348 Run : func (cmd * cobra.Command , args []string ) {
3449 // no-op, logic is provided by the OTE framework
3550 if err := cmd .Help (); err != nil {
36- fmt .Fprintf (os .Stderr , "Error: %v\n " , err )
37- os .Exit (1 )
51+ klog .Fatal (err )
3852 }
3953 },
4054 }
@@ -47,16 +61,15 @@ func main() {
4761
4862 cmd .AddCommand (otecmd .DefaultExtensionCommands (registry )... )
4963
50- code := cli .Run (cmd )
51- os .Exit (code )
64+ return cmd , nil
5265}
5366
5467// prepareOperatorTestsRegistry creates the OTE registry for this operator.
5568//
5669// Note:
5770//
5871// This method must be called before adding the registry to the OTE framework.
59- func prepareOperatorTestsRegistry () * oteextension.Registry {
72+ func prepareOperatorTestsRegistry () ( * oteextension.Registry , error ) {
6073 registry := oteextension .NewRegistry ()
6174 extension := oteextension .NewExtension ("openshift" , "payload" , "cluster-kube-apiserver-operator" )
6275
@@ -76,9 +89,8 @@ func prepareOperatorTestsRegistry() *oteextension.Registry {
7689 // Exclude [Slow] tests - they go to slow suite instead
7790 // Parallelism: 1 enforces serial execution even when run without -c 1 flag
7891 extension .AddSuite (oteextension.Suite {
79- Name : "openshift/cluster-kube-apiserver-operator/conformance/serial" ,
80- Parents : []string {"openshift/conformance/serial" },
81- Parallelism : 1 ,
92+ Name : "openshift/cluster-kube-apiserver-operator/conformance/serial" ,
93+ Parents : []string {"openshift/conformance/serial" },
8294 Qualifiers : []string {
8395 `name.contains("[Serial]") && !name.contains("[Slow]")` ,
8496 },
@@ -89,9 +101,8 @@ func prepareOperatorTestsRegistry() *oteextension.Registry {
89101 // Tests with [Slow][Disruptive][Timeout:] will run serially due to [Serial] tag
90102 // Parallelism: 1 enforces serial execution even when run without -c 1 flag
91103 extension .AddSuite (oteextension.Suite {
92- Name : "openshift/cluster-kube-apiserver-operator/optional/slow" ,
93- Parents : []string {"openshift/optional/slow" },
94- Parallelism : 1 ,
104+ Name : "openshift/cluster-kube-apiserver-operator/optional/slow" ,
105+ Parents : []string {"openshift/optional/slow" },
95106 Qualifiers : []string {
96107 `name.contains("[Slow]") || (name.contains("[Timeout:") && !name.contains("[Serial]"))` ,
97108 },
@@ -105,32 +116,9 @@ func prepareOperatorTestsRegistry() *oteextension.Registry {
105116 // Build ginkgo test specs from the test/e2e package
106117 specs , err := g .BuildExtensionTestSpecsFromOpenShiftGinkgoSuite ()
107118 if err != nil {
108- panic ( fmt .Sprintf ("couldn't build extension test specs from ginkgo: %+v " , err . Error ()) )
119+ return nil , fmt .Errorf ("couldn't build extension test specs from ginkgo: %w " , err )
109120 }
110121
111- // Ensure [Disruptive] tests are also [Serial]
112- specs = specs .Walk (func (spec * et.ExtensionTestSpec ) {
113- if strings .Contains (spec .Name , "[Disruptive]" ) && ! strings .Contains (spec .Name , "[Serial]" ) {
114- spec .Name = strings .ReplaceAll (
115- spec .Name ,
116- "[Disruptive]" ,
117- "[Serial][Disruptive]" ,
118- )
119- }
120- })
121-
122- // Preserve original-name labels for renamed tests
123- specs = specs .Walk (func (spec * et.ExtensionTestSpec ) {
124- for label := range spec .Labels {
125- if strings .HasPrefix (label , "original-name:" ) {
126- parts := strings .SplitN (label , "original-name:" , 2 )
127- if len (parts ) > 1 {
128- spec .OriginalName = parts [1 ]
129- }
130- }
131- }
132- })
133-
134122 // Extract timeout from test name if present (e.g., [Timeout:50m])
135123 specs = specs .Walk (func (spec * et.ExtensionTestSpec ) {
136124 // Look for [Timeout:XXm] or [Timeout:XXh] pattern in test name
@@ -155,14 +143,9 @@ func prepareOperatorTestsRegistry() *oteextension.Registry {
155143 // "[sig-api-machinery] <test name here>",
156144 )
157145
158- // Initialize environment before running any tests
159- specs .AddBeforeAll (func () {
160- // do stuff
161- })
162-
163146 // Add the discovered test specs to the extension
164147 extension .AddSpecs (specs )
165148
166149 registry .Register (extension )
167- return registry
150+ return registry , nil
168151}
0 commit comments