2022-06-27 10:24:17 +03:00
|
|
|
package client_test
|
|
|
|
|
|
|
|
import (
|
2022-06-27 10:39:20 +03:00
|
|
|
"fmt"
|
2022-06-27 10:24:17 +03:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 14:20:03 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2022-06-27 10:24:17 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrors(t *testing.T) {
|
2023-08-02 10:01:03 +03:00
|
|
|
errs := []struct {
|
2022-06-27 10:24:17 +03:00
|
|
|
check func(error) bool
|
2023-08-02 10:01:03 +03:00
|
|
|
err error
|
2022-06-27 10:24:17 +03:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
check: client.IsErrContainerNotFound,
|
2023-08-02 10:01:03 +03:00
|
|
|
err: new(apistatus.ContainerNotFound),
|
2022-06-27 10:24:17 +03:00
|
|
|
},
|
2022-08-01 17:17:48 +03:00
|
|
|
{
|
|
|
|
check: client.IsErrEACLNotFound,
|
2023-08-02 10:01:03 +03:00
|
|
|
err: new(apistatus.EACLNotFound),
|
2022-08-01 17:17:48 +03:00
|
|
|
},
|
2022-06-27 10:24:17 +03:00
|
|
|
{
|
|
|
|
check: client.IsErrObjectNotFound,
|
2023-08-02 10:01:03 +03:00
|
|
|
err: new(apistatus.ObjectNotFound),
|
2022-06-27 10:24:17 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
check: client.IsErrObjectAlreadyRemoved,
|
2023-08-02 10:01:03 +03:00
|
|
|
err: new(apistatus.ObjectAlreadyRemoved),
|
2022-06-27 10:24:17 +03:00
|
|
|
},
|
2022-06-27 10:45:43 +03:00
|
|
|
{
|
|
|
|
check: client.IsErrSessionExpired,
|
2023-08-02 10:01:03 +03:00
|
|
|
err: new(apistatus.SessionTokenExpired),
|
2022-06-27 10:45:43 +03:00
|
|
|
}, {
|
|
|
|
check: client.IsErrSessionNotFound,
|
2023-08-02 10:01:03 +03:00
|
|
|
err: new(apistatus.SessionTokenNotFound),
|
2022-06-27 10:45:43 +03:00
|
|
|
},
|
2023-08-02 10:01:03 +03:00
|
|
|
}
|
2022-06-27 10:24:17 +03:00
|
|
|
|
2023-08-02 10:01:03 +03: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 10:24:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|