Skip to content

Commit 53aaf20

Browse files
UPSTREAM: <carry>: [OTE] - Add tracking mechanism
1 parent 7f00e53 commit 53aaf20

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"name": "[sig-olmv1] OLMv1 should pass a trivial sanity check",
4+
"labels": {},
5+
"resources": {
6+
"isolation": {}
7+
},
8+
"source": "openshift:payload:olmv1",
9+
"lifecycle": "blocking",
10+
"environmentSelector": {}
11+
}
12+
]

openshift/tests-extension/Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ LDFLAGS := -X '$(GO_PKG_NAME)/pkg/version.CommitFromGit=$(GIT_COMMIT)' \
1515
-X '$(GO_PKG_NAME)/pkg/version.BuildDate=$(BUILD_DATE)' \
1616
-X '$(GO_PKG_NAME)/pkg/version.GitTreeState=$(GIT_TREE_STATE)'
1717

18+
19+
METADATA := $(shell pwd)/.openshift-tests-extension/openshift_payload_olmv1.json
20+
1821
#SECTION General
1922

2023
# The help target prints out all targets with their descriptions organized
@@ -67,3 +70,74 @@ fix-lint: $(GOLANGCI_LINT) #HELP Fix lint issues
6770
build: #HELP Build the extended tests binary
6871
@mkdir -p $(TOOLS_BIN_DIR)
6972
GO_COMPLIANCE_POLICY="exempt_all" go build -ldflags "$(LDFLAGS)" -mod=vendor -o $(TOOLS_BIN_DIR)/olmv1-tests-ext ./cmd/...
73+
74+
.PHONY: update-metadata
75+
update-metadata: #HELP Build and run 'update-metadata' to generate test metadata
76+
$(TOOLS_BIN_DIR)/olmv1-tests-ext update --component openshift:payload:olmv1
77+
$(MAKE) clean-metadata
78+
79+
#────────────────────────────────────────────────────────────────────
80+
# OpenShift Extended TestID Policy: Stability & Traceability
81+
#────────────────────────────────────────────────────────────────────
82+
# A TestID is a unique and stable identity for a test.
83+
# It is made up of: Component (Product:Type:ComponentName:TestDescription)
84+
# Reference: https://github.com/openshift/enhancements/blob/master/enhancements/testing/openshift-tests-extension.md#test-id
85+
#
86+
# What Happens If You Rename or Delete Tests Without Tracking:
87+
# - Component readiness will show unknown or missing tests
88+
# - ci-test-mapping will not match old and new test names
89+
# - TRT must manually fix test records
90+
# More info: https://github.com/openshift-eng/ci-test-mapping/blob/main/README.md#renaming-tests
91+
#
92+
#──────────────────────────────────────────────────────────────
93+
# If You Need to Rename a Test:
94+
#──────────────────────────────────────────────────────────────
95+
# 1. Run: make list-test-names
96+
# 2. Find the current full test name (e.g. "[sig-abc] My test does XYZ")
97+
# 3. Add a Ginkgo label: ginkgo.Label("original-name:[sig-abc] My test does XYZ")
98+
# 4. Change the test name string and run: make build-update
99+
# **Example**
100+
# It("should pass a renamed sanity check",
101+
# Label("original-name:[sig-olmv1] OLMv1 should pass a trivial sanity check"),
102+
# func(ctx context.Context) {
103+
# Expect(len("test")).To(BeNumerically(">", 0))
104+
# })
105+
# Note: You only add the label once. Do not update it after future renames.
106+
#
107+
#──────────────────────────────────────────────────────────────
108+
# If You Want to Delete a Test:
109+
#──────────────────────────────────────────────────────────────
110+
# 1. Run: make list-test-names
111+
# 2. In main.go add:
112+
# ext.IgnoreObsoleteTests(
113+
# "[sig-olmv1] My removed test name",
114+
# )
115+
# 3. Delete the test code in your suite file (e.g. olmv1.go)
116+
# 4. Run: make build-update
117+
# This will regenerate the metadata without the test entry.
118+
#────────────────────────────────────────────────────────────────────
119+
.PHONY: build-update
120+
build-update: build update-metadata #HELP Build and update metadata and sanitize output
121+
122+
#SECTION Metadata
123+
124+
.PHONY: list-test-names
125+
list-test-names: #HELP Show current full test names (use to capture for original-name label)
126+
@$(TOOLS_BIN_DIR)/olmv1-tests-ext list -o names
127+
128+
# Remove 'codeLocations' to avoid absolute paths like:
129+
# "/Users/$(USER)/go/src/.../olmv1.go:12"
130+
# These are machine-specific and make the metadata non-idempotent.
131+
# This prevents proper diffs, validation, and committing metadata across environments.
132+
# More info: https://issues.redhat.com/browse/TRT-2186
133+
.PHONY: clean-metadata
134+
clean-metadata: #HELP Remove 'codeLocations' from metadata JSON
135+
@echo "Cleaning metadata (removing codeLocations)..."
136+
@jq 'map(del(.codeLocations))' $(METADATA) > $(METADATA).tmp && mv $(METADATA).tmp $(METADATA)
137+
138+
.PHONY: verify-metadata #HELP To verify that the metadata was properly update
139+
verify-metadata: update-metadata
140+
@if ! git diff --exit-code $(METADATA); then \
141+
echo "ERROR: Metadata is out of date. Please run 'make build-update' and commit the result."; \
142+
exit 1; \
143+
fi

openshift/tests-extension/cmd/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,39 @@ func main() {
105105
}
106106
})
107107

108+
// Preserve test ID traceability by setting the original-name field.
109+
// This logic looks for a custom Ginkgo label in the format:
110+
// Label("original-name:<full old test name>")
111+
// When found, it sets spec.OriginalName = <old name>.
112+
//
113+
// **Example**
114+
// It("should pass a renamed sanity check",
115+
// Label("original-name:[sig-olmv1] OLMv1 should pass a trivial sanity check"),
116+
// func(ctx context.Context) {
117+
// Expect(len("test")).To(BeNumerically(">", 0))
118+
// })
119+
specs = specs.Walk(func(spec *et.ExtensionTestSpec) {
120+
for label := range spec.Labels {
121+
if strings.HasPrefix(label, "original-name:") {
122+
parts := strings.SplitN(label, "original-name:", 2)
123+
if len(parts) > 1 {
124+
spec.OriginalName = parts[1]
125+
}
126+
}
127+
}
128+
})
129+
130+
// To delete tests you must mark them as obsolete.
131+
// These tests will be excluded from metadata validation during update.
132+
// 1 - To get the full name of the test you want to remove run: make list-test-names
133+
// 2 - Add the test name here to avoid validation errors
134+
// 3 - Remove the test in your test file.
135+
// 4 - Run make build-update
136+
ext.IgnoreObsoleteTests(
137+
// "[sig-olmv1] OLMv1 should pass a trivial sanity check",
138+
// Add more removed test names below
139+
)
140+
108141
// TODO: Init test framework for cluster-aware cases
109142
// --------------------------------------------------
110143
// The external binary doesn't currently init the test framework (e.g., kubeconfig, REST client).

0 commit comments

Comments
 (0)