Skip to content

✨ Add IsZero method to reconcile.Result #1059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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