Skip to content

Commit 0052374

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

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-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: 64 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,64 @@ 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+
# A TestID is a unique and stable identity for a test.
81+
# It is made up of: Component (Product:Type:ComponentName:TestDescription)
82+
# It is required to ensure unique TestID over time.
83+
# More info:
84+
# - https://github.com/openshift/enhancements/blob/master/enhancements/testing/openshift-tests-extension.md#test-id
85+
# - https://github.com/openshift-eng/ci-test-mapping
86+
#──────────────────────────────────────────────────────────────
87+
# How to rename a test?
88+
# 1. Run: make list-test-names
89+
# 2. Find the current full test name (e.g. "[sig-abc] My test does XYZ")
90+
# 3. Add a Ginkgo label: ginkgo.Label("original-name:[sig-abc] My test does XYZ")
91+
# 4. Change the test name string and run: make build-update
92+
# **Example**
93+
# It("should pass a renamed sanity check",
94+
# Label("original-name:[sig-olmv1] OLMv1 should pass a trivial sanity check"),
95+
# func(ctx context.Context) {
96+
# Expect(len("test")).To(BeNumerically(">", 0))
97+
# })
98+
# Note: You only add the label once. Do not update it after future renames.
99+
#──────────────────────────────────────────────────────────────
100+
# How to delete a test?
101+
# 1. Run: make list-test-names
102+
# 2. In main.go add:
103+
# ext.IgnoreObsoleteTests(
104+
# "[sig-olmv1] My removed test name",
105+
# )
106+
# 3. Delete the test code in your suite file (e.g. olmv1.go)
107+
# 4. Run: make build-update.
108+
# This will regenerate the metadata without the test entry.
109+
#────────────────────────────────────────────────────────────────────
110+
.PHONY: build-update
111+
build-update: build update-metadata #HELP Build and update metadata and sanitize output
112+
113+
#SECTION Metadata
114+
115+
.PHONY: list-test-names
116+
list-test-names: #HELP Show current full test names (use to capture for original-name label)
117+
@$(TOOLS_BIN_DIR)/olmv1-tests-ext list -o names
118+
119+
# Remove 'codeLocations' to avoid absolute paths like:
120+
# "/Users/$(USER)/go/src/.../olmv1.go:12"
121+
# These are machine-specific and make the metadata non-idempotent.
122+
# More info: https://issues.redhat.com/browse/TRT-2186
123+
.PHONY: clean-metadata
124+
clean-metadata: #HELP Remove 'codeLocations' from metadata JSON
125+
@echo "Cleaning metadata (removing codeLocations)..."
126+
@jq 'map(del(.codeLocations))' $(METADATA) > $(METADATA).tmp && mv $(METADATA).tmp $(METADATA)
127+
128+
.PHONY: verify-metadata #HELP To verify that the metadata was properly update
129+
verify-metadata: update-metadata
130+
@if ! git diff --exit-code $(METADATA); then \
131+
echo "ERROR: Metadata is out of date. Please run 'make build-update' and commit the result."; \
132+
exit 1; \
133+
fi

openshift/tests-extension/cmd/main.go

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

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

0 commit comments

Comments
 (0)