@@ -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
@@ -105,32 +118,9 @@ func prepareOperatorTestsRegistry() *oteextension.Registry {
105118 // Build ginkgo test specs from the test/e2e package
106119 specs , err := g .BuildExtensionTestSpecsFromOpenShiftGinkgoSuite ()
107120 if err != nil {
108- panic ( fmt .Sprintf ("couldn't build extension test specs from ginkgo: %+v " , err . Error ()) )
121+ return nil , fmt .Errorf ("couldn't build extension test specs from ginkgo: %w " , err )
109122 }
110123
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-
134124 // Extract timeout from test name if present (e.g., [Timeout:50m])
135125 specs = specs .Walk (func (spec * et.ExtensionTestSpec ) {
136126 // Look for [Timeout:XXm] or [Timeout:XXh] pattern in test name
@@ -155,14 +145,9 @@ func prepareOperatorTestsRegistry() *oteextension.Registry {
155145 // "[sig-api-machinery] <test name here>",
156146 )
157147
158- // Initialize environment before running any tests
159- specs .AddBeforeAll (func () {
160- // do stuff
161- })
162-
163148 // Add the discovered test specs to the extension
164149 extension .AddSpecs (specs )
165150
166151 registry .Register (extension )
167- return registry
152+ return registry , nil
168153}
0 commit comments