Skip to content

Commit 2e62791

Browse files
committed
✨ Add IsZero method to reconcile.Result
Signed-off-by: Vince Prignano <[email protected]>
1 parent a148298 commit 2e62791

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pkg/reconcile/reconcile.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ 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+
if r == nil {
38+
return true
39+
}
40+
return *r == Result{}
41+
}
42+
3543
// Request contains the information necessary to reconcile a Kubernetes object. This includes the
3644
// information to uniquely identify the object - its Name and Namespace. It does NOT contain information about
3745
// any specific Event or the object contents itself.

pkg/reconcile/reconcile_test.go

Lines changed: 22 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,27 @@ import (
2627
)
2728

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

0 commit comments

Comments
 (0)