Skip to content

Commit 3c8c10e

Browse files
committed
✨ Add IsZero method to reconcile.Result
Signed-off-by: Vince Prignano <vincepri@vmware.com>
1 parent 229c3c3 commit 3c8c10e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pkg/reconcile/reconcile.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ type Result struct {
3232
RequeueAfter time.Duration
3333
}
3434

35+
// IsZero returns true if this result is empty.
36+
func (r Result) IsZero() bool {
37+
return r == Result{}
38+
}
39+
3540
// Request contains the information necessary to reconcile a Kubernetes object. This includes the
3641
// information to uniquely identify the object - its Name and Namespace. It does NOT contain information about
3742
// any specific Event or the object contents itself.

pkg/reconcile/reconcile_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package reconcile_test
1818

1919
import (
2020
"fmt"
21+
"time"
2122

2223
. "github.com/onsi/ginkgo"
2324
. "github.com/onsi/gomega"
@@ -26,6 +27,25 @@ import (
2627
)
2728

2829
var _ = Describe("reconcile", func() {
30+
Describe("Result", func() {
31+
It("IsZero should return true if empty", func() {
32+
res := &reconcile.Result{}
33+
Expect(res.IsZero()).To(BeTrue())
34+
res2 := reconcile.Result{}
35+
Expect(res2.IsZero()).To(BeTrue())
36+
})
37+
38+
It("IsZero should return false if Requeue is set to true", func() {
39+
res := reconcile.Result{Requeue: true}
40+
Expect(res.IsZero()).To(BeFalse())
41+
})
42+
43+
It("IsZero should return false if RequeueAfter is set to true", func() {
44+
res := reconcile.Result{RequeueAfter: 1 * time.Second}
45+
Expect(res.IsZero()).To(BeFalse())
46+
})
47+
})
48+
2949
Describe("Func", func() {
3050
It("should call the function with the request and return a nil error.", func() {
3151
request := reconcile.Request{

0 commit comments

Comments
 (0)