diff --git a/minio/minio.go b/minio/minio.go index a97964a..cf1ec0d 100644 --- a/minio/minio.go +++ b/minio/minio.go @@ -19,7 +19,7 @@ import ( ) type MinioI interface { - UploadFile(ctx context.Context, filePath string, fileContent any, fileMimeType string) (url string, objectInfo *miniogo.ObjectInfo, err error) + UploadFile(ctx context.Context, logger *zap.Logger, filePath string, fileContent any, fileMimeType string) (url string, objectInfo *miniogo.ObjectInfo, err error) UploadFileBytes(ctx context.Context, logger *zap.Logger, filePath string, fileBytes []byte, fileMimeType string) (url string, objectInfo *miniogo.ObjectInfo, err error) DeleteFile(ctx context.Context, logger *zap.Logger, filePath string) (err error) GetFile(ctx context.Context, logger *zap.Logger, filePath string) ([]byte, error) @@ -86,9 +86,9 @@ func NewMinioClientAndInitBucket(ctx context.Context, cfg *Config, logger *zap.L return &minio{client: client, bucket: cfg.BucketName}, nil } -func (m *minio) UploadFile(ctx context.Context, filePath string, fileContent any, fileMimeType string) (url string, objectInfo *miniogo.ObjectInfo, err error) { +func (m *minio) UploadFile(ctx context.Context, logger *zap.Logger, filePath string, fileContent any, fileMimeType string) (url string, objectInfo *miniogo.ObjectInfo, err error) { jsonData, _ := json.Marshal(fileContent) - return m.UploadFileBytes(ctx, nil, filePath, jsonData, fileMimeType) + return m.UploadFileBytes(ctx, logger, filePath, jsonData, fileMimeType) } func (m *minio) UploadFileBytes(ctx context.Context, logger *zap.Logger, filePath string, fileBytes []byte, fileMimeType string) (url string, objectInfo *miniogo.ObjectInfo, err error) { diff --git a/minio/minio_test.go b/minio/minio_test.go index 3068b12..51715b9 100644 --- a/minio/minio_test.go +++ b/minio/minio_test.go @@ -7,6 +7,7 @@ import ( "github.com/gofrs/uuid" "github.com/stretchr/testify/require" + "go.uber.org/zap" miniox "github.com/instill-ai/x/minio" ) @@ -17,13 +18,14 @@ func TestMinio(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() + log, _ := zap.NewDevelopment() mc, err := miniox.NewMinioClientAndInitBucket(ctx, &miniox.Config{ Host: "localhost", Port: "19000", RootUser: "minioadmin", RootPwd: "minioadmin", BucketName: "instill-ai-model", - }, nil) + }, log) require.NoError(t, err) @@ -35,12 +37,12 @@ func TestMinio(t *testing.T) { data["uid"] = uid.String() jsonBytes, _ := json.Marshal(data) - url, stat, err := mc.UploadFile(ctx, fileName.String(), data, "application/json") + url, stat, err := mc.UploadFile(ctx, log, fileName.String(), data, "application/json") require.NoError(t, err) t.Log("url:", url) t.Log("size:", stat.Size) - fileBytes, err := mc.GetFile(ctx, nil, fileName.String()) + fileBytes, err := mc.GetFile(ctx, log, fileName.String()) require.NoError(t, err) require.Equal(t, jsonBytes, fileBytes) } diff --git a/mock/minio_i_mock.gen.go b/mock/minio_i_mock.gen.go index 602baa6..ee9f512 100644 --- a/mock/minio_i_mock.gen.go +++ b/mock/minio_i_mock.gen.go @@ -1370,7 +1370,7 @@ func (mmUploadFile *mMinioIMockUploadFile) invocationsDone() bool { } // UploadFile implements minio.MinioI -func (mmUploadFile *MinioIMock) UploadFile(ctx context.Context, filePath string, fileContent any, fileMimeType string) (url string, objectInfo *miniogo.ObjectInfo, err error) { +func (mmUploadFile *MinioIMock) UploadFile(ctx context.Context, logger *zap.Logger, filePath string, fileContent any, fileMimeType string) (url string, objectInfo *miniogo.ObjectInfo, err error) { mm_atomic.AddUint64(&mmUploadFile.beforeUploadFileCounter, 1) defer mm_atomic.AddUint64(&mmUploadFile.afterUploadFileCounter, 1)