Skip to content

Commit 2d5a2ca

Browse files
committed
Dirty draft for extension tests
1 parent 657b65f commit 2d5a2ca

File tree

4 files changed

+1064
-295
lines changed

4 files changed

+1064
-295
lines changed

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

0 commit comments

Comments
 (0)