Roman Loginov
8b3252cbd0
The Access Denied status may be received from APE due to exceeding the quota. In this situation, you need to return the appropriate error. The Conflict status is used because this error was made based on the LimitExceeded error from aws iam error https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateUser.html#API_CreateUser_Errors. Signed-off-by: Roman Loginov <r.loginov@yadro.com>
92 lines
2.6 KiB
Go
92 lines
2.6 KiB
Go
package frostfs
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/frostfs"
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func TestHandleObjectError(t *testing.T) {
|
|
msg := "some msg"
|
|
|
|
t.Run("nil error", func(t *testing.T) {
|
|
err := handleObjectError(msg, nil)
|
|
require.Nil(t, err)
|
|
})
|
|
|
|
t.Run("simple access denied", func(t *testing.T) {
|
|
reason := "some reason"
|
|
inputErr := new(apistatus.ObjectAccessDenied)
|
|
inputErr.WriteReason(reason)
|
|
|
|
err := handleObjectError(msg, inputErr)
|
|
require.ErrorIs(t, err, frostfs.ErrAccessDenied)
|
|
require.Contains(t, err.Error(), reason)
|
|
require.Contains(t, err.Error(), msg)
|
|
})
|
|
|
|
t.Run("access denied - quota reached", func(t *testing.T) {
|
|
reason := "Quota limit reached"
|
|
inputErr := new(apistatus.ObjectAccessDenied)
|
|
inputErr.WriteReason(reason)
|
|
|
|
err := handleObjectError(msg, inputErr)
|
|
require.ErrorIs(t, err, frostfs.ErrQuotaLimitReached)
|
|
require.Contains(t, err.Error(), reason)
|
|
require.Contains(t, err.Error(), msg)
|
|
})
|
|
|
|
t.Run("simple timeout", func(t *testing.T) {
|
|
inputErr := errors.New("timeout")
|
|
|
|
err := handleObjectError(msg, inputErr)
|
|
require.ErrorIs(t, err, frostfs.ErrGatewayTimeout)
|
|
require.Contains(t, err.Error(), inputErr.Error())
|
|
require.Contains(t, err.Error(), msg)
|
|
})
|
|
|
|
t.Run("deadline exceeded", func(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
|
defer cancel()
|
|
<-ctx.Done()
|
|
|
|
err := handleObjectError(msg, ctx.Err())
|
|
require.ErrorIs(t, err, frostfs.ErrGatewayTimeout)
|
|
require.Contains(t, err.Error(), ctx.Err().Error())
|
|
require.Contains(t, err.Error(), msg)
|
|
})
|
|
|
|
t.Run("grpc deadline exceeded", func(t *testing.T) {
|
|
inputErr := fmt.Errorf("wrap grpc error: %w", status.Error(codes.DeadlineExceeded, "error"))
|
|
|
|
err := handleObjectError(msg, inputErr)
|
|
require.ErrorIs(t, err, frostfs.ErrGatewayTimeout)
|
|
require.Contains(t, err.Error(), inputErr.Error())
|
|
require.Contains(t, err.Error(), msg)
|
|
})
|
|
|
|
t.Run("global domain already", func(t *testing.T) {
|
|
inputErr := errors.New("global domain is already taken")
|
|
|
|
err := handleObjectError(msg, inputErr)
|
|
require.ErrorIs(t, err, frostfs.ErrGlobalDomainIsAlreadyTaken)
|
|
require.Contains(t, err.Error(), inputErr.Error())
|
|
require.Contains(t, err.Error(), msg)
|
|
})
|
|
|
|
t.Run("unknown error", func(t *testing.T) {
|
|
inputErr := errors.New("unknown error")
|
|
|
|
err := handleObjectError(msg, inputErr)
|
|
require.ErrorIs(t, err, inputErr)
|
|
require.Contains(t, err.Error(), msg)
|
|
})
|
|
}
|