Skip to content

Commit

Permalink
Merge pull request #1059 from vincepri/add-iszero-result
Browse files Browse the repository at this point in the history
✨ Add IsZero method to reconcile.Result
  • Loading branch information
k8s-ci-robot authored Jul 21, 2020
2 parents 229c3c3 + bef7dd5 commit c5fc2a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/reconcile/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions pkg/reconcile/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package reconcile_test

import (
"fmt"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -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{
Expand Down

0 comments on commit c5fc2a5

Please sign in to comment.