Skip to content
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

added a pointer-receiver accessor to RetryableError #494

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions helper/resource/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func Retry(timeout time.Duration, f RetryFunc) error {
// RetryFunc is the function retried until it succeeds.
type RetryFunc func() *RetryError

func (e *RetryError) Error() error {
if e == nil {
return nil
}
return e.Err
}

// RetryError is the required return type of RetryFunc. It forces client code
// to choose whether or not a given error is retryable.
type RetryError struct {
Expand Down
21 changes: 21 additions & 0 deletions helper/resource/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ func TestRetryContext_cancel(t *testing.T) {
}
}

func TestRetryError_GetError(t *testing.T) {
t.Parallel()

var retryErr *RetryError
err := retryErr.Error()
if err != nil {
t.Fatalf("nil RetryError cast to non-nil error")
}

err = fmt.Errorf("test error")
retryErr = RetryableError(err)
if retryErr.Error() != err {
t.Fatalf("RetryableError did not return encapsulated error")
}

retryErr = NonRetryableError(err)
if retryErr.Error() != err {
t.Fatalf("RetryableError did not return encapsulated error")
}
}

func TestRetryContext_deadline(t *testing.T) {
t.Parallel()

Expand Down