Skip to content

OPRUN-3992: [OTE] Add tracking mechanism #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"name": "[sig-olmv1] OLMv1 should pass a trivial sanity check",
"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:olmv1",
"lifecycle": "blocking",
"environmentSelector": {}
}
]
64 changes: 64 additions & 0 deletions openshift/tests-extension/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
32 changes: 32 additions & 0 deletions openshift/tests-extension/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:<full old test name>")
// When found, it sets spec.OriginalName = <old name>.
// **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).
Expand Down