Files
mtusi2026lab7/internal/storage/autherr_test.go
T

27 lines
832 B
Go

package storage
import (
"errors"
"fmt"
"testing"
"github.com/minio/minio-go/v7"
)
func TestIsAuthError(t *testing.T) {
wrap := func(code string) error { return fmt.Errorf("s3 put: %w", minio.ErrorResponse{Code: code}) }
for code, want := range map[string]bool{
"InvalidAccessKeyId": true, // ключ удалён (отзыв)
"SignatureDoesNotMatch": true, // secret key сменён (ротация)
"AccessDenied": false, // отказ политики по префиксу — повтор не поможет
"NoSuchKey": false,
} {
if got := IsAuthError(wrap(code)); got != want {
t.Errorf("%s: got %v, want %v", code, got, want)
}
}
if IsAuthError(errors.New("dial tcp: connection refused")) || IsAuthError(nil) {
t.Error("non-S3 error classified as auth error")
}
}