mirror of
https://github.com/wahyd4/cert-manager.git
synced 2026-08-15 08:07:07 +10:00
Fix up bugs in unit testing framework
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package acme
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -25,9 +26,11 @@ type acmeFixture struct {
|
||||
Client *client.FakeACME
|
||||
|
||||
PreFn func(*acmeFixture)
|
||||
CheckFn func(*acmeFixture)
|
||||
CheckFn func(*acmeFixture, ...interface{})
|
||||
Err bool
|
||||
|
||||
Ctx context.Context
|
||||
|
||||
// f is the integration test fixture being used for this test
|
||||
f *unit.Fixture
|
||||
}
|
||||
@@ -36,6 +39,9 @@ func (s *acmeFixture) Setup(t *testing.T) {
|
||||
if s.Client == nil {
|
||||
s.Client = &client.FakeACME{}
|
||||
}
|
||||
if s.Ctx == nil {
|
||||
s.Ctx = context.Background()
|
||||
}
|
||||
s.f = &unit.Fixture{
|
||||
T: t,
|
||||
KubeObjects: s.KubeObjects,
|
||||
@@ -50,13 +56,13 @@ func (s *acmeFixture) Setup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *acmeFixture) Finish(t *testing.T) {
|
||||
func (s *acmeFixture) Finish(t *testing.T, args ...interface{}) {
|
||||
defer s.f.Stop()
|
||||
// resync listers before running checks
|
||||
s.f.Sync()
|
||||
// run custom checks
|
||||
if s.CheckFn != nil {
|
||||
s.CheckFn(s)
|
||||
s.CheckFn(s, args...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -60,7 +60,10 @@ func (s *Fixture) CertManagerInformerFactory() informers.SharedInformerFactory {
|
||||
func (s *Fixture) Start() {
|
||||
s.kubeClient = kubefake.NewSimpleClientset(s.KubeObjects...)
|
||||
s.cmClient = cmfake.NewSimpleClientset(s.CertManagerObjects...)
|
||||
s.recorder = record.NewFakeRecorder(0)
|
||||
// create a fake recorder with a buffer of 5.
|
||||
// this may need to be increased in future to acomodate tests that
|
||||
// produce more than 5 events
|
||||
s.recorder = record.NewFakeRecorder(5)
|
||||
|
||||
s.kubeClient.PrependReactor("create", "*", func(action coretesting.Action) (handled bool, ret runtime.Object, err error) {
|
||||
obj := action.(coretesting.CreateAction).GetObject().(metav1.Object)
|
||||
@@ -79,8 +82,14 @@ func (s *Fixture) Start() {
|
||||
}
|
||||
|
||||
// Stop will signal the informers to stop watching changes
|
||||
// This method is *not* safe to be called concurrently
|
||||
func (s *Fixture) Stop() {
|
||||
if s.stopCh == nil {
|
||||
return
|
||||
}
|
||||
|
||||
close(s.stopCh)
|
||||
s.stopCh = nil
|
||||
}
|
||||
|
||||
// WaitForResync will wait for the informer factory informer duration by
|
||||
|
||||
Reference in New Issue
Block a user