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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
.idea/
coverage.out
/cloud-credential-tests-ext

/cloud-credential-operator-tests-ext
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,31 @@ update-go-modules-k8s:
done
go mod tidy
go mod vendor

# OTE binary configuration
TESTS_EXT_DIR := ./cmd/extension
TESTS_EXT_BINARY := bin/cco-tests-ext

# Build OTE extension binary
.PHONY: tests-ext-build
tests-ext-build:
@echo "Building OTE test extension binary..."
@cd test && $(MAKE) -f bindata.mk bindata
@mkdir -p bin
GOTOOLCHAIN=auto GOSUMDB=sum.golang.org go build -mod=mod -o $(TESTS_EXT_BINARY) $(TESTS_EXT_DIR)
@echo "OTE binary built successfully at $(TESTS_EXT_BINARY)"

# Alias for backward compatibility
.PHONY: extension
extension: tests-ext-build

# List all tests
.PHONY: list-tests
list-tests: tests-ext-build
$(TESTS_EXT_DIR)/$(TESTS_EXT_BINARY) list

# Clean extension binary
.PHONY: clean-extension
clean-extension:
rm -f $(TESTS_EXT_DIR)/$(TESTS_EXT_BINARY)
@cd test && $(MAKE) clean-bindata
104 changes: 104 additions & 0 deletions cmd/extension/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package main
Copy link
Contributor

Choose a reason for hiding this comment

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

The OTE test framework has already been added to CCO, so this addition may be redundant.
Perhaps the prompt could be adjusted here to check whether the OTE test framework already exists and whether any update is needed.


import (
"context"
"fmt"
"os"
"regexp"
"strings"

"github.com/spf13/cobra"

"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"

// Import test framework packages for initialization
"github.com/openshift/origin/test/extended/util"
"k8s.io/kubernetes/test/e2e/framework"

// Import test packages from test module
_ "github.com/openshift/cloud-credential-operator/test/e2e"
)

func main() {
// Initialize test framework
// This sets TestContext.KubeConfig from KUBECONFIG env var and initializes the cloud provider
util.InitStandardFlags()
if err := util.InitTest(false); err != nil {
panic(fmt.Sprintf("couldn't initialize test framework: %+v", err.Error()))
}
framework.AfterReadingAllFlags(&framework.TestContext)

registry := e.NewRegistry()
ext := e.NewExtension("openshift", "payload", "cco")

// Add main test suite
ext.AddSuite(e.Suite{
Name: "openshift/cloud-credential-operator/tests",
Parents: []string{"openshift/conformance/parallel"},
})

// Build test specs from Ginkgo
allSpecs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
if err != nil {
panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error()))
}

// Filter to only include CCO-specific tests (tests with [sig-cco] in name)
var filteredSpecs []*et.ExtensionTestSpec
allSpecs.Walk(func(spec *et.ExtensionTestSpec) {
if strings.Contains(spec.Name, "[sig-cco]") {
filteredSpecs = append(filteredSpecs, spec)
}
})
specs := et.ExtensionTestSpecs(filteredSpecs)

// Apply platform filters based on Platform: labels
specs.Walk(func(spec *et.ExtensionTestSpec) {
for label := range spec.Labels {
if strings.HasPrefix(label, "Platform:") {
platformName := strings.TrimPrefix(label, "Platform:")
spec.Include(et.PlatformEquals(platformName))
}
}
})

// Apply platform filters based on [platform:xxx] in test names
specs.Walk(func(spec *et.ExtensionTestSpec) {
re := regexp.MustCompile(`\[platform:([a-z]+)\]`)
if match := re.FindStringSubmatch(spec.Name); match != nil {
platform := match[1]
spec.Include(et.PlatformEquals(platform))
}
})

// Wrap test execution with cleanup handler
// This marks tests as started and ensures proper cleanup
specs.Walk(func(spec *et.ExtensionTestSpec) {
originalRun := spec.Run
spec.Run = func(ctx context.Context) *et.ExtensionTestResult {
var result *et.ExtensionTestResult
util.WithCleanup(func() {
result = originalRun(ctx)
})
return result
}
})

ext.AddSpecs(specs)
registry.Register(ext)

root := &cobra.Command{
Long: "Cloud Credential Operator Tests",
}

root.AddCommand(cmd.DefaultExtensionCommands(registry)...)

if err := func() error {
return root.Execute()
}(); err != nil {
os.Exit(1)
}
}
Loading