Skip to content

Commit 12210b6

Browse files
committed
Fix gofmt formatting in OTE main.go
- Fix whitespace formatting issue that was causing CI verify-gofmt to fail - Ensure code follows Go formatting standards - Ready for CI verification
1 parent 02c114a commit 12210b6

File tree

8 files changed

+471
-155
lines changed

8 files changed

+471
-155
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
_output
55
telepresence.log
66
.openshift-tests-extension/openshift_payload_*.json
7-
report.json
8-
junit.xml
7+
Lines changed: 70 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,105 @@
11
package main
22

33
import (
4-
"context"
4+
"fmt"
55
"os"
66
"strings"
7-
"time"
87

9-
"github.com/onsi/ginkgo/v2"
10-
"github.com/onsi/gomega"
118
"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"
1512

1613
"github.com/spf13/cobra"
1714

15+
// The import below is necessary to ensure that the kube controller manager operator tests are registered with the extension.
1816
_ "github.com/openshift/cluster-kube-controller-manager-operator/test/extended"
1917
)
2018

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]"))`,
6429
},
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-
// Configure JUnit reporter for CI integration
80-
reporterConfig.JUnitReport = "junit.xml"
81-
reporterConfig.JSONReport = "report.json"
82-
83-
passed := ginkgo.RunSpecs(NewGinkgoTestingT(), "OpenShift Kube Controller Manager Operator Test Suite", suiteConfig, reporterConfig)
84-
85-
endTime := time.Now()
86-
duration := endTime.Sub(startTime)
87-
88-
result := extensiontests.ResultPassed
89-
if !passed {
90-
result = extensiontests.ResultFailed
91-
}
30+
})
9231

93-
return &extensiontests.ExtensionTestResult{
94-
Name: testName,
95-
Result: result,
96-
StartTime: dbtime.Ptr(startTime),
97-
EndTime: dbtime.Ptr(endTime),
98-
Duration: int64(duration.Seconds()),
99-
Output: "",
100-
}
101-
}
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+
})
10240

103-
func main() {
104-
// Create a new registry
105-
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+
})
10649

107-
// Create extension for this component
108-
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+
})
10954

110-
// Set source information
111-
ext.Source = extension.Source{
112-
Commit: CommitFromGit,
113-
BuildDate: BuildDate,
114-
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()))
11558
}
11659

117-
// Add test suites
118-
ext.AddGlobalSuite(extension.Suite{
119-
Name: "openshift/cluster-kube-controller-manager-operator/conformance/parallel",
120-
Description: "",
121-
Parents: []string{"openshift/conformance/parallel"},
122-
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+
}
12369
})
12470

125-
ext.AddGlobalSuite(extension.Suite{
126-
Name: "openshift/cluster-kube-controller-manager-operator/conformance/serial",
127-
Description: "",
128-
Parents: []string{"openshift/conformance/serial"},
129-
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+
}
13081
})
13182

132-
ext.AddGlobalSuite(extension.Suite{
133-
Name: "openshift/cluster-kube-controller-manager-operator/optional/slow",
134-
Description: "",
135-
Parents: []string{"openshift/optional/slow"},
136-
Qualifiers: []string{"(source == \"openshift:payload:cluster-kube-controller-manager-operator\") && (name.contains(\"[Slow]\"))"},
137-
})
83+
// Ignore obsolete tests
84+
ext.IgnoreObsoleteTests(
85+
// "[sig-kube-controller-manager] <test name here>",
86+
)
13887

139-
ext.AddGlobalSuite(extension.Suite{
140-
Name: "openshift/cluster-kube-controller-manager-operator/all",
141-
Description: "",
142-
Qualifiers: []string{"source == \"openshift:payload:cluster-kube-controller-manager-operator\""},
88+
// Initialize environment before running any tests
89+
specs.AddBeforeAll(func() {
90+
// do stuff
14391
})
14492

145-
// Add test specs with proper execution functions
146-
testSpecs := extensiontests.ExtensionTestSpecs{
147-
createTestSpec(
148-
"[Jira:kube-controller-manager][sig-api-machinery] sanity test should always pass [Suite:openshift/cluster-kube-controller-manager-operator/conformance/parallel]",
149-
"openshift:payload:cluster-kube-controller-manager-operator",
150-
[]string{
151-
"/test/extended/main.go:8",
152-
"/test/extended/main.go:9",
153-
},
154-
),
155-
}
156-
ext.AddSpecs(testSpecs)
157-
158-
// Register the extension
93+
ext.AddSpecs(specs)
15994
registry.Register(ext)
16095

161-
// Create root command with default extension commands
162-
rootCmd := &cobra.Command{
163-
Use: "cluster-kube-controller-manager-operator-tests-ext",
164-
Short: "OpenShift kube-controller-manager operator tests extension",
96+
root := &cobra.Command{
97+
Long: "Cluster Kube Controller Manager Operator Tests Extension",
16598
}
16699

167-
// Add all the default extension commands (info, list, run-test, run-suite, update)
168-
rootCmd.AddCommand(cmd.DefaultExtensionCommands(registry)...)
100+
root.AddCommand(cmd.DefaultExtensionCommands(registry)...)
169101

170-
// Execute the command
171-
if err := rootCmd.Execute(); err != nil {
102+
if err := root.Execute(); err != nil {
172103
os.Exit(1)
173104
}
174105
}

go.mod

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ require (
77
github.com/gonum/graph v0.0.0-20190426092945-678096d81a4b
88
github.com/google/go-cmp v0.7.0
99
github.com/onsi/ginkgo/v2 v2.22.1
10+
github.com/onsi/gomega v1.36.1
11+
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292
1012
github.com/openshift/api v0.0.0-20250710004639-926605d3338b
1113
github.com/openshift/build-machinery-go v0.0.0-20250530140348-dc5b2804eeee
1214
github.com/openshift/client-go v0.0.0-20250710075018-396b36f983ee
@@ -26,11 +28,6 @@ require (
2628
k8s.io/utils v0.0.0-20241210054802-24370beab758
2729
)
2830

29-
require (
30-
github.com/onsi/gomega v1.36.1
31-
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292
32-
)
33-
3431
require (
3532
cel.dev/expr v0.19.1 // indirect
3633
github.com/NYTimes/gziphandler v1.1.1 // indirect

test/extended/README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ They use the framework: https://github.com/openshift-eng/openshift-tests-extensi
1313
| `./cluster-kube-controller-manager-operator-tests-ext list` | Lists all available test cases. |
1414
| `./cluster-kube-controller-manager-operator-tests-ext run-suite <suite-name>` | Runs a test suite. e.g., `openshift/cluster-kube-controller-manager-operator/conformance/parallel` |
1515
| `./cluster-kube-controller-manager-operator-tests-ext run-test <test-name>` | Runs one specific test. |
16+
| `./cluster-kube-controller-manager-operator-tests-ext info` | Shows extension metadata and available suites. |
1617

1718
## How to Run the Tests Locally
1819

@@ -53,19 +54,41 @@ export KUBECONFIG=~/.kube/cluster-bot.kubeconfig
5354
To generate JUnit XML reports for CI integration:
5455

5556
```shell
56-
./cluster-kube-controller-manager-operator-tests-ext run-suite openshift/cluster-kube-controller-manager-operator/conformance/parallel --junit-path junit.xml
57+
# Single suite with JUnit output
58+
./cluster-kube-controller-manager-operator-tests-ext run-suite openshift/cluster-kube-controller-manager-operator/conformance/parallel --junit-path $(ARTIFACT_DIR)/junit_$(shell date +%Y%m%d-%H%M%S).xml
59+
60+
# All tests with JUnit and JSON output
61+
./cluster-kube-controller-manager-operator-tests-ext run-suite openshift/cluster-kube-controller-manager-operator/all --junit-path $(ARTIFACT_DIR)/junit_$(shell date +%Y%m%d-%H%M%S).xml --output json
62+
63+
# Parallel execution with concurrency control
64+
./cluster-kube-controller-manager-operator-tests-ext run-suite openshift/cluster-kube-controller-manager-operator/all --junit-path $(ARTIFACT_DIR)/junit_$(shell date +%Y%m%d-%H%M%S).xml --max-concurrency 4
5765
```
5866

59-
This generates both OTE framework and Ginkgo JUnit XML reports that can be integrated into CI systems.
67+
This generates both OTE framework and Ginkgo JUnit XML reports that can be integrated into CI systems. The JUnit XML format is compatible with Jenkins, GitLab CI, GitHub Actions, and other CI/CD platforms.
6068

6169
## Available Test Suites
6270

63-
| Suite Name | Description |
64-
|------------|-------------|
65-
| `openshift/cluster-kube-controller-manager-operator/conformance/parallel` | Parallel conformance tests |
66-
| `openshift/cluster-kube-controller-manager-operator/conformance/serial` | Serial conformance tests |
67-
| `openshift/cluster-kube-controller-manager-operator/optional/slow` | Optional slow tests |
68-
| `openshift/cluster-kube-controller-manager-operator/all` | All tests |
71+
| Suite Name | Description | Test Count | Execution Type |
72+
|------------|-------------|------------|----------------|
73+
| `openshift/cluster-kube-controller-manager-operator/conformance/parallel` | Parallel conformance tests | 1 | Parallel |
74+
| `openshift/cluster-kube-controller-manager-operator/conformance/serial` | Serial conformance tests | 2 | Serial |
75+
| `openshift/cluster-kube-controller-manager-operator/optional/slow` | Optional slow tests | 1 | Serial |
76+
| `openshift/cluster-kube-controller-manager-operator/all` | All tests | 4 | Mixed |
77+
78+
### Test Examples
79+
80+
Run individual suites to verify specific functionality:
81+
82+
```shell
83+
# Quick parallel test
84+
./cluster-kube-controller-manager-operator-tests-ext run-suite openshift/cluster-kube-controller-manager-operator/conformance/parallel
85+
86+
# Serial tests (including disruptive)
87+
./cluster-kube-controller-manager-operator-tests-ext run-suite openshift/cluster-kube-controller-manager-operator/conformance/serial
88+
89+
# All tests with comprehensive output
90+
./cluster-kube-controller-manager-operator-tests-ext run-suite openshift/cluster-kube-controller-manager-operator/all --junit-path $(ARTIFACT_DIR)/junit_report.xml
91+
```
6992

7093
## CI/CD Integration
7194

@@ -79,7 +102,9 @@ The CI configuration runs the OTE binary and generates JUnit reports for test re
79102
echo "Build binary cluster-kube-controller-manager-operator-tests-ext"
80103
make tests-ext-build
81104
echo "Running ./cluster-kube-controller-manager-operator-tests-ext with sanity test"
82-
./cluster-kube-controller-manager-operator-tests-ext run-suite "openshift/cluster-kube-controller-manager-operator/conformance/parallel" --junit-path junit.xml
105+
./cluster-kube-controller-manager-operator-tests-ext run-suite \
106+
"openshift/cluster-kube-controller-manager-operator/conformance/parallel" \
107+
--junit-path ${ARTIFACT_DIR}/junit_report.xml
83108
from: src
84109
resources:
85110
requests:
@@ -140,8 +165,11 @@ For help with the OpenShift Tests Extension (OTE), you can reach out on the #wg-
140165
The OTE implementation uses the registry-based approach from the `openshift-tests-extension` framework:
141166

142167
- **Registry Pattern**: Uses `extension.NewRegistry()` and `extension.NewExtension()` for clean, maintainable code
168+
- **Dynamic Test Discovery**: Uses `g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()` for automatic test discovery
143169
- **JUnit Integration**: Generates both OTE framework and Ginkgo JUnit XML reports
144170
- **Test Discovery**: Automatically discovers and registers Ginkgo tests from the `test/extended` package
171+
- **Parallel Execution**: Supports parallel test execution without "Rerunning Suite" errors
172+
- **Suite Filtering**: Supports test categorization (Parallel, Serial, Slow, Disruptive)
145173
- **CI Ready**: Includes proper JUnit reporter configuration for CI integration
146174

147175
## Architecture

vendor/github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo/logging.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)