Commit e769c33d authored by Maru Newby's avatar Maru Newby

fed: Improve e2e framework setup/teardown

- reuse default framework setup rather than duplicating - skip namespace creation for each test in hosting cluster - ensure FederationAfterEach is called if BeforeEach fails
parent 61703787
...@@ -40,33 +40,40 @@ import ( ...@@ -40,33 +40,40 @@ import (
type Framework struct { type Framework struct {
*framework.Framework *framework.Framework
// To make sure that this framework cleans up after itself, no matter what,
// we install a Cleanup action before each test and clear it after. If we
// should abort, the AfterSuite hook should run all Cleanup actions.
cleanupHandle framework.CleanupActionHandle
FederationClientset *federation_clientset.Clientset FederationClientset *federation_clientset.Clientset
FederationNamespace *v1.Namespace FederationNamespace *v1.Namespace
} }
func NewDefaultFederatedFramework(baseName string) *Framework { func NewDefaultFederatedFramework(baseName string) *Framework {
options := framework.FrameworkOptions{ f := &Framework{}
ClientQPS: 20,
ClientBurst: 50, // Register the federation cleanup before initializing the default
} // e2e framework to ensure it gets called before the default
// framework's cleanup.
AfterEach(f.FederationAfterEach)
f := &Framework{&framework.Framework{ f.Framework = framework.NewDefaultFramework(baseName)
BaseName: baseName, f.Framework.SkipNamespaceCreation = true
AddonResourceConstraints: make(map[string]framework.ResourceConstraint),
Options: options,
ClientSet: nil,
}, nil, &v1.Namespace{}}
BeforeEach(f.BeforeEach) // Register the federation setup after initializing the default
// e2e framework to ensure it gets called after the default
// framework's setup.
BeforeEach(f.FederationBeforeEach) BeforeEach(f.FederationBeforeEach)
AfterEach(f.FederationAfterEach)
AfterEach(f.AfterEach)
return f return f
} }
// FederationBeforeEach checks for federation apiserver is ready and makes a namespace. // FederationBeforeEach checks for federation apiserver is ready and makes a namespace.
func (f *Framework) FederationBeforeEach() { func (f *Framework) FederationBeforeEach() {
// The fact that we need this feels like a bug in ginkgo.
// https://github.com/onsi/ginkgo/issues/222
f.cleanupHandle = framework.AddCleanupAction(f.FederationAfterEach)
if f.FederationClientset == nil { if f.FederationClientset == nil {
By("Creating a release 1.5 federation Clientset") By("Creating a release 1.5 federation Clientset")
var err error var err error
...@@ -122,6 +129,8 @@ func (f *Framework) deleteFederationNs() { ...@@ -122,6 +129,8 @@ func (f *Framework) deleteFederationNs() {
// FederationAfterEach deletes the namespace, after reading its events. // FederationAfterEach deletes the namespace, after reading its events.
func (f *Framework) FederationAfterEach() { func (f *Framework) FederationAfterEach() {
framework.RemoveCleanupAction(f.cleanupHandle)
// DeleteNamespace at the very end in defer, to avoid any // DeleteNamespace at the very end in defer, to avoid any
// expectation failures preventing deleting the namespace. // expectation failures preventing deleting the namespace.
defer func() { defer func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment