Skip to content

Commit

Permalink
feat: add ExpectedErrorf
Browse files Browse the repository at this point in the history
Convenient.

Signed-off-by: Alexey Palazhchenko <[email protected]>
  • Loading branch information
AlekSi authored and talos-bot committed May 14, 2021
1 parent 3d83f61 commit 7885e16
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
10 changes: 5 additions & 5 deletions retry/constant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test_constantRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 3,
Expand All @@ -60,7 +60,7 @@ func Test_constantRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 5,
Expand Down Expand Up @@ -99,7 +99,7 @@ func Test_constantRetryer_Retry(t *testing.T) {
return fmt.Errorf("unexpected")
}

return ExpectedError(fmt.Errorf("unexpected"))
return ExpectedErrorf("unexpected")
},
},
expectedCount: 2,
Expand All @@ -120,7 +120,7 @@ func Test_constantRetryer_Retry(t *testing.T) {
return nil
}

return ExpectedError(fmt.Errorf("unexpected"))
return ExpectedErrorf("unexpected")
},
},
expectedCount: 2,
Expand Down Expand Up @@ -154,7 +154,7 @@ func Test_constantRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 1,
Expand Down
10 changes: 5 additions & 5 deletions retry/exponential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test_exponentialRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 4,
Expand All @@ -60,7 +60,7 @@ func Test_exponentialRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 5,
Expand Down Expand Up @@ -99,7 +99,7 @@ func Test_exponentialRetryer_Retry(t *testing.T) {
return fmt.Errorf("unexpected")
}

return ExpectedError(fmt.Errorf("unexpected"))
return ExpectedErrorf("unexpected")
},
},
expectedCount: 2,
Expand All @@ -120,7 +120,7 @@ func Test_exponentialRetryer_Retry(t *testing.T) {
return nil
}

return ExpectedError(fmt.Errorf("unexpected"))
return ExpectedErrorf("unexpected")
},
},
expectedCount: 2,
Expand Down Expand Up @@ -154,7 +154,7 @@ func Test_exponentialRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 2,
Expand Down
10 changes: 5 additions & 5 deletions retry/linear_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test_linearRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 5,
Expand All @@ -60,7 +60,7 @@ func Test_linearRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 9,
Expand Down Expand Up @@ -99,7 +99,7 @@ func Test_linearRetryer_Retry(t *testing.T) {
return fmt.Errorf("unexpected")
}

return ExpectedError(fmt.Errorf("unexpected"))
return ExpectedErrorf("unexpected")
},
},
expectedCount: 1,
Expand All @@ -120,7 +120,7 @@ func Test_linearRetryer_Retry(t *testing.T) {
return nil
}

return ExpectedError(fmt.Errorf("unexpected"))
return ExpectedErrorf("unexpected")
},
},
expectedCount: 2,
Expand Down Expand Up @@ -154,7 +154,7 @@ func Test_linearRetryer_Retry(t *testing.T) {
f: func() error {
count++

return ExpectedError(fmt.Errorf("expected"))
return ExpectedErrorf("expected")
},
},
expectedCount: 1,
Expand Down
5 changes: 5 additions & 0 deletions retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ func ExpectedError(err error) error {
return expectedError{err}
}

// ExpectedErrorf makes an expected error from given format and arguments.
func ExpectedErrorf(format string, a ...interface{}) error {
return ExpectedError(fmt.Errorf(format, a...))
}

// UnexpectedError error represents an error that is unexpected by the retrying
// function. This error is fatal.
//
Expand Down

0 comments on commit 7885e16

Please sign in to comment.