2022-06-27 07:24:17 +00:00
|
|
|
package client_test
|
|
|
|
|
|
|
|
import (
|
2022-06-27 07:39:20 +00:00
|
|
|
"fmt"
|
2022-06-27 07:24:17 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2022-06-27 07:24:17 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrors(t *testing.T) {
|
2023-08-02 07:01:03 +00:00
|
|
|
errs := []struct {
|
2022-06-27 07:24:17 +00:00
|
|
|
check func(error) bool
|
2023-08-02 07:01:03 +00:00
|
|
|
err error
|
2022-06-27 07:24:17 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
check: client.IsErrContainerNotFound,
|
2023-08-02 07:01:03 +00:00
|
|
|
err: new(apistatus.ContainerNotFound),
|
2022-06-27 07:24:17 +00:00
|
|
|
},
|
2022-08-01 14:17:48 +00:00
|
|
|
{
|
|
|
|
check: client.IsErrEACLNotFound,
|
2023-08-02 07:01:03 +00:00
|
|
|
err: new(apistatus.EACLNotFound),
|
2022-08-01 14:17:48 +00:00
|
|
|
},
|
2022-06-27 07:24:17 +00:00
|
|
|
{
|
|
|
|
check: client.IsErrObjectNotFound,
|
2023-08-02 07:01:03 +00:00
|
|
|
err: new(apistatus.ObjectNotFound),
|
2022-06-27 07:24:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
check: client.IsErrObjectAlreadyRemoved,
|
2023-08-02 07:01:03 +00:00
|
|
|
err: new(apistatus.ObjectAlreadyRemoved),
|
2022-06-27 07:24:17 +00:00
|
|
|
},
|
2022-06-27 07:45:43 +00:00
|
|
|
{
|
|
|
|
check: client.IsErrSessionExpired,
|
2023-08-02 07:01:03 +00:00
|
|
|
err: new(apistatus.SessionTokenExpired),
|
2022-06-27 07:45:43 +00:00
|
|
|
}, {
|
|
|
|
check: client.IsErrSessionNotFound,
|
2023-08-02 07:01:03 +00:00
|
|
|
err: new(apistatus.SessionTokenNotFound),
|
2022-06-27 07:45:43 +00:00
|
|
|
},
|
2023-08-02 07:01:03 +00:00
|
|
|
}
|
2022-06-27 07:24:17 +00:00
|
|
|
|
2023-08-02 07:01:03 +00:00
|
|
|
for i := range errs {
|
|
|
|
for j := range errs {
|
|
|
|
nestedErr := fmt.Errorf("top-level context: :%w", fmt.Errorf("inner context: %w", errs[j].err))
|
|
|
|
require.Equal(t, i == j, errs[i].check(errs[j].err))
|
|
|
|
require.Equal(t, i == j, errs[i].check(nestedErr))
|
2022-06-27 07:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|