Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ telepresence.log
# Test extension binaries
/cluster-kube-apiserver-operator-tests-ext
/cluster-kube-apiserver-operator-tests-ext.gz

# Auto-generated test metadata (generated at build time)
/cmd/cluster-kube-apiserver-operator-tests-ext/adapter/standard_go_tests.go
cmd/cluster-kube-apiserver-operator-tests-ext/adapter/compiled_tests/
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,25 @@ verify-bindata-v4.1.0: verify-apirequestcounts-crd
.PHONY: verify-apirequestcounts-crd
verify-apirequestcounts-crd:
diff -Naup $(APIREQUESTCOUNT_CRD_SOURCE) $(APIREQUESTCOUNT_CRD_TARGET)

# compile test packages into standalone test binaries (following Cypress pattern)
# MUST run BEFORE generate-test-metadata (which compiles adapter with go:embed)
# Binaries are compiled to cmd/.../adapter/compiled_tests/ and embedded in the OTE binary
.PHONY: compile-test-binaries
compile-test-binaries:
@echo "Compiling test binaries for OTE extension..."
@mkdir -p cmd/cluster-kube-apiserver-operator-tests-ext/adapter/compiled_tests
@for dir in test/e2e*; do \
if [ -d "$$dir" ] && ls $$dir/*_test.go >/dev/null 2>&1; then \
binary_name=$$(basename $$dir).test; \
echo " Compiling $$dir -> compiled_tests/$$binary_name"; \
go test -c -o cmd/cluster-kube-apiserver-operator-tests-ext/adapter/compiled_tests/$$binary_name ./$$dir || echo " Warning: $$dir compilation failed"; \
fi \
done
@echo "Test binaries compiled successfully"

# generate test metadata for OTE extension (runs AFTER compile-test-binaries)
build: compile-test-binaries generate-test-metadata
.PHONY: generate-test-metadata
generate-test-metadata:
@cd cmd/cluster-kube-apiserver-operator-tests-ext/adapter && go run generate_metadata.go
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ make build

```bash
# Run a specific test suite or test
./cluster-kube-apiserver-operator-tests-ext run-suite SUITE=openshift/cluster-kube-apiserver-operator/all
./cluster-kube-apiserver-operator-tests-ext run-suite openshift/cluster-kube-apiserver-operator/all
./cluster-kube-apiserver-operator-tests-ext run-test "test-name"

# Run with JUnit output
./cluster-kube-apiserver-operator-tests-ext run-suite SUITE=openshift/cluster-kube-apiserver-operator/all JUNIT_DIR=/tmp/junit-results
./cluster-kube-apiserver-operator-tests-ext run-test TEST=openshift/cluster-kube-apiserver-operator/all/test-name JUNIT_DIR=/tmp/junit-results
./cluster-kube-apiserver-operator-tests-ext run-suite openshift/cluster-kube-apiserver-operator/all --junit-path=/tmp/junit.xml
./cluster-kube-apiserver-operator-tests-ext run-test "test-name" --junit-path=/tmp/junit.xml
```

### Listing available tests and suites
Expand All @@ -209,6 +209,9 @@ make build

# List tests in a suite
./cluster-kube-apiserver-operator-tests-ext list tests --suite=openshift/cluster-kube-apiserver-operator/all

# for concurrency
./cluster-kube-apiserver-operator-tests-ext run-suite openshift/cluster-kube-apiserver-operator/all -c 1
```

For more information about the OTE framework, see the [openshift-tests-extension documentation](https://github.com/openshift-eng/openshift-tests-extension).
Copy link
Member

@stbenjam stbenjam Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach won't work; we don't ship source code in the images in the payload, and origin only extracts the test binary anyway.

Go supports compiled tests, and I would suggest seeing if you can write an OTE adapter like we have for Ginkgo and Cypress: https://github.com/openshift-eng/openshift-tests-extension/tree/main/pkg/cypress

Or just convert the go tests to ginkgo, not wrapped

Copy link
Contributor Author

@gangwgr gangwgr Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this for test case name generation generate_metadata.go and gotest_wrapper.go is similar to cypress

Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//go:build ignore
// +build ignore

package main

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/openshift/cluster-kube-apiserver-operator/cmd/cluster-kube-apiserver-operator-tests-ext/adapter"
)

// findRepoRoot walks up directories to find go.mod
func findRepoRoot() (string, error) {
dir, err := os.Getwd()
if err != nil {
return "", err
}

for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
return dir, nil
}

parent := filepath.Dir(dir)
if parent == dir {
return "", fmt.Errorf("could not find go.mod in any parent directory")
}
dir = parent
}
}

func main() {
// Find repository root by looking for go.mod
repoRoot, err := findRepoRoot()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to find repository root: %v\n", err)
os.Exit(1)
}

// Set TEST_ROOT_DIR to repository root for discovery
os.Setenv("TEST_ROOT_DIR", repoRoot)

// Auto-discover all tests from test/e2e* directories
// Default: Serial tag, Informing lifecycle (can be overridden per-test via comments)
configs, err := adapter.AutoDiscoverAllGoTests([]string{"Serial"}, "Informing")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to discover tests: %v\n", err)
os.Exit(1)
}

if len(configs) == 0 {
fmt.Fprintf(os.Stderr, "Warning: No tests discovered\n")
}

// Generate standard_go_tests.go file in the same directory as this script
// This script is always in the adapter package directory
scriptDir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get script directory: %v\n", err)
os.Exit(1)
}

// If running with "go run", find the actual source directory
cwd, _ := os.Getwd()
if filepath.Base(scriptDir) != "adapter" {
scriptDir = cwd
}

outputPath := filepath.Join(scriptDir, "standard_go_tests.go")

var sb strings.Builder
sb.WriteString(`// Code generated by generate-test-metadata. DO NOT EDIT.
// To regenerate: make update

package adapter

import (
extensiontests "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
)

// Pre-discovered test metadata - embedded in binary at build time.
// To regenerate: developers run discovery locally and update this list.
var standardGoTestMetadata = []GoTestConfig{
`)

for _, config := range configs {
sb.WriteString(fmt.Sprintf("\t// %s\n", config.TestFile))

// Format tags array
var tagsStr string
if len(config.Tags) == 0 {
tagsStr = "[]string{}"
} else {
tagList := make([]string, len(config.Tags))
for i, tag := range config.Tags {
tagList[i] = fmt.Sprintf("%q", tag)
}
tagsStr = fmt.Sprintf("[]string{%s}", strings.Join(tagList, ", "))
}

// Build config line with all fields
sb.WriteString(fmt.Sprintf("\t{TestFile: %q, TestPattern: %q, Tags: %s",
config.TestFile, config.TestPattern, tagsStr))

if config.Timeout != "" {
sb.WriteString(fmt.Sprintf(", Timeout: %q", config.Timeout))
}

if config.Lifecycle != "" {
sb.WriteString(fmt.Sprintf(", Lifecycle: %q", config.Lifecycle))
}

sb.WriteString("},\n")
}

sb.WriteString(`}

// BuildExtensionTestSpecsFromGoTestMetadata returns ExtensionTestSpecs for standard Go tests
// This function is called by main.go to register the tests with OTE
// It uses the embedded standardGoTestMetadata and returns specs that can be filtered and executed
// Following the Cypress pattern: tests are registered as ExtensionTestSpec for OTE filtering and execution
func BuildExtensionTestSpecsFromGoTestMetadata() (extensiontests.ExtensionTestSpecs, error) {
return buildExtensionTestSpecsFromMetadata(standardGoTestMetadata), nil
}
`)

if err := os.WriteFile(outputPath, []byte(sb.String()), 0644); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write file: %v\n", err)
os.Exit(1)
}

fmt.Printf("Generated %s with %d tests\n", outputPath, len(configs))
}
Loading