diff --git a/openshift/tests-extension/.openshift-tests-extension/openshift_payload_olmv1.json b/openshift/tests-extension/.openshift-tests-extension/openshift_payload_olmv1.json new file mode 100644 index 000000000..4b7fc6ce5 --- /dev/null +++ b/openshift/tests-extension/.openshift-tests-extension/openshift_payload_olmv1.json @@ -0,0 +1,12 @@ +[ + { + "name": "[sig-olmv1] OLMv1 should pass a trivial sanity check", + "labels": {}, + "resources": { + "isolation": {} + }, + "source": "openshift:payload:olmv1", + "lifecycle": "blocking", + "environmentSelector": {} + } +] diff --git a/openshift/tests-extension/Makefile b/openshift/tests-extension/Makefile index b7df73583..54e9083c2 100644 --- a/openshift/tests-extension/Makefile +++ b/openshift/tests-extension/Makefile @@ -15,6 +15,9 @@ LDFLAGS := -X '$(GO_PKG_NAME)/pkg/version.CommitFromGit=$(GIT_COMMIT)' \ -X '$(GO_PKG_NAME)/pkg/version.BuildDate=$(BUILD_DATE)' \ -X '$(GO_PKG_NAME)/pkg/version.GitTreeState=$(GIT_TREE_STATE)' + +METADATA := $(shell pwd)/.openshift-tests-extension/openshift_payload_olmv1.json + #SECTION General # The help target prints out all targets with their descriptions organized @@ -67,3 +70,64 @@ fix-lint: $(GOLANGCI_LINT) #HELP Fix lint issues build: #HELP Build the extended tests binary @mkdir -p $(TOOLS_BIN_DIR) GO_COMPLIANCE_POLICY="exempt_all" go build -ldflags "$(LDFLAGS)" -mod=vendor -o $(TOOLS_BIN_DIR)/olmv1-tests-ext ./cmd/... + +.PHONY: update-metadata +update-metadata: #HELP Build and run 'update-metadata' to generate test metadata + $(TOOLS_BIN_DIR)/olmv1-tests-ext update --component openshift:payload:olmv1 + $(MAKE) clean-metadata + + +# A TestID is a unique and stable identity for a test. +# It is made up of: Component (Product:Type:ComponentName:TestDescription) +# It is required to ensure unique TestID over time. +# More info: +# - https://github.com/openshift/enhancements/blob/master/enhancements/testing/openshift-tests-extension.md#test-id +# - https://github.com/openshift-eng/ci-test-mapping +#────────────────────────────────────────────────────────────── +# How to rename a test? +# 1. Run: make list-test-names +# 2. Find the current full test name (e.g. "[sig-abc] My test does XYZ") +# 3. Add a Ginkgo label: ginkgo.Label("original-name:[sig-abc] My test does XYZ") +# 4. Change the test name string and run: make build-update +# **Example** +# It("should pass a renamed sanity check", +# Label("original-name:[sig-olmv1] OLMv1 should pass a trivial sanity check"), +# func(ctx context.Context) { +# Expect(len("test")).To(BeNumerically(">", 0)) +# }) +# Note: You only add the label once. Do not update it after future renames. +#────────────────────────────────────────────────────────────── +# How to delete a test? +# 1. Run: make list-test-names +# 2. In main.go add: +# ext.IgnoreObsoleteTests( +# "[sig-olmv1] My removed test name", +# ) +# 3. Delete the test code in your suite file (e.g. olmv1.go) +# 4. Run: make build-update. +# This will regenerate the metadata without the test entry. +#──────────────────────────────────────────────────────────────────── +.PHONY: build-update +build-update: build update-metadata #HELP Build and update metadata and sanitize output + +#SECTION Metadata + +.PHONY: list-test-names +list-test-names: #HELP Show current full test names (use to capture for original-name label) + @$(TOOLS_BIN_DIR)/olmv1-tests-ext list -o names + +# Remove 'codeLocations' to avoid absolute paths like: +# "/Users/$(USER)/go/src/.../olmv1.go:12" +# These are machine-specific and make the metadata non-idempotent. +# More info: https://issues.redhat.com/browse/TRT-2186 +.PHONY: clean-metadata +clean-metadata: #HELP Remove 'codeLocations' from metadata JSON + @echo "Cleaning metadata (removing codeLocations)..." + @jq 'map(del(.codeLocations))' $(METADATA) > $(METADATA).tmp && mv $(METADATA).tmp $(METADATA) + +.PHONY: verify-metadata #HELP To verify that the metadata was properly update +verify-metadata: update-metadata + @if ! git diff --exit-code $(METADATA); then \ + echo "ERROR: Metadata is out of date. Please run 'make build-update' and commit the result."; \ + exit 1; \ + fi diff --git a/openshift/tests-extension/cmd/main.go b/openshift/tests-extension/cmd/main.go index bda687a76..082ac7de0 100644 --- a/openshift/tests-extension/cmd/main.go +++ b/openshift/tests-extension/cmd/main.go @@ -105,6 +105,38 @@ func main() { } }) + // To handle renames and preserve test ID by setting the original-name. + // This logic looks for a custom Ginkgo label in the format: + // Label("original-name:") + // When found, it sets spec.OriginalName = . + // **Example** + // It("should pass a renamed sanity check", + // Label("original-name:[sig-olmv1] OLMv1 should pass a trivial sanity check"), + // func(ctx context.Context) { + // Expect(len("test")).To(BeNumerically(">", 0)) + // }) + specs = specs.Walk(func(spec *et.ExtensionTestSpec) { + for label := range spec.Labels { + if strings.HasPrefix(label, "original-name:") { + parts := strings.SplitN(label, "original-name:", 2) + if len(parts) > 1 { + spec.OriginalName = parts[1] + } + } + } + }) + + // To delete tests you must mark them as obsolete. + // These tests will be excluded from metadata validation during OTE update. + // 1 - To get the full name of the test you want to remove run: make list-test-names + // 2 - Add the test name here to avoid validation errors + // 3 - Remove the test in your test file. + // 4 - Run make build-update + ext.IgnoreObsoleteTests( + // "[sig-olmv1] OLMv1 should pass a trivial sanity check", + // Add more removed test names below + ) + // TODO: Init test framework for cluster-aware cases // -------------------------------------------------- // The external binary doesn't currently init the test framework (e.g., kubeconfig, REST client).