Skip to content

Commit daabf23

Browse files
committed
Refactor test/extended to use OpenShift Tests Extension (OTE) framework
This commit refactors the openshift-apiserver extended tests to use the modern OpenShift Tests Extension (OTE) framework, following the pattern established in the service-ca-operator repository. Changes: - Migrate from test/extended/ to test/tests-extension/ directory structure - Implement OTE framework integration in cmd/main.go - Add comprehensive test coverage for openshift-apiserver components: * Deployment status and health checks * Pod running state validation * Service and endpoints verification * ConfigMap and Secret validation - Create proper Go module (go.mod/go.sum) for tests-extension - Add Makefile with build, test, and metadata management targets - Update main Makefile to include tests-extension targets - Add .gitignore and comprehensive README.md documentation - Generate test metadata for CI/CD pipeline integration Test suites available: - openshift/openshift-apiserver/all - openshift/openshift-apiserver/conformance/parallel - openshift/openshift-apiserver/conformance/serial - openshift/openshift-apiserver/optional/slow This refactoring modernizes the test infrastructure while maintaining backward compatibility and adding enhanced test coverage for the openshift-apiserver component. Resolves: Refactor test/extended to OTE framework
1 parent 42d570e commit daabf23

File tree

281 files changed

+622
-188328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+622
-188328
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

Makefile

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ IMAGE_REGISTRY?=registry.svc.ci.openshift.org
1414
# OpenShift Tests Extension (OpenShift API Server)
1515
# -------------------------------------------------------------------
1616
TESTS_EXT_BINARY := openshift-apiserver-tests-ext
17-
TESTS_EXT_PACKAGE := ./cmd/openshift-apiserver-tests-ext
17+
TESTS_EXT_PACKAGE := ./test/tests-extension/cmd
1818

1919
TESTS_EXT_GIT_COMMIT := $(shell git rev-parse --short HEAD)
2020
TESTS_EXT_BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
@@ -71,3 +71,36 @@ tests-ext-update: tests-ext-build
7171
for f in .openshift-tests-extension/*.json; do \
7272
jq 'map(del(.codeLocations))' "$f" > tmpp && mv tmpp "$f"; \
7373
done
74+
75+
# -------------------------------------------------------------------
76+
# Additional tests-extension targets
77+
# -------------------------------------------------------------------
78+
.PHONY: tests-ext-verify
79+
tests-ext-verify:
80+
cd test/tests-extension && make verify
81+
82+
.PHONY: tests-ext-clean
83+
tests-ext-clean:
84+
cd test/tests-extension && make clean
85+
86+
.PHONY: tests-ext-run-suite
87+
tests-ext-run-suite:
88+
cd test/tests-extension && make run-suite SUITE=$(SUITE) ARTIFACT_DIR=$(ARTIFACT_DIR)
89+
90+
.PHONY: tests-ext-list
91+
tests-ext-list:
92+
cd test/tests-extension && make list-test-names
93+
94+
.PHONY: tests-ext-build-update
95+
tests-ext-build-update:
96+
cd test/tests-extension && make build-update
97+
98+
# Add tests-extension targets to main targets
99+
all: tests-ext-build
100+
.PHONY: all
101+
102+
clean: tests-ext-clean
103+
.PHONY: clean
104+
105+
verify: tests-ext-verify
106+
.PHONY: verify

go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ require (
1616
github.com/google/gofuzz v1.2.0
1717
github.com/hashicorp/golang-lru v0.5.4
1818
github.com/jteeuwen/go-bindata v3.0.8-0.20151023091102-a0ff2567cfb7+incompatible
19-
github.com/onsi/ginkgo/v2 v2.23.4
20-
github.com/onsi/gomega v1.38.0
2119
github.com/opencontainers/go-digest v1.0.0
2220
github.com/opencontainers/image-spec v1.1.1
23-
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292
2421
github.com/openshift/api v0.0.0-20250820105013-6282350d0c39
2522
github.com/openshift/apiserver-library-go v0.0.0-20250710132015-f0d44ef6e53b
2623
github.com/openshift/build-machinery-go v0.0.0-20250806130835-622c0378eb0d
@@ -81,7 +78,6 @@ require (
8178
github.com/go-openapi/jsonpointer v0.21.1 // indirect
8279
github.com/go-openapi/jsonreference v0.21.0 // indirect
8380
github.com/go-openapi/swag v0.23.1 // indirect
84-
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
8581
github.com/gogo/protobuf v1.3.2 // indirect
8682
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
8783
github.com/golang/protobuf v1.5.4 // indirect
@@ -116,6 +112,8 @@ require (
116112
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
117113
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
118114
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
115+
github.com/onsi/ginkgo/v2 v2.23.4 // indirect
116+
github.com/onsi/gomega v1.38.0 // indirect
119117
github.com/opencontainers/runc v1.2.1 // indirect
120118
github.com/opencontainers/runtime-spec v1.2.0 // indirect
121119
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ github.com/opencontainers/runc v1.2.1 h1:mQkmeFSUxqFaVmvIn1VQPeQIKpHFya5R07aJw0D
250250
github.com/opencontainers/runc v1.2.1/go.mod h1:/PXzF0h531HTMsYQnmxXkBD7YaGShm/2zcRB79dksUc=
251251
github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk=
252252
github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
253-
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292 h1:3athg6KQ+TaNfW4BWZDlGFt1ImSZEJWgzXtPC1VPITI=
254-
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250804142706-7b3ab438a292/go.mod h1:6gkP5f2HL0meusT0Aim8icAspcD1cG055xxBZ9yC68M=
255253
github.com/openshift/api v0.0.0-20250820105013-6282350d0c39 h1:X42iTyo3AAHS36BkiBkU8FvxfK8NEDmnBi3QrnaCIlA=
256254
github.com/openshift/api v0.0.0-20250820105013-6282350d0c39/go.mod h1:SPLf21TYPipzCO67BURkCfK6dcIIxx0oNRVWaOyRcXM=
257255
github.com/openshift/apiserver-library-go v0.0.0-20250710132015-f0d44ef6e53b h1:rIfs2f1zo9GLyxk6tak2bHzX01VTz6Xheay2NECfZpg=

test/extended/main.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/tests-extension/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# Go workspace file
18+
go.work
19+
20+
# Build artifacts
21+
bin/
22+
.openshift-tests-extension/
23+
24+
# IDE files
25+
.vscode/
26+
.idea/
27+
*.swp
28+
*.swo
29+
*~
30+
31+
# OS generated files
32+
.DS_Store
33+
.DS_Store?
34+
._*
35+
.Spotlight-V100
36+
.Trashes
37+
ehthumbs.db
38+
Thumbs.db

test/tests-extension/Makefile

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Get the directory where this Makefile is, so we can use it below for including
2+
DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
3+
4+
# Definitions for the extended tests
5+
6+
GO_PKG_NAME := github.com/openshift-eng/openshift-tests-extension
7+
8+
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')
9+
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
10+
GIT_TREE_STATE := $(shell if git rev-parse --git-dir > /dev/null 2>&1; then if git diff --quiet; then echo clean; else echo dirty; fi; else echo unknown; fi)
11+
12+
LDFLAGS := -X '$(GO_PKG_NAME)/pkg/version.CommitFromGit=$(GIT_COMMIT)' \
13+
-X '$(GO_PKG_NAME)/pkg/version.BuildDate=$(BUILD_DATE)' \
14+
-X '$(GO_PKG_NAME)/pkg/version.GitTreeState=$(GIT_TREE_STATE)'
15+
16+
17+
METADATA := $(shell pwd)/.openshift-tests-extension/openshift_payload_openshift-apiserver.json
18+
19+
.PHONY: help
20+
help: #HELP Display essential help.
21+
@awk 'BEGIN {FS = ":[^#]*#HELP"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\n"} /^[a-zA-Z_0-9-]+:.*#HELP / { printf " \033[36m%-17s\033[0m %s\n", $$1, $$2 } ' $(MAKEFILE_LIST)
22+
23+
#SECTION Tests
24+
TOOLS_BIN_DIR := $(CURDIR)/bin
25+
26+
.PHONY: run-suite #HELP Run tests by suite name and generate JUnit report (e.g., make run-suite SUITE=openshift/openshift-apiserver/all ARTIFACT_DIR=/tmp/artifacts)
27+
run-suite: build #HELP Run tests by suite name and generate JUnit report
28+
@if [ -z "$(SUITE)" ]; then \
29+
echo "Error: SUITE variable is required. Available suites:"; \
30+
echo " - openshift/openshift-apiserver/all"; \
31+
echo " - openshift/openshift-apiserver/conformance/parallel"; \
32+
echo " - openshift/openshift-apiserver/conformance/serial"; \
33+
echo " - openshift/openshift-apiserver/optional/slow"; \
34+
echo ""; \
35+
echo "Usage: make run-suite SUITE=openshift/openshift-apiserver/all [ARTIFACT_DIR=/tmp/artifacts]"; \
36+
exit 1; \
37+
fi
38+
@if [ -z "$(ARTIFACT_DIR)" ]; then \
39+
echo "Warning: ARTIFACT_DIR not set, using current directory for JUnit report"; \
40+
ARTIFACT_DIR=.; \
41+
fi
42+
@mkdir -p $(ARTIFACT_DIR)
43+
$(TOOLS_BIN_DIR)/openshift-apiserver-tests-ext run-suite $(SUITE) -j $(ARTIFACT_DIR)/junit_$(shell date +%Y%m%d-%H%M%S).xml
44+
45+
#SECTION Development
46+
.PHONY: verify #HELP To verify the code
47+
verify: tidy fmt vet lint
48+
49+
.PHONY: tidy #HELP Run go mod tidy.
50+
tidy:
51+
go mod tidy
52+
53+
.PHONY: fmt
54+
fmt: #HELP Run go fmt against code.
55+
go fmt ./...
56+
57+
.PHONY: vet
58+
vet: #HELP Run go vet against code.
59+
go vet ./...
60+
61+
.PHONY: lint
62+
lint: #HELP Run golangci linter.
63+
@echo "Linting not configured for tests-extension"
64+
65+
.PHONY: fix-lint
66+
fix-lint: #HELP Fix lint issues
67+
@echo "Linting not configured for tests-extension"
68+
69+
# GO_COMPLIANCE_POLICY="exempt_all" must only be used for test related binaries.
70+
# It prevents various FIPS compliance policies from being applied to this compilation.
71+
# Do not set globally.
72+
.PHONY: build
73+
build: #HELP Build the extended tests binary
74+
@mkdir -p $(TOOLS_BIN_DIR)
75+
GO_COMPLIANCE_POLICY="exempt_all" go build -ldflags "$(LDFLAGS)" -o $(TOOLS_BIN_DIR)/openshift-apiserver-tests-ext ./cmd/...
76+
77+
.PHONY: update-metadata
78+
update-metadata: build #HELP Build and run 'update-metadata' to generate test metadata
79+
$(TOOLS_BIN_DIR)/openshift-apiserver-tests-ext update --component openshift:payload:openshift-apiserver
80+
$(MAKE) clean-metadata
81+
82+
83+
# Ensure TestID is unique over time.
84+
# TestID is built over Product:Type:ComponentName:TestDescription
85+
# (i.e. openshift:payload:openshift-apiserver:TestName)
86+
# Details:
87+
# - https://github.com/openshift/enhancements/blob/master/enhancements/testing/openshift-tests-extension.md#test-id
88+
# - https://github.com/openshift-eng/ci-test-mapping
89+
#──────────────────────────────────────────────────────────────
90+
# How to rename a test?
91+
# 1. Run: make list-test-names
92+
# 2. Find the current full test name (e.g. "[sig-abc] My test does XYZ")
93+
# 3. Add a Ginkgo label: ginkgo.Label("original-name:[sig-abc] My test does XYZ"). if there is existing original-name label, please do not update the label again and keep it unchanged.
94+
# 4. Change the test name string and run: make build-update
95+
# **Example**
96+
# It("should pass a renamed sanity check",
97+
# Label("original-name:[sig-openshift-apiserver] OLMv1 should pass a trivial sanity check"),
98+
# func(ctx context.Context) {
99+
# Expect(len("test")).To(BeNumerically(">", 0))
100+
# })
101+
# Note: You only add the label once. Do not update it after future renames.
102+
#──────────────────────────────────────────────────────────────
103+
# How to delete a test?
104+
# 1. Run: make list-test-names
105+
# 2. In main.go add:
106+
# ext.IgnoreObsoleteTests(
107+
# "[sig-openshift-apiserver] My removed test name",
108+
# )
109+
# 3. Delete the test code in your suite file (e.g. openshift_apiserver.go)
110+
# 4. Run: make build-update.
111+
# This will regenerate the metadata without the test entry.
112+
#────────────────────────────────────────────────────────────────────
113+
.PHONY: build-update
114+
build-update: build update-metadata #HELP Build and update metadata and sanitize output
115+
116+
.PHONY: clean
117+
clean: #HELP Remove build artifacts
118+
rm -rf $(TOOLS_BIN_DIR)
119+
120+
#SECTION Metadata
121+
122+
.PHONY: list-test-names
123+
list-test-names: build #HELP Show current full test names
124+
@$(TOOLS_BIN_DIR)/openshift-apiserver-tests-ext list -o names
125+
126+
# Remove 'codeLocations' to avoid absolute paths like:
127+
# "/Users/$(USER)/go/src/.../openshift_apiserver.go:12"
128+
# These are machine-specific and make the metadata non-idempotent.
129+
# More info: https://issues.redhat.com/browse/TRT-2186
130+
.PHONY: clean-metadata
131+
clean-metadata: #HELP Remove 'codeLocations' from metadata JSON
132+
@echo "Cleaning metadata (removing codeLocations)..."
133+
@jq 'map(del(.codeLocations))' $(METADATA) > $(METADATA).tmp && mv $(METADATA).tmp $(METADATA)
134+
135+
.PHONY: verify-metadata #HELP To verify that the metadata was properly updated
136+
verify-metadata: update-metadata
137+
@if ! git diff --exit-code $(METADATA); then \
138+
echo "ERROR: Metadata is out of date. Please run 'make build-update' and commit the result."; \
139+
exit 1; \
140+
fi

test/extended/README.md renamed to test/tests-extension/README.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ They use the framework: https://github.com/openshift-eng/openshift-tests-extensi
99

1010
| Command | Description |
1111
|----------------------------------------------------------------------------|--------------------------------------------------------------------------|
12-
| `make tests-ext-build` | Builds the test extension binary. |
13-
| `./openshift-apiserver-tests-ext list` | Lists all available test cases. |
14-
| `./openshift-apiserver-tests-ext run-suite <suite-name>` | Runs a test suite. e.g., `openshift/openshift-apiserver/conformance/parallel` |
15-
| `./openshift-apiserver-tests-ext run <test-name>` | Runs one specific test. |
12+
| `make build` | Builds the test extension binary. |
13+
| `./bin/openshift-apiserver-tests-ext list` | Lists all available test cases. |
14+
| `make run-suite SUITE=openshift/openshift-apiserver/all` | Runs a test suite. e.g., `openshift/openshift-apiserver/conformance/parallel` |
15+
| `./bin/openshift-apiserver-tests-ext run <test-name>` | Runs one specific test. |
1616

1717

1818
## How to Run the Tests Locally
@@ -22,7 +22,7 @@ Use the environment variable `KUBECONFIG` to point to your cluster configuration
2222

2323
```shell
2424
export KUBECONFIG=path/to/kubeconfig
25-
./openshift-apiserver-tests-ext run <test-name>
25+
make run-suite SUITE=openshift/openshift-apiserver/all
2626
```
2727

2828
### Local Test using OCP
@@ -48,25 +48,25 @@ export KUBECONFIG=~/.kube/cluster-bot.kubeconfig
4848

4949
**Example:**
5050
```shell
51-
./openshift-apiserver-tests-ext run-suite openshift/openshift-apiserver/all
51+
make run-suite SUITE=openshift/openshift-apiserver/all
5252
```
5353

5454
## Writing Tests
5555

56-
You can write tests in the `test/extended/` directory.
56+
You can write tests in the `test/` directory.
5757

5858
## Development Workflow
5959

60-
- Add or update tests in: `test/extended/`
61-
- Run `make build` to build the operator binary and `make tests-ext-build` for the test binary.
60+
- Add or update tests in: `test/`
61+
- Run `make build` to build the test binary.
6262
- You can run the full suite or one test using the commands in the table above.
6363
- Before committing your changes:
64-
- Run `make tests-ext-update`
64+
- Run `make build-update`
6565
- Run `make verify` to check formatting, linting, and validation
6666

6767
## How to Rename a Test
6868

69-
1. Run `./openshift-apiserver-tests-ext list` to see the current test names
69+
1. Run `make list-test-names` to see the current test names
7070
2. Find the name of the test you want to rename
7171
3. Add a Ginkgo label with the original name, like this:
7272

@@ -78,14 +78,14 @@ It("should pass a renamed sanity check",
7878
})
7979
```
8080

81-
4. Run `make tests-ext-update` to update the metadata
81+
4. Run `make build-update` to update the metadata
8282

8383
**Note:** Only add the label once. Do not update it again after future renames.
8484

8585
## How to Delete a Test
8686

87-
1. Run `./openshift-apiserver-tests-ext list` to find the test name
88-
2. Add the test name to the `IgnoreObsoleteTests` block in `cmd/openshift-apiserver-tests-ext/main.go`, like this:
87+
1. Run `make list-test-names` to find the test name
88+
2. Add the test name to the `IgnoreObsoleteTests` block in `cmd/main.go`, like this:
8989

9090
```go
9191
ext.IgnoreObsoleteTests(
@@ -94,7 +94,7 @@ ext.IgnoreObsoleteTests(
9494
```
9595

9696
3. Delete the test code from your suite.
97-
4. Run `make tests-ext-update` to clean the metadata
97+
4. Run `make build-update` to clean the metadata
9898

9999
**WARNING**: Deleting a test may cause issues with Sippy https://sippy.dptools.openshift.org/sippy-ng/
100100
or other tools that expected the Unique TestID tracked outside of this repository. [More info](https://github.com/openshift-eng/ci-test-mapping)
@@ -135,10 +135,12 @@ More info: https://docs.ci.openshift.org/docs/architecture/ci-operator/#testing-
135135

136136
| Target | Description |
137137
|--------------------------|------------------------------------------------------------------------------|
138-
| `make build` | Builds the operator binary. |
139-
| `make tests-ext-build` | Builds the test extension binary. |
140-
| `make tests-ext-update` | Updates the metadata JSON file and cleans machine-specific codeLocations. |
138+
| `make build` | Builds the test extension binary. |
139+
| `make run-suite` | Runs tests by suite name and generates JUnit report. |
140+
| `make build-update` | Builds and updates metadata and sanitizes output. |
141141
| `make verify` | Runs formatting, vet, and linter. |
142+
| `make list-test-names` | Shows current full test names. |
143+
| `make clean` | Removes build artifacts. |
142144

143145
**Note:** Metadata is stored in: `.openshift-tests-extension/openshift_payload_openshift-apiserver.json`
144146

@@ -163,9 +165,9 @@ rely on these tests to validate that their solutions are compatible and conforma
163165
It is generally preferred to include tests in the same image as the component
164166
being tested whenever possible.
165167

166-
### Why do we need to run `make tests-ext-update`?
168+
### Why do we need to run `make build-update`?
167169

168-
Running `make tests-ext-update` ensures that each test gets a unique and stable **TestID** over time.
170+
Running `make build-update` ensures that each test gets a unique and stable **TestID** over time.
169171

170172
The TestID is used to identify tests across the OpenShift CI/CD pipeline and reporting tools like Sippy.
171173
It helps track test results, detect regressions, and ensures the correct tests are

0 commit comments

Comments
 (0)