56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
|
|
package minio
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
miniogo "github.com/minio/minio-go/v7"
|
||
|
|
|
||
|
|
"code.nochebuena.dev/go/xerrors"
|
||
|
|
)
|
||
|
|
|
||
|
|
func assertXCode(t *testing.T, err error, want xerrors.Code) {
|
||
|
|
t.Helper()
|
||
|
|
var xe *xerrors.Err
|
||
|
|
if !errors.As(err, &xe) {
|
||
|
|
t.Fatalf("expected *xerrors.Err, got %T: %v", err, err)
|
||
|
|
}
|
||
|
|
if xe.Code() != want {
|
||
|
|
t.Errorf("want code %s, got %s", want, xe.Code())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHandleError_Nil(t *testing.T) {
|
||
|
|
if HandleError(nil) != nil {
|
||
|
|
t.Error("HandleError(nil) should return nil")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHandleError_NoSuchBucket(t *testing.T) {
|
||
|
|
assertXCode(t, HandleError(miniogo.ErrorResponse{Code: miniogo.NoSuchBucket}), xerrors.ErrNotFound)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHandleError_NoSuchKey(t *testing.T) {
|
||
|
|
assertXCode(t, HandleError(miniogo.ErrorResponse{Code: miniogo.NoSuchKey}), xerrors.ErrNotFound)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHandleError_AccessDenied(t *testing.T) {
|
||
|
|
assertXCode(t, HandleError(miniogo.ErrorResponse{Code: miniogo.AccessDenied}), xerrors.ErrPermissionDenied)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHandleError_InvalidAccessKeyID(t *testing.T) {
|
||
|
|
assertXCode(t, HandleError(miniogo.ErrorResponse{Code: miniogo.InvalidAccessKeyID}), xerrors.ErrPermissionDenied)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHandleError_BucketAlreadyExists(t *testing.T) {
|
||
|
|
assertXCode(t, HandleError(miniogo.ErrorResponse{Code: miniogo.BucketAlreadyExists}), xerrors.ErrAlreadyExists)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHandleError_BucketAlreadyOwnedByYou(t *testing.T) {
|
||
|
|
assertXCode(t, HandleError(miniogo.ErrorResponse{Code: miniogo.BucketAlreadyOwnedByYou}), xerrors.ErrAlreadyExists)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHandleError_Unknown(t *testing.T) {
|
||
|
|
assertXCode(t, HandleError(miniogo.ErrorResponse{Code: "SomeUnknownCode"}), xerrors.ErrInternal)
|
||
|
|
}
|