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
@@ -1 +1,5 @@
/openshift-router

# OTE (OpenShift Tests Extension) generated files
tests-extension/bin/
tests-extension/test/testdata/bindata.go
26 changes: 26 additions & 0 deletions tests-extension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Include bindata targets
include bindata.mk

# Binary name and output directory
BINARY := bin/router-tests-ext

# Build extension binary
.PHONY: build
build: bindata
@echo "Building extension binary..."
@mkdir -p bin
go build -o $(BINARY) ./cmd
@echo "Binary built successfully at $(BINARY)"

# Clean generated files
.PHONY: clean
clean:
@echo "Cleaning binaries..."
@rm -f $(BINARY)

.PHONY: help
help:
@echo "Available targets:"
@echo " bindata - Generate bindata.go from test/testdata"
@echo " build - Build extension binary (includes bindata)"
@echo " clean - Remove extension binary"
29 changes: 29 additions & 0 deletions tests-extension/bindata.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Bindata generation for testdata files

# Testdata path
TESTDATA_PATH := test/testdata

# go-bindata tool path
GOPATH ?= $(shell go env GOPATH)
GO_BINDATA := $(GOPATH)/bin/go-bindata

# Install go-bindata if not present
$(GO_BINDATA):
@echo "Installing go-bindata to $(GO_BINDATA)..."
@go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
@echo "go-bindata installed successfully"

# Generate bindata.go from testdata directory
.PHONY: bindata
bindata: clean-bindata $(GO_BINDATA)
@echo "Generating bindata from $(TESTDATA_PATH)..."
@mkdir -p $(TESTDATA_PATH)
$(GO_BINDATA) -nocompress -nometadata \
-pkg testdata -o $(TESTDATA_PATH)/bindata.go -prefix "test" $(TESTDATA_PATH)/...
@gofmt -s -w $(TESTDATA_PATH)/bindata.go
@echo "Bindata generated successfully at $(TESTDATA_PATH)/bindata.go"

.PHONY: clean-bindata
clean-bindata:
@echo "Cleaning bindata..."
@rm -f $(TESTDATA_PATH)/bindata.go
95 changes: 95 additions & 0 deletions tests-extension/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

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
_ "github.com/openshift/router-tests-extension/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", "router")

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

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

// 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: "Router Tests",
}

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

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