Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch s3 putobject to upload function #2801

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/services/files/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (u *S3Uploader) UploadFileWithACL(fname string, uploadPath string, acl stri
}

// Upload the file to S3.
_, err = u.Client.PutObject(f, u.Bucket, uploadPath, acl)
_, err = u.Client.Upload(f, u.Bucket, uploadPath, acl)

if err != nil {
u.log.WithField("error", err.Error()).Error("Error uploading to AWS S3")
Expand Down
18 changes: 9 additions & 9 deletions pkg/services/files/uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var _ = Describe("Uploader Test", func() {
_ = os.Remove(file.Name())
}(file)

s3Client.EXPECT().PutObject(gomock.AssignableToTypeOf(&os.File{}), config.Get().BucketName, uploadPath, acl).Return(nil, nil)
s3Client.EXPECT().Upload(gomock.AssignableToTypeOf(&os.File{}), config.Get().BucketName, uploadPath, acl).Return(nil, nil)
uploadURL, err := s3Uploader.UploadFile(file.Name(), uploadPath)
Expect(err).ToNot(HaveOccurred())
expectedURL := fmt.Sprintf("https://%s.s3.%s.amazonaws.com/%s", s3Uploader.Bucket, conf.BucketRegion, uploadPath)
Expand All @@ -185,7 +185,7 @@ var _ = Describe("Uploader Test", func() {
_ = os.Remove(file.Name())
}(file)

s3Client.EXPECT().PutObject(gomock.AssignableToTypeOf(&os.File{}), config.Get().BucketName, uploadPath, acl).Return(nil, nil)
s3Client.EXPECT().Upload(gomock.AssignableToTypeOf(&os.File{}), config.Get().BucketName, uploadPath, acl).Return(nil, nil)

uploadURL, err := s3Uploader.UploadFileWithACL(file.Name(), uploadPath, "")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -200,15 +200,15 @@ var _ = Describe("Uploader Test", func() {
sourceFilePath := filepath.Join(os.TempDir(), sourceFileName)

// should not call S3Client PuObject
s3Client.EXPECT().PutObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
s3Client.EXPECT().Upload(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0)
_, err := s3Uploader.UploadFile(sourceFilePath, uploadPath)
expectedErrorMessage := fmt.Sprintf("%s: no such file or directory", sourceFilePath)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(expectedErrorMessage))
})

It("UploadFile should return error when PutObject fails", func() {
expectedError := errors.New("s3Client. PutObject failed to upload file")
It("UploadFile should return error when Upload fails", func() {
expectedError := errors.New("s3Client. Upload failed to upload file")
uploadPath := faker.UUIDHyphenated() + "/" + faker.UUIDHyphenated()

file, err := os.CreateTemp(os.TempDir(), "uploader-*.source-file ")
Expand All @@ -219,7 +219,7 @@ var _ = Describe("Uploader Test", func() {
_ = os.Remove(file.Name())
}(file)

s3Client.EXPECT().PutObject(gomock.AssignableToTypeOf(&os.File{}), config.Get().BucketName, uploadPath, acl).Return(nil, expectedError)
s3Client.EXPECT().Upload(gomock.AssignableToTypeOf(&os.File{}), config.Get().BucketName, uploadPath, acl).Return(nil, expectedError)
_, err = s3Uploader.UploadFile(file.Name(), uploadPath)
Expect(err).To(HaveOccurred())
Expect(err).To(Equal(err))
Expand Down Expand Up @@ -247,7 +247,7 @@ var _ = Describe("Uploader Test", func() {
wg := sync.WaitGroup{}
wg.Add(1)
expectedFilePath := fmt.Sprintf("%s/%s", orgID, strings.TrimPrefix(sourceFilePath, conf.RepoTempPath))
s3Client.EXPECT().PutObject(gomock.AssignableToTypeOf(&os.File{}), conf.BucketName, expectedFilePath, acl).
s3Client.EXPECT().Upload(gomock.AssignableToTypeOf(&os.File{}), conf.BucketName, expectedFilePath, acl).
DoAndReturn(func(arg0, arg1, arg2, arg3 interface{}) (interface{}, error) {
defer wg.Done()
return nil, nil
Expand Down Expand Up @@ -282,11 +282,11 @@ var _ = Describe("Uploader Test", func() {
wg := sync.WaitGroup{}
wg.Add(1)
expectedFilePath := fmt.Sprintf("%s/%s", orgID, strings.TrimPrefix(sourceFilePath, conf.RepoTempPath))
s3Client.EXPECT().PutObject(gomock.AssignableToTypeOf(&os.File{}), conf.BucketName, expectedFilePath, acl).
s3Client.EXPECT().Upload(gomock.AssignableToTypeOf(&os.File{}), conf.BucketName, expectedFilePath, acl).
DoAndReturn(func(arg0, arg1, arg2, arg3 interface{}) (interface{}, error) {
return nil, errors.New("Error uploading file")
})
s3Client.EXPECT().PutObject(gomock.AssignableToTypeOf(&os.File{}), conf.BucketName, expectedFilePath, acl).
s3Client.EXPECT().Upload(gomock.AssignableToTypeOf(&os.File{}), conf.BucketName, expectedFilePath, acl).
DoAndReturn(func(arg0, arg1, arg2, arg3 interface{}) (interface{}, error) {
defer wg.Done()
return nil, nil
Expand Down
Loading