Skip to content

Commit

Permalink
fix(minio): add logger in UploadFile input param
Browse files Browse the repository at this point in the history
  • Loading branch information
joremysh committed Oct 24, 2024
1 parent 6fa2745 commit e96ce6b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions minio/minio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)

Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion mock/minio_i_mock.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e96ce6b

Please sign in to comment.