Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b9cc29e

Browse files
committedMar 26, 2025·
Dirty draft for extension tests
1 parent 657b65f commit b9cc29e

File tree

4 files changed

+1062
-295
lines changed

4 files changed

+1062
-295
lines changed
 

Diff for: ‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
MCO_COMPONENTS = daemon controller server operator
2-
EXTRA_COMPONENTS = apiserver-watcher machine-os-builder
2+
EXTRA_COMPONENTS = apiserver-watcher machine-os-builder machine-config-operator-ext-test
33
ALL_COMPONENTS = $(patsubst %,machine-config-%,$(MCO_COMPONENTS)) $(EXTRA_COMPONENTS)
44
PREFIX ?= /usr
55
GO111MODULE?=on

Diff for: ‎cmd/machine-config-operator-ext-test/main.go

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
//et "github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
8+
"github.com/spf13/cobra"
9+
10+
e2e "k8s.io/kubernetes/test/e2e/framework"
11+
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
12+
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
13+
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
14+
exutil "github.com/openshift/openshift-tests-private/test/extended/util"
15+
16+
// If using ginkgo, import your tests here
17+
//_ "github.com/openshift-eng/openshift-tests-extension/test/example"
18+
_ "github.com/openshift/openshift-tests-private/test/extended/mco"
19+
)
20+
21+
func main() {
22+
// Extension registry
23+
registry := e.NewRegistry()
24+
exutil.InitStandardFlags()
25+
e2e.AfterReadingAllFlags(exutil.TestContext)
26+
27+
exutil.AnnotateTestSuite()
28+
exutil.TestContext.AllowedNotReadyNodes = 100
29+
exutil.TestContext.MaxNodesToGather = 0
30+
31+
err := exutil.InitTest(false)
32+
if err != nil {
33+
panic(fmt.Sprintf("couldn't init tests: %+v", err.Error()))
34+
}
35+
36+
// You can declare multiple extensions, but most people will probably only need to create one.
37+
ext := e.NewExtension("openshift", "payload", "mco")
38+
39+
// Add suites to the extension. Specifying parents will cause the tests from this suite
40+
// to be included when a parent is invoked.
41+
ext.AddSuite(
42+
e.Suite{
43+
Name: "mco/tests",
44+
Parents: []string{"openshift/conformance/parallel"},
45+
})
46+
47+
// The tests that a suite is composed of can be filtered by CEL expressions. By
48+
// default, the qualifiers only apply to tests from this extension.
49+
// ext.AddSuite(e.Suite{
50+
// Name: "test/extended/mco",
51+
//// Qualifiers: []string{
52+
//// `!labels.exists(l, l=="SLOW")`,
53+
//// },
54+
// })
55+
//
56+
// Global suites' qualifiers will apply to all tests available, even
57+
// those outside of this extension (when invoked by origin).
58+
// ext.AddGlobalSuite(e.Suite{
59+
// Name: "example/slow",
60+
// Qualifiers: []string{
61+
// `labels.exists(l, l=="SLOW")`,
62+
// },
63+
// })
64+
65+
// If using Ginkgo, build test specs automatically
66+
specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
67+
if err != nil {
68+
panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error()))
69+
}
70+
71+
// Environment selector information can be added to test specs to support filtering by environment
72+
//specs.Select(et.NameContains("[sig-testing] openshift-tests-extension should support test-skips via environment flags")).
73+
// Include(et.PlatformEquals("aws"))
74+
75+
// You can add hooks to run before/after tests. There are BeforeEach, BeforeAll, AfterEach,
76+
// and AfterAll. "Each" functions must be thread safe.
77+
//
78+
// specs.AddBeforeAll(func() {
79+
// initializeTestFramework()
80+
// })
81+
//
82+
// specs.AddBeforeEach(func(spec ExtensionTestSpec) {
83+
// if spec.Name == "my test" {
84+
// // do stuff
85+
// }
86+
// })
87+
//
88+
// specs.AddAfterEach(func(res *ExtensionTestResult) {
89+
// if res.Result == ResultFailed && apiTimeoutRegexp.Matches(res.Output) {
90+
// res.AddDetails("api-timeout", collectDiagnosticInfo())
91+
// }
92+
// })
93+
94+
// You can also manually build a test specs list from other testing tooling
95+
// TODO: example
96+
97+
// Modify specs, such as adding a label to all specs
98+
// specs = specs.AddLabel("SLOW")
99+
100+
// Specs can be globally filtered...
101+
specs = specs.MustFilter([]string{`name.contains("ocb")`})
102+
103+
// Or walked...
104+
// specs = specs.Walk(func(spec *extensiontests.ExtensionTestSpec) {
105+
// if strings.Contains(e.Name, "scale up") {
106+
// e.Labels.Insert("SLOW")
107+
// }
108+
//
109+
// Specs can also be selected...
110+
// specs = specs.Select(et.NameContains("slow test")).AddLabel("SLOW")
111+
//
112+
// Or with "any" (or) matching selections
113+
// specs = specs.SelectAny(et.NameContains("slow test"), et.HasLabel("SLOW"))
114+
//
115+
// Or with "all" (and) matching selections
116+
// specs = specs.SelectAll(et.NameContains("slow test"), et.HasTagWithValue("speed", "slow"))
117+
//
118+
// Test renames
119+
// if spec.Name == "[sig-testing] openshift-tests-extension has a test with a typo" {
120+
// spec.OriginalName = `[sig-testing] openshift-tests-extension has a test with a tpyo`
121+
// }
122+
//
123+
// Filter by environment flags
124+
// if spec.Name == "[sig-testing] openshift-tests-extension should support defining the platform for tests" {
125+
// spec.Include(et.PlatformEquals("aws"))
126+
// spec.Exclude(et.And(et.NetworkEquals("ovn"), et.TopologyEquals("ha")))
127+
// }
128+
// })
129+
130+
ext.AddSpecs(specs)
131+
registry.Register(ext)
132+
133+
root := &cobra.Command{
134+
Long: "OpenShift Tests Extension Example",
135+
}
136+
137+
root.AddCommand(cmd.DefaultExtensionCommands(registry)...)
138+
139+
if err := func() error {
140+
return root.Execute()
141+
}(); err != nil {
142+
os.Exit(1)
143+
}
144+
}

Diff for: ‎go.mod

+333-53
Large diffs are not rendered by default.

Diff for: ‎go.sum

+584-241
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.