api: match permanent sentinel errors after backoff unwrapping (#32197)

This commit is contained in:
andig 2026-07-27 19:00:46 +02:00 • committed by GitHub
parent af8ecb2de2
commit 8bbbc2497d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 64 additions and 5 deletions

27
api/error_test.go Normal file
View 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)
}
}