forked from TrueCloudLab/frostfs-sdk-go
client: Extend tests for apistatuses
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
parent
1d952ced4e
commit
149b145073
1 changed files with 99 additions and 23 deletions
|
@ -12,9 +12,11 @@ func TestFromStatusV2(t *testing.T) {
|
|||
type statusConstructor func() apistatus.Status
|
||||
|
||||
for _, testItem := range [...]struct {
|
||||
status any // Status or statusConstructor
|
||||
codeV2 uint64
|
||||
messageV2 string
|
||||
status any // Status or statusConstructor
|
||||
codeV2 uint64
|
||||
messageV2 string
|
||||
compatibleErrs []error
|
||||
checkAsErr func(error) bool
|
||||
}{
|
||||
{
|
||||
status: errors.New("some error"),
|
||||
|
@ -30,7 +32,7 @@ func TestFromStatusV2(t *testing.T) {
|
|||
codeV2: 0,
|
||||
},
|
||||
{
|
||||
status: true,
|
||||
status: false,
|
||||
codeV2: 0,
|
||||
},
|
||||
{
|
||||
|
@ -43,93 +45,155 @@ func TestFromStatusV2(t *testing.T) {
|
|||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
var st apistatus.ServerInternal
|
||||
|
||||
st := new(apistatus.ServerInternal)
|
||||
st.SetMessage("internal error message")
|
||||
|
||||
return st
|
||||
}),
|
||||
codeV2: 1024,
|
||||
codeV2: 1024,
|
||||
compatibleErrs: []error{apistatus.ErrServerInternal, apistatus.ServerInternal{}, &apistatus.ServerInternal{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.ServerInternal
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
var st apistatus.WrongMagicNumber
|
||||
|
||||
st := new(apistatus.WrongMagicNumber)
|
||||
st.WriteCorrectMagic(322)
|
||||
|
||||
return st
|
||||
}),
|
||||
codeV2: 1025,
|
||||
codeV2: 1025,
|
||||
compatibleErrs: []error{apistatus.ErrWrongMagicNumber, apistatus.WrongMagicNumber{}, &apistatus.WrongMagicNumber{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.WrongMagicNumber
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.ObjectLocked)
|
||||
}),
|
||||
codeV2: 2050,
|
||||
codeV2: 2050,
|
||||
compatibleErrs: []error{apistatus.ErrObjectLocked, apistatus.ObjectLocked{}, &apistatus.ObjectLocked{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.ObjectLocked
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.LockNonRegularObject)
|
||||
}),
|
||||
codeV2: 2051,
|
||||
codeV2: 2051,
|
||||
compatibleErrs: []error{apistatus.ErrLockNonRegularObject, apistatus.LockNonRegularObject{}, &apistatus.LockNonRegularObject{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.LockNonRegularObject
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
var st apistatus.ObjectAccessDenied
|
||||
|
||||
st := new(apistatus.ObjectAccessDenied)
|
||||
st.WriteReason("any reason")
|
||||
|
||||
return st
|
||||
}),
|
||||
codeV2: 2048,
|
||||
codeV2: 2048,
|
||||
compatibleErrs: []error{apistatus.ErrObjectAccessDenied, apistatus.ObjectAccessDenied{}, &apistatus.ObjectAccessDenied{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.ObjectAccessDenied
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.ObjectNotFound)
|
||||
}),
|
||||
codeV2: 2049,
|
||||
codeV2: 2049,
|
||||
compatibleErrs: []error{apistatus.ErrObjectNotFound, apistatus.ObjectNotFound{}, &apistatus.ObjectNotFound{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.ObjectNotFound
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.ObjectAlreadyRemoved)
|
||||
}),
|
||||
codeV2: 2052,
|
||||
codeV2: 2052,
|
||||
compatibleErrs: []error{apistatus.ErrObjectAlreadyRemoved, apistatus.ObjectAlreadyRemoved{}, &apistatus.ObjectAlreadyRemoved{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.ObjectAlreadyRemoved
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: statusConstructor(func() apistatus.Status {
|
||||
return new(apistatus.ObjectOutOfRange)
|
||||
}),
|
||||
codeV2: 2053,
|
||||
codeV2: 2053,
|
||||
compatibleErrs: []error{apistatus.ErrObjectOutOfRange, apistatus.ObjectOutOfRange{}, &apistatus.ObjectOutOfRange{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.ObjectOutOfRange
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.ContainerNotFound)
|
||||
}),
|
||||
codeV2: 3072,
|
||||
codeV2: 3072,
|
||||
compatibleErrs: []error{apistatus.ErrContainerNotFound, apistatus.ContainerNotFound{}, &apistatus.ContainerNotFound{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.ContainerNotFound
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.EACLNotFound)
|
||||
}),
|
||||
codeV2: 3073,
|
||||
codeV2: 3073,
|
||||
compatibleErrs: []error{apistatus.ErrEACLNotFound, apistatus.EACLNotFound{}, &apistatus.EACLNotFound{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.EACLNotFound
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.SessionTokenNotFound)
|
||||
}),
|
||||
codeV2: 4096,
|
||||
codeV2: 4096,
|
||||
compatibleErrs: []error{apistatus.ErrSessionTokenNotFound, apistatus.SessionTokenNotFound{}, &apistatus.SessionTokenNotFound{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.SessionTokenNotFound
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.SessionTokenExpired)
|
||||
}),
|
||||
codeV2: 4097,
|
||||
codeV2: 4097,
|
||||
compatibleErrs: []error{apistatus.ErrSessionTokenExpired, apistatus.SessionTokenExpired{}, &apistatus.SessionTokenExpired{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.SessionTokenExpired
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.NodeUnderMaintenance)
|
||||
}),
|
||||
codeV2: 1027,
|
||||
codeV2: 1027,
|
||||
compatibleErrs: []error{apistatus.ErrNodeUnderMaintenance, apistatus.NodeUnderMaintenance{}, &apistatus.NodeUnderMaintenance{}, apistatus.Error},
|
||||
checkAsErr: func(err error) bool {
|
||||
var target *apistatus.NodeUnderMaintenance
|
||||
return errors.As(err, &target)
|
||||
},
|
||||
},
|
||||
} {
|
||||
var st apistatus.Status
|
||||
|
@ -158,5 +222,17 @@ func TestFromStatusV2(t *testing.T) {
|
|||
// must generate the same status.Status message
|
||||
require.Equal(t, stv2, res)
|
||||
}
|
||||
|
||||
randomError := errors.New("garbage")
|
||||
errFromStatus := apistatus.ErrFromStatus(st)
|
||||
|
||||
for _, err := range testItem.compatibleErrs {
|
||||
require.ErrorIs(t, errFromStatus, err)
|
||||
require.NotErrorIs(t, randomError, err)
|
||||
}
|
||||
|
||||
if testItem.checkAsErr != nil {
|
||||
require.True(t, testItem.checkAsErr(errFromStatus))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue