forked from TrueCloudLab/frostfs-sdk-go
09ed6077f9
Client errors are quite often wrapped in context. When checking a specific error, it is required not to lose the ability to determine it, regardless of the attached context. In previous implementation `IsErr*` functions didn't support wrapped errors. Make `IsErr*` functions to preliminarily unwrap `error` argument before type assertion. Use `errors.Unwrap` for this instead of `errors.As` since the latter has the overhead of filling in an error. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
46 lines
956 B
Go
46 lines
956 B
Go
package client_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestErrors(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
check func(error) bool
|
|
errs []error
|
|
}{
|
|
{
|
|
check: client.IsErrContainerNotFound,
|
|
errs: []error{
|
|
apistatus.ContainerNotFound{},
|
|
new(apistatus.ContainerNotFound),
|
|
},
|
|
},
|
|
{
|
|
check: client.IsErrObjectNotFound,
|
|
errs: []error{
|
|
apistatus.ObjectNotFound{},
|
|
new(apistatus.ObjectNotFound),
|
|
},
|
|
},
|
|
{
|
|
check: client.IsErrObjectAlreadyRemoved,
|
|
errs: []error{
|
|
apistatus.ObjectAlreadyRemoved{},
|
|
new(apistatus.ObjectAlreadyRemoved),
|
|
},
|
|
},
|
|
} {
|
|
require.NotEmpty(t, tc.errs)
|
|
|
|
for i := range tc.errs {
|
|
require.True(t, tc.check(tc.errs[i]), tc.errs[i])
|
|
require.True(t, tc.check(fmt.Errorf("some context: %w", tc.errs[i])), tc.errs[i])
|
|
}
|
|
}
|
|
}
|