api: match permanent sentinel errors after backoff unwrapping (#32197)
This commit is contained in:
parent
af8ecb2de2
commit
8bbbc2497d
2 changed files with 64 additions and 5 deletions
27
api/error_test.go
Normal file
27
api/error_test.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// Backoff returns permanent errors unwrapped. These must still match the sentinel.
|
||||
func TestPermanentSentinels(t *testing.T) {
|
||||
for _, tc := range []struct{ err, other error }{
|
||||
{ErrNotAvailable, ErrUnsupportedPlatform},
|
||||
{ErrUnsupportedPlatform, ErrNotAvailable},
|
||||
{ErrMissingCredentials, ErrMissingToken},
|
||||
{ErrMissingToken, ErrMissingCredentials},
|
||||
} {
|
||||
_, unwrapped := backoff.RetryWithData(func() (int, error) {
|
||||
return 0, tc.err
|
||||
}, &backoff.StopBackOff{})
|
||||
|
||||
assert.ErrorIs(t, unwrapped, tc.err)
|
||||
assert.ErrorIs(t, fmt.Errorf("wrapped: %w", unwrapped), tc.err)
|
||||
assert.NotErrorIs(t, unwrapped, tc.other)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue