feat(minio): initial stable release v1.0.0 — Client interface, xerrors, GetObject, doc examples
Add Client interface with PutObject, GetObject, RemoveObject, PresignedGetObject, and HandleError; Component now embeds Client with Native() as escape hatch for operations not covered by the interface. Add xerrors dependency: HandleError maps minio-go error codes to portable typed codes (NoSuchKey → ErrNotFound, AccessDenied → ErrPermissionDenied, BucketAlreadyExists → ErrAlreadyExists, etc.). OnStop sets c.mc = nil for lifecycle consistency. doc.go updated with launcher wiring, upload, presigned URL, GetObject, and HandleError usage examples. API committed as stable. What's included: - Config with Endpoint, AccessKey, SecretKey, UseSSL, Bucket, Region (env-driven, embeddable) - Transport field in Config for test injection (env:"-", nil uses minio-go default) - Client interface: PutObject, GetObject, RemoveObject, PresignedGetObject, HandleError - Component interface: launcher.Component + health.Checkable + Client + Native() - New(logger, cfg) constructor for lifecycle registration via lc.Append - Automatic bucket creation on OnStart if bucket does not exist - Health check via BucketExists at LevelCritical priority - HandleError: maps minio-go ErrorResponse codes to xerrors typed errors - 21 unit tests using mock HTTP transport; no live server required
This commit is contained in:
55
errors_test.go
Normal file
55
errors_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user