diff --git a/pkg/reconcile/reconcile.go b/pkg/reconcile/reconcile.go index 50dea3615b..c6f7f64a65 100644 --- a/pkg/reconcile/reconcile.go +++ b/pkg/reconcile/reconcile.go @@ -32,6 +32,14 @@ type Result struct { RequeueAfter time.Duration } +// IsZero returns true if this result is empty. +func (r *Result) IsZero() bool { + if r == nil { + return true + } + return *r == Result{} +} + // Request contains the information necessary to reconcile a Kubernetes object. This includes the // information to uniquely identify the object - its Name and Namespace. It does NOT contain information about // any specific Event or the object contents itself. diff --git a/pkg/reconcile/reconcile_test.go b/pkg/reconcile/reconcile_test.go index 120f2789f4..88b4af7475 100644 --- a/pkg/reconcile/reconcile_test.go +++ b/pkg/reconcile/reconcile_test.go @@ -18,6 +18,7 @@ package reconcile_test import ( "fmt" + "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -26,6 +27,27 @@ import ( ) var _ = Describe("reconcile", func() { + Describe("Result", func() { + It("IsZero should return true if empty", func() { + var res *reconcile.Result + Expect(res.IsZero()).To(BeTrue()) + res2 := &reconcile.Result{} + Expect(res2.IsZero()).To(BeTrue()) + res3 := reconcile.Result{} + Expect(res3.IsZero()).To(BeTrue()) + }) + + It("IsZero should return false if Requeue is set to true", func() { + res := reconcile.Result{Requeue: true} + Expect(res.IsZero()).To(BeFalse()) + }) + + It("IsZero should return false if RequeueAfter is set to true", func() { + res := reconcile.Result{RequeueAfter: 1 * time.Second} + Expect(res.IsZero()).To(BeFalse()) + }) + }) + Describe("Func", func() { It("should call the function with the request and return a nil error.", func() { request := reconcile.Request{