|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "context" |
| 4 | + "fmt" |
5 | 5 | "os"
|
6 | 6 | "strings"
|
7 |
| - "time" |
8 | 7 |
|
9 |
| - "github.com/onsi/ginkgo/v2" |
10 |
| - "github.com/onsi/gomega" |
11 | 8 | "github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
|
12 |
| - "github.com/openshift-eng/openshift-tests-extension/pkg/dbtime" |
13 |
| - "github.com/openshift-eng/openshift-tests-extension/pkg/extension" |
14 |
| - "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests" |
| 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" |
15 | 12 |
|
16 | 13 | "github.com/spf13/cobra"
|
17 | 14 |
|
| 15 | + // The import below is necessary to ensure that the kube controller manager operator tests are registered with the extension. |
18 | 16 | _ "github.com/openshift/cluster-kube-controller-manager-operator/test/extended"
|
19 | 17 | )
|
20 | 18 |
|
21 |
| -var ( |
22 |
| - CommitFromGit string |
23 |
| - BuildDate string |
24 |
| - GitTreeState string |
25 |
| -) |
26 |
| - |
27 |
| -// GinkgoTestingT implements the minimal TestingT interface needed by Ginkgo |
28 |
| -type GinkgoTestingT struct{} |
29 |
| - |
30 |
| -func (GinkgoTestingT) Errorf(format string, args ...interface{}) {} |
31 |
| -func (GinkgoTestingT) Fail() {} |
32 |
| -func (GinkgoTestingT) FailNow() { os.Exit(1) } |
33 |
| - |
34 |
| -// NewGinkgoTestingT creates a new testing.T compatible instance for Ginkgo |
35 |
| -func NewGinkgoTestingT() *GinkgoTestingT { |
36 |
| - return &GinkgoTestingT{} |
37 |
| -} |
38 |
| - |
39 |
| -// escapeRegexChars escapes special regex characters in test names for Ginkgo focus |
40 |
| -func escapeRegexChars(s string) string { |
41 |
| - // Only escape the problematic characters that cause regex parsing issues |
42 |
| - // We need to escape [ and ] which are treated as character classes |
43 |
| - s = strings.ReplaceAll(s, "[", "\\[") |
44 |
| - s = strings.ReplaceAll(s, "]", "\\]") |
45 |
| - return s |
46 |
| -} |
47 |
| - |
48 |
| -// createTestSpec creates a test spec with proper execution functions |
49 |
| -func createTestSpec(name, source string, codeLocations []string) *extensiontests.ExtensionTestSpec { |
50 |
| - return &extensiontests.ExtensionTestSpec{ |
51 |
| - Name: name, |
52 |
| - Source: source, |
53 |
| - CodeLocations: codeLocations, |
54 |
| - Lifecycle: extensiontests.LifecycleBlocking, |
55 |
| - Resources: extensiontests.Resources{ |
56 |
| - Isolation: extensiontests.Isolation{}, |
57 |
| - }, |
58 |
| - EnvironmentSelector: extensiontests.EnvironmentSelector{}, |
59 |
| - Run: func(ctx context.Context) *extensiontests.ExtensionTestResult { |
60 |
| - return runGinkgoTest(ctx, name) |
61 |
| - }, |
62 |
| - RunParallel: func(ctx context.Context) *extensiontests.ExtensionTestResult { |
63 |
| - return runGinkgoTest(ctx, name) |
| 19 | +func main() { |
| 20 | + registry := e.NewRegistry() |
| 21 | + ext := e.NewExtension("openshift", "payload", "cluster-kube-controller-manager-operator") |
| 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]"))`, |
64 | 29 | },
|
65 |
| - } |
66 |
| -} |
67 |
| - |
68 |
| -// runGinkgoTest runs a Ginkgo test in-process |
69 |
| -func runGinkgoTest(ctx context.Context, testName string) *extensiontests.ExtensionTestResult { |
70 |
| - startTime := time.Now() |
71 |
| - |
72 |
| - // Configure Ginkgo to run specific test |
73 |
| - gomega.RegisterFailHandler(ginkgo.Fail) |
74 |
| - |
75 |
| - // Run the test suite with focus on specific test |
76 |
| - suiteConfig, reporterConfig := ginkgo.GinkgoConfiguration() |
77 |
| - suiteConfig.FocusStrings = []string{escapeRegexChars(testName)} |
78 |
| - |
79 |
| - passed := ginkgo.RunSpecs(NewGinkgoTestingT(), "OpenShift Kube Controller Manager Operator Test Suite", suiteConfig, reporterConfig) |
80 |
| - |
81 |
| - endTime := time.Now() |
82 |
| - duration := endTime.Sub(startTime) |
83 |
| - |
84 |
| - result := extensiontests.ResultPassed |
85 |
| - if !passed { |
86 |
| - result = extensiontests.ResultFailed |
87 |
| - } |
| 30 | + }) |
88 | 31 |
|
89 |
| - return &extensiontests.ExtensionTestResult{ |
90 |
| - Name: testName, |
91 |
| - Result: result, |
92 |
| - StartTime: dbtime.Ptr(startTime), |
93 |
| - EndTime: dbtime.Ptr(endTime), |
94 |
| - Duration: int64(duration.Seconds()), |
95 |
| - Output: "", |
96 |
| - } |
97 |
| -} |
| 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 | + }) |
98 | 40 |
|
99 |
| -func main() { |
100 |
| - // Create a new registry |
101 |
| - registry := extension.NewRegistry() |
| 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]")`, |
| 47 | + }, |
| 48 | + }) |
102 | 49 |
|
103 |
| - // Create extension for this component |
104 |
| - ext := extension.NewExtension("openshift", "payload", "cluster-kube-controller-manager-operator") |
| 50 | + // Suite: all (includes everything) |
| 51 | + ext.AddSuite(e.Suite{ |
| 52 | + Name: "openshift/cluster-kube-controller-manager-operator/all", |
| 53 | + }) |
105 | 54 |
|
106 |
| - // Set source information |
107 |
| - ext.Source = extension.Source{ |
108 |
| - Commit: CommitFromGit, |
109 |
| - BuildDate: BuildDate, |
110 |
| - GitTreeState: GitTreeState, |
| 55 | + specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite() |
| 56 | + if err != nil { |
| 57 | + panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error())) |
111 | 58 | }
|
112 | 59 |
|
113 |
| - // Add test suites |
114 |
| - ext.AddGlobalSuite(extension.Suite{ |
115 |
| - Name: "openshift/cluster-kube-controller-manager-operator/conformance/parallel", |
116 |
| - Description: "", |
117 |
| - Parents: []string{"openshift/conformance/parallel"}, |
118 |
| - Qualifiers: []string{"(source == \"openshift:payload:cluster-kube-controller-manager-operator\") && (!(name.contains(\"[Serial]\") || name.contains(\"[Slow]\")))"}, |
| 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 | + } |
119 | 69 | })
|
120 | 70 |
|
121 |
| - ext.AddGlobalSuite(extension.Suite{ |
122 |
| - Name: "openshift/cluster-kube-controller-manager-operator/conformance/serial", |
123 |
| - Description: "", |
124 |
| - Parents: []string{"openshift/conformance/serial"}, |
125 |
| - Qualifiers: []string{"(source == \"openshift:payload:cluster-kube-controller-manager-operator\") && (name.contains(\"[Serial]\"))"}, |
| 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 | + } |
126 | 81 | })
|
127 | 82 |
|
128 |
| - ext.AddGlobalSuite(extension.Suite{ |
129 |
| - Name: "openshift/cluster-kube-controller-manager-operator/optional/slow", |
130 |
| - Description: "", |
131 |
| - Parents: []string{"openshift/optional/slow"}, |
132 |
| - Qualifiers: []string{"(source == \"openshift:payload:cluster-kube-controller-manager-operator\") && (name.contains(\"[Slow]\"))"}, |
133 |
| - }) |
| 83 | + // Ignore obsolete tests |
| 84 | + ext.IgnoreObsoleteTests( |
| 85 | + // "[sig-kube-controller-manager] <test name here>", |
| 86 | + ) |
134 | 87 |
|
135 |
| - ext.AddGlobalSuite(extension.Suite{ |
136 |
| - Name: "openshift/cluster-kube-controller-manager-operator/all", |
137 |
| - Description: "", |
138 |
| - Qualifiers: []string{"source == \"openshift:payload:cluster-kube-controller-manager-operator\""}, |
| 88 | + // Initialize environment before running any tests |
| 89 | + specs.AddBeforeAll(func() { |
| 90 | + // do stuff |
139 | 91 | })
|
140 | 92 |
|
141 |
| - // Add test specs with proper execution functions |
142 |
| - testSpecs := extensiontests.ExtensionTestSpecs{ |
143 |
| - createTestSpec( |
144 |
| - "[Jira:kube-controller-manager][sig-api-machinery] sanity test should always pass [Suite:openshift/cluster-kube-controller-manager-operator/conformance/parallel]", |
145 |
| - "openshift:payload:cluster-kube-controller-manager-operator", |
146 |
| - []string{ |
147 |
| - "/test/extended/main.go:8", |
148 |
| - "/test/extended/main.go:9", |
149 |
| - }, |
150 |
| - ), |
151 |
| - } |
152 |
| - ext.AddSpecs(testSpecs) |
153 |
| - |
154 |
| - // Register the extension |
| 93 | + ext.AddSpecs(specs) |
155 | 94 | registry.Register(ext)
|
156 | 95 |
|
157 |
| - // Create root command with default extension commands |
158 |
| - rootCmd := &cobra.Command{ |
159 |
| - Use: "cluster-kube-controller-manager-operator-tests-ext", |
160 |
| - Short: "OpenShift kube-controller-manager operator tests extension", |
| 96 | + root := &cobra.Command{ |
| 97 | + Long: "Cluster Kube Controller Manager Operator Tests Extension", |
161 | 98 | }
|
162 | 99 |
|
163 |
| - // Add all the default extension commands (info, list, run-test, run-suite, update) |
164 |
| - rootCmd.AddCommand(cmd.DefaultExtensionCommands(registry)...) |
| 100 | + root.AddCommand(cmd.DefaultExtensionCommands(registry)...) |
165 | 101 |
|
166 |
| - // Execute the command |
167 |
| - if err := rootCmd.Execute(); err != nil { |
| 102 | + if err := root.Execute(); err != nil { |
168 | 103 | os.Exit(1)
|
169 | 104 | }
|
170 | 105 | }
|
0 commit comments