2023-02-14 14:27:06 +00:00
|
|
|
package rbac_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-08-18 18:55:43 +00:00
|
|
|
"github.com/coder/coder/v2/coderd/rbac"
|
2023-02-14 14:27:06 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsUnauthorizedError(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
t.Run("NotWrapped", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
errFunc := func() error {
|
|
|
|
return rbac.UnauthorizedError{}
|
|
|
|
}
|
|
|
|
|
|
|
|
err := errFunc()
|
|
|
|
require.True(t, rbac.IsUnauthorizedError(err))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Wrapped", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
errFunc := func() error {
|
|
|
|
return xerrors.Errorf("test error: %w", rbac.UnauthorizedError{})
|
|
|
|
}
|
|
|
|
err := errFunc()
|
|
|
|
require.True(t, rbac.IsUnauthorizedError(err))
|
|
|
|
})
|
|
|
|
}
|