|
| 1 | +/* |
| 2 | +This command is used to run the Cluster OpenShift API Server Operator tests extension for OpenShift. |
| 3 | +It registers the Cluster OpenShift API Server Operator tests with the OpenShift Tests Extension framework |
| 4 | +and provides a command-line interface to execute them. |
| 5 | +For further information, please refer to the documentation at: |
| 6 | +https://github.com/openshift-eng/openshift-tests-extension/blob/main/cmd/example-tests/main.go |
| 7 | +*/ |
| 8 | +package main |
| 9 | + |
| 10 | +import ( |
| 11 | + "fmt" |
| 12 | + "os" |
| 13 | + "strings" |
| 14 | + |
| 15 | + "github.com/openshift-eng/openshift-tests-extension/pkg/cmd" |
| 16 | + e "github.com/openshift-eng/openshift-tests-extension/pkg/extension" |
| 17 | + et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests" |
| 18 | + g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo" |
| 19 | + |
| 20 | + "github.com/spf13/cobra" |
| 21 | + |
| 22 | + // The import below is necessary to ensure that the OAS operator tests are registered with the extension. |
| 23 | + _ "github.com/openshift/cluster-kube-apiserver-operator/test/extended" |
| 24 | +) |
| 25 | + |
| 26 | +func main() { |
| 27 | + registry := e.NewRegistry() |
| 28 | + ext := e.NewExtension("openshift", "payload", "cluster-kube-apiserve-operator") |
| 29 | + |
| 30 | + // Suite: conformance/parallel (fast, parallel-safe) |
| 31 | + ext.AddSuite(e.Suite{ |
| 32 | + Name: "openshift/cluster-kube-apiserve-operator/conformance/parallel", |
| 33 | + Parents: []string{"openshift/conformance/parallel"}, |
| 34 | + Qualifiers: []string{ |
| 35 | + `!(name.contains("[Serial]") || name.contains("[Slow]"))`, |
| 36 | + }, |
| 37 | + }) |
| 38 | + |
| 39 | + // Suite: conformance/serial (explicitly serial tests) |
| 40 | + ext.AddSuite(e.Suite{ |
| 41 | + Name: "openshift/cluster-kube-apiserve-operator/conformance/serial", |
| 42 | + Parents: []string{"openshift/conformance/serial"}, |
| 43 | + Qualifiers: []string{ |
| 44 | + `name.contains("[Serial]")`, |
| 45 | + }, |
| 46 | + }) |
| 47 | + |
| 48 | + // Suite: optional/slow (long-running tests) |
| 49 | + ext.AddSuite(e.Suite{ |
| 50 | + Name: "openshift/cluster-kube-apiserve-operator/optional/slow", |
| 51 | + Parents: []string{"openshift/optional/slow"}, |
| 52 | + Qualifiers: []string{ |
| 53 | + `name.contains("[Slow]")`, |
| 54 | + }, |
| 55 | + }) |
| 56 | + |
| 57 | + // Suite: all (includes everything) |
| 58 | + ext.AddSuite(e.Suite{ |
| 59 | + Name: "openshift/cluster-kube-apiserve-operator/all", |
| 60 | + }) |
| 61 | + |
| 62 | + specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite() |
| 63 | + if err != nil { |
| 64 | + panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error())) |
| 65 | + } |
| 66 | + |
| 67 | + // Ensure [Disruptive] tests are also [Serial] |
| 68 | + specs = specs.Walk(func(spec *et.ExtensionTestSpec) { |
| 69 | + if strings.Contains(spec.Name, "[Disruptive]") && !strings.Contains(spec.Name, "[Serial]") { |
| 70 | + spec.Name = strings.ReplaceAll( |
| 71 | + spec.Name, |
| 72 | + "[Disruptive]", |
| 73 | + "[Serial][Disruptive]", |
| 74 | + ) |
| 75 | + } |
| 76 | + }) |
| 77 | + |
| 78 | + // Preserve original-name labels for renamed tests |
| 79 | + specs = specs.Walk(func(spec *et.ExtensionTestSpec) { |
| 80 | + for label := range spec.Labels { |
| 81 | + if strings.HasPrefix(label, "original-name:") { |
| 82 | + parts := strings.SplitN(label, "original-name:", 2) |
| 83 | + if len(parts) > 1 { |
| 84 | + spec.OriginalName = parts[1] |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + }) |
| 89 | + |
| 90 | + // Ignore obsolete tests |
| 91 | + ext.IgnoreObsoleteTests( |
| 92 | + // "[sig-openshift-apiserver] <test name here>", |
| 93 | + ) |
| 94 | + |
| 95 | + // Initialize environment before running any tests |
| 96 | + specs.AddBeforeAll(func() { |
| 97 | + // do stuff |
| 98 | + }) |
| 99 | + |
| 100 | + ext.AddSpecs(specs) |
| 101 | + registry.Register(ext) |
| 102 | + |
| 103 | + root := &cobra.Command{ |
| 104 | + Long: "Cluster OpenShift API Server Operator Tests Extension", |
| 105 | + } |
| 106 | + |
| 107 | + root.AddCommand(cmd.DefaultExtensionCommands(registry)...) |
| 108 | + |
| 109 | + if err := root.Execute(); err != nil { |
| 110 | + os.Exit(1) |
| 111 | + } |
| 112 | +} |
0 commit comments