|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
| 4 | + "context" |
5 | 5 | "os" |
6 | | - "strings" |
7 | | - |
8 | | - "github.com/openshift-eng/openshift-tests-extension/pkg/cmd" |
9 | | - e "github.com/openshift-eng/openshift-tests-extension/pkg/extension" |
10 | | - et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests" |
11 | | - g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo" |
12 | 6 |
|
13 | 7 | "github.com/spf13/cobra" |
| 8 | + "k8s.io/component-base/cli" |
| 9 | + |
| 10 | + otecmd "github.com/openshift-eng/openshift-tests-extension/pkg/cmd" |
| 11 | + oteextension "github.com/openshift-eng/openshift-tests-extension/pkg/extension" |
| 12 | + "github.com/openshift/cluster-kube-controller-manager-operator/pkg/version" |
14 | 13 |
|
15 | | - // The import below is necessary to ensure that the kube controller manager operator tests are registered with the extension. |
16 | | - _ "github.com/openshift/cluster-kube-controller-manager-operator/test/extended" |
| 14 | + "k8s.io/klog/v2" |
17 | 15 | ) |
18 | 16 |
|
19 | 17 | func main() { |
20 | | - registry := e.NewRegistry() |
21 | | - ext := e.NewExtension("openshift", "payload", "cluster-kube-controller-manager-operator") |
| 18 | + command := newOperatorTestCommand(context.Background()) |
| 19 | + code := cli.Run(command) |
| 20 | + os.Exit(code) |
| 21 | +} |
22 | 22 |
|
23 | | - // Suite: conformance/parallel (fast, parallel-safe) |
24 | | - ext.AddSuite(e.Suite{ |
25 | | - Name: "openshift/cluster-kube-controller-manager-operator/conformance/parallel", |
26 | | - Parents: []string{"openshift/conformance/parallel"}, |
27 | | - Qualifiers: []string{ |
28 | | - `!(name.contains("[Serial]") || name.contains("[Slow]"))`, |
29 | | - }, |
30 | | - }) |
| 23 | +func newOperatorTestCommand(ctx context.Context) *cobra.Command { |
| 24 | + registry := prepareOperatorTestsRegistry() |
31 | 25 |
|
32 | | - // Suite: conformance/serial (explicitly serial tests) |
33 | | - ext.AddSuite(e.Suite{ |
34 | | - Name: "openshift/cluster-kube-controller-manager-operator/conformance/serial", |
35 | | - Parents: []string{"openshift/conformance/serial"}, |
36 | | - Qualifiers: []string{ |
37 | | - `name.contains("[Serial]")`, |
38 | | - }, |
39 | | - }) |
40 | | - |
41 | | - // Suite: optional/slow (long-running tests) |
42 | | - ext.AddSuite(e.Suite{ |
43 | | - Name: "openshift/cluster-kube-controller-manager-operator/optional/slow", |
44 | | - Parents: []string{"openshift/optional/slow"}, |
45 | | - Qualifiers: []string{ |
46 | | - `name.contains("[Slow]")`, |
| 26 | + cmd := &cobra.Command{ |
| 27 | + Use: "cluster-kube-controller-manager-operator-tests-ext", |
| 28 | + Short: "A binary used to run cluster-kube-controller-manager-operator tests as part of OTE.", |
| 29 | + Run: func(cmd *cobra.Command, args []string) { |
| 30 | + if err := cmd.Help(); err != nil { |
| 31 | + klog.Fatal(err) |
| 32 | + } |
47 | 33 | }, |
48 | | - }) |
49 | | - |
50 | | - // Suite: all (includes everything) |
51 | | - ext.AddSuite(e.Suite{ |
52 | | - Name: "openshift/cluster-kube-controller-manager-operator/all", |
53 | | - }) |
54 | | - |
55 | | - specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite() |
56 | | - if err != nil { |
57 | | - panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error())) |
58 | 34 | } |
59 | 35 |
|
60 | | - // Ensure [Disruptive] tests are also [Serial] (for any future tests that might need this) |
61 | | - specs = specs.Walk(func(spec *et.ExtensionTestSpec) { |
62 | | - if strings.Contains(spec.Name, "[Disruptive]") && !strings.Contains(spec.Name, "[Serial]") { |
63 | | - spec.Name = strings.ReplaceAll( |
64 | | - spec.Name, |
65 | | - "[Disruptive]", |
66 | | - "[Serial][Disruptive]", |
67 | | - ) |
68 | | - } |
69 | | - }) |
70 | | - |
71 | | - // Preserve original-name labels for renamed tests |
72 | | - specs = specs.Walk(func(spec *et.ExtensionTestSpec) { |
73 | | - for label := range spec.Labels { |
74 | | - if strings.HasPrefix(label, "original-name:") { |
75 | | - parts := strings.SplitN(label, "original-name:", 2) |
76 | | - if len(parts) > 1 { |
77 | | - spec.OriginalName = parts[1] |
78 | | - } |
79 | | - } |
80 | | - } |
81 | | - }) |
82 | | - |
83 | | - // Ignore obsolete tests |
84 | | - ext.IgnoreObsoleteTests( |
85 | | - // "[sig-kube-controller-manager] <test name here>", |
86 | | - ) |
87 | | - |
88 | | - // Initialize environment before running any tests |
89 | | - specs.AddBeforeAll(func() { |
90 | | - // do stuff |
91 | | - }) |
| 36 | + if v := version.Get().String(); len(v) == 0 { |
| 37 | + cmd.Version = "<unknown>" |
| 38 | + } else { |
| 39 | + cmd.Version = v |
| 40 | + } |
92 | 41 |
|
93 | | - ext.AddSpecs(specs) |
94 | | - registry.Register(ext) |
| 42 | + cmd.AddCommand(otecmd.DefaultExtensionCommands(registry)...) |
95 | 43 |
|
96 | | - root := &cobra.Command{ |
97 | | - Long: "Cluster Kube Controller Manager Operator Tests Extension", |
98 | | - } |
| 44 | + return cmd |
| 45 | +} |
99 | 46 |
|
100 | | - root.AddCommand(cmd.DefaultExtensionCommands(registry)...) |
| 47 | +func prepareOperatorTestsRegistry() *oteextension.Registry { |
| 48 | + registry := oteextension.NewRegistry() |
| 49 | + extension := oteextension.NewExtension("openshift", "payload", "cluster-kube-controller-manager-operator") |
101 | 50 |
|
102 | | - if err := root.Execute(); err != nil { |
103 | | - os.Exit(1) |
104 | | - } |
| 51 | + registry.Register(extension) |
| 52 | + return registry |
105 | 53 | } |
0 commit comments