Skip to content

Commit

Permalink
Make Permanent(nil) return nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobg authored and cenkalti committed Jun 4, 2020
1 parent 31cc31b commit 382faa4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion retry.go
Expand Up @@ -89,7 +89,10 @@ func (e *PermanentError) Unwrap() error {
}

// Permanent wraps the given err in a *PermanentError.
func Permanent(err error) *PermanentError {
func Permanent(err error) error {
if err == nil {
return nil
}
return &PermanentError{
Err: err,
}
Expand Down
17 changes: 16 additions & 1 deletion retry_test.go
Expand Up @@ -88,7 +88,7 @@ func TestRetryContext(t *testing.T) {
}
}

func TestRetryPermenent(t *testing.T) {
func TestRetryPermanent(t *testing.T) {
const permanentOn = 3
var i = 0

Expand All @@ -114,3 +114,18 @@ func TestRetryPermenent(t *testing.T) {
t.Errorf("invalid number of retries: %d", i)
}
}

func TestPermanent(t *testing.T) {
want := errors.New("foo")
var err error = Permanent(want)

got := errors.Unwrap(err)
if got != want {
t.Errorf("got %v, want %v", got, want)
}

err = Permanent(nil)
if err != nil {
t.Errorf("got %v, want nil", err)
}
}

0 comments on commit 382faa4

Please sign in to comment.