e2e framework: support callbacks during framework creation and before each test

This will be used as mechanism for invoking some of the code which is currently
hard-coded in the framework once that code is placed in optional packages.
This commit is contained in:
Patrick Ohly 2022-08-25 17:04:05 +02:00
parent fbb6ccc0c6
commit 37d562b454

View File

@ -61,6 +61,25 @@ const (
DefaultNamespaceDeletionTimeout = 5 * time.Minute
)
var (
// NewFrameworkExtensions lists functions that get called by
// NewFramework after constructing a new framework and after
// calling ginkgo.BeforeEach for the framework.
//
// This can be used by extensions of the core framework to modify
// settings in the framework instance or to add additional callbacks
// with gingko.BeforeEach/AfterEach/DeferCleanup.
//
// When a test runs, functions will be invoked in this order:
// - f.BeforeEach
// - all BeforeEaches in the order in which they were defined (first-in-first-out)
// - It callback
// - all AfterEaches in the order in which they were defined
// - all DeferCleanups with the order reversed (first-in-last-out)
// - f.AfterEach
NewFrameworkExtensions []func(f *Framework)
)
// Framework supports common operations used by e2e tests; it will keep a client & a namespace for you.
// Eventual goal is to merge this with integration test framework.
type Framework struct {
@ -155,7 +174,13 @@ func NewFramework(baseName string, options Options, client clientset.Interface)
Timeouts: NewTimeoutContextWithDefaults(),
}
// The order is important here: if the extension calls ginkgo.BeforeEach
// itself, then it can be sure that f.BeforeEach already ran when its
// own callback gets invoked.
ginkgo.BeforeEach(f.BeforeEach, AnnotatedLocation("set up framework"))
for _, extension := range NewFrameworkExtensions {
extension(f)
}
return f
}