2022-12-20 08:38:58 +00:00
|
|
|
package frostfs
|
2022-04-21 08:49:56 +00:00
|
|
|
|
|
|
|
import (
|
2023-06-13 14:47:31 +00:00
|
|
|
"context"
|
|
|
|
"errors"
|
2022-04-21 08:49:56 +00:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
2023-06-13 14:47:31 +00:00
|
|
|
"time"
|
2022-04-21 08:49:56 +00:00
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
2023-06-13 14:47:31 +00:00
|
|
|
errorsFrost "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/errors"
|
2023-09-26 11:26:33 +00:00
|
|
|
apistatus "git.frostfs.info/mbiryukova/frostfs-sdk-go/client/status"
|
2022-04-21 08:49:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-06-13 14:47:31 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2022-04-21 08:49:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrorChecking(t *testing.T) {
|
|
|
|
reason := "some reason"
|
|
|
|
err := new(apistatus.ObjectAccessDenied)
|
|
|
|
err.WriteReason(reason)
|
|
|
|
|
|
|
|
var wrappedError error
|
|
|
|
|
2023-06-13 14:47:31 +00:00
|
|
|
if fetchedReason, ok := errorsFrost.IsErrObjectAccessDenied(err); ok {
|
2022-06-06 11:09:09 +00:00
|
|
|
wrappedError = fmt.Errorf("%w: %s", layer.ErrAccessDenied, fetchedReason)
|
2022-04-21 08:49:56 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 11:09:09 +00:00
|
|
|
require.ErrorIs(t, wrappedError, layer.ErrAccessDenied)
|
2022-04-21 08:49:56 +00:00
|
|
|
require.Contains(t, wrappedError.Error(), reason)
|
|
|
|
}
|
2023-06-13 14:47:31 +00:00
|
|
|
|
|
|
|
func TestErrorTimeoutChecking(t *testing.T) {
|
|
|
|
t.Run("simple timeout", func(t *testing.T) {
|
|
|
|
require.True(t, errorsFrost.IsTimeoutError(errors.New("timeout")))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("deadline exceeded", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
|
|
|
defer cancel()
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
|
|
|
|
require.True(t, errorsFrost.IsTimeoutError(ctx.Err()))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("grpc deadline exceeded", func(t *testing.T) {
|
|
|
|
err := fmt.Errorf("wrap grpc error: %w", status.Error(codes.DeadlineExceeded, "error"))
|
|
|
|
require.True(t, errorsFrost.IsTimeoutError(err))
|
|
|
|
})
|
|
|
|
}
|