Skip to content

Commit

Permalink
Merge pull request #54 from pdelagrave/contenttype
Browse files Browse the repository at this point in the history
Added the option to set the content-type metadata when uploading a file
  • Loading branch information
vito authored Nov 3, 2016
2 parents 52d303d + b8981c5 commit b4a70c6
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 78 deletions.
75 changes: 56 additions & 19 deletions fakes/fake_s3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package fakes
import (
"sync"

"github.com/concourse/s3-resource"
s3resource "github.com/concourse/s3-resource"
)

type FakeS3Client struct {
Expand All @@ -28,15 +28,13 @@ type FakeS3Client struct {
result1 []string
result2 error
}
UploadFileStub func(bucketName string, remotePath string, localPath string, acl string, serverSideEncryption string, kmsKeyId string) (string, error)
UploadFileStub func(bucketName string, remotePath string, localPath string, options s3resource.UploadFileOptions) (string, error)
uploadFileMutex sync.RWMutex
uploadFileArgsForCall []struct {
bucketName string
remotePath string
localPath string
acl string
serverSideEncryption string
kmsKeyId string
bucketName string
remotePath string
localPath string
options s3resource.UploadFileOptions
}
uploadFileReturns struct {
result1 string
Expand Down Expand Up @@ -83,6 +81,8 @@ type FakeS3Client struct {
uRLReturns struct {
result1 string
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}

func (fake *FakeS3Client) BucketFiles(bucketName string, prefixHint string) ([]string, error) {
Expand All @@ -91,6 +91,7 @@ func (fake *FakeS3Client) BucketFiles(bucketName string, prefixHint string) ([]s
bucketName string
prefixHint string
}{bucketName, prefixHint})
fake.recordInvocation("BucketFiles", []interface{}{bucketName, prefixHint})
fake.bucketFilesMutex.Unlock()
if fake.BucketFilesStub != nil {
return fake.BucketFilesStub(bucketName, prefixHint)
Expand Down Expand Up @@ -125,6 +126,7 @@ func (fake *FakeS3Client) BucketFileVersions(bucketName string, remotePath strin
bucketName string
remotePath string
}{bucketName, remotePath})
fake.recordInvocation("BucketFileVersions", []interface{}{bucketName, remotePath})
fake.bucketFileVersionsMutex.Unlock()
if fake.BucketFileVersionsStub != nil {
return fake.BucketFileVersionsStub(bucketName, remotePath)
Expand Down Expand Up @@ -153,19 +155,18 @@ func (fake *FakeS3Client) BucketFileVersionsReturns(result1 []string, result2 er
}{result1, result2}
}

func (fake *FakeS3Client) UploadFile(bucketName string, remotePath string, localPath string, acl string, serverSideEncryption string, kmsKeyId string) (string, error) {
func (fake *FakeS3Client) UploadFile(bucketName string, remotePath string, localPath string, options s3resource.UploadFileOptions) (string, error) {
fake.uploadFileMutex.Lock()
fake.uploadFileArgsForCall = append(fake.uploadFileArgsForCall, struct {
bucketName string
remotePath string
localPath string
acl string
serverSideEncryption string
kmsKeyId string
}{bucketName, remotePath, localPath, acl, serverSideEncryption, kmsKeyId})
bucketName string
remotePath string
localPath string
options s3resource.UploadFileOptions
}{bucketName, remotePath, localPath, options})
fake.recordInvocation("UploadFile", []interface{}{bucketName, remotePath, localPath, options})
fake.uploadFileMutex.Unlock()
if fake.UploadFileStub != nil {
return fake.UploadFileStub(bucketName, remotePath, localPath, acl, serverSideEncryption, kmsKeyId)
return fake.UploadFileStub(bucketName, remotePath, localPath, options)
} else {
return fake.uploadFileReturns.result1, fake.uploadFileReturns.result2
}
Expand All @@ -177,10 +178,10 @@ func (fake *FakeS3Client) UploadFileCallCount() int {
return len(fake.uploadFileArgsForCall)
}

func (fake *FakeS3Client) UploadFileArgsForCall(i int) (string, string, string, string) {
func (fake *FakeS3Client) UploadFileArgsForCall(i int) (string, string, string, s3resource.UploadFileOptions) {
fake.uploadFileMutex.RLock()
defer fake.uploadFileMutex.RUnlock()
return fake.uploadFileArgsForCall[i].bucketName, fake.uploadFileArgsForCall[i].remotePath, fake.uploadFileArgsForCall[i].localPath, fake.uploadFileArgsForCall[i].acl
return fake.uploadFileArgsForCall[i].bucketName, fake.uploadFileArgsForCall[i].remotePath, fake.uploadFileArgsForCall[i].localPath, fake.uploadFileArgsForCall[i].options
}

func (fake *FakeS3Client) UploadFileReturns(result1 string, result2 error) {
Expand All @@ -199,6 +200,7 @@ func (fake *FakeS3Client) DownloadFile(bucketName string, remotePath string, ver
versionID string
localPath string
}{bucketName, remotePath, versionID, localPath})
fake.recordInvocation("DownloadFile", []interface{}{bucketName, remotePath, versionID, localPath})
fake.downloadFileMutex.Unlock()
if fake.DownloadFileStub != nil {
return fake.DownloadFileStub(bucketName, remotePath, versionID, localPath)
Expand Down Expand Up @@ -232,6 +234,7 @@ func (fake *FakeS3Client) DeleteFile(bucketName string, remotePath string) error
bucketName string
remotePath string
}{bucketName, remotePath})
fake.recordInvocation("DeleteFile", []interface{}{bucketName, remotePath})
fake.deleteFileMutex.Unlock()
if fake.DeleteFileStub != nil {
return fake.DeleteFileStub(bucketName, remotePath)
Expand Down Expand Up @@ -266,6 +269,7 @@ func (fake *FakeS3Client) DeleteVersionedFile(bucketName string, remotePath stri
remotePath string
versionID string
}{bucketName, remotePath, versionID})
fake.recordInvocation("DeleteVersionedFile", []interface{}{bucketName, remotePath, versionID})
fake.deleteVersionedFileMutex.Unlock()
if fake.DeleteVersionedFileStub != nil {
return fake.DeleteVersionedFileStub(bucketName, remotePath, versionID)
Expand Down Expand Up @@ -301,6 +305,7 @@ func (fake *FakeS3Client) URL(bucketName string, remotePath string, private bool
private bool
versionID string
}{bucketName, remotePath, private, versionID})
fake.recordInvocation("URL", []interface{}{bucketName, remotePath, private, versionID})
fake.uRLMutex.Unlock()
if fake.URLStub != nil {
return fake.URLStub(bucketName, remotePath, private, versionID)
Expand Down Expand Up @@ -328,4 +333,36 @@ func (fake *FakeS3Client) URLReturns(result1 string) {
}{result1}
}

func (fake *FakeS3Client) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.bucketFilesMutex.RLock()
defer fake.bucketFilesMutex.RUnlock()
fake.bucketFileVersionsMutex.RLock()
defer fake.bucketFileVersionsMutex.RUnlock()
fake.uploadFileMutex.RLock()
defer fake.uploadFileMutex.RUnlock()
fake.downloadFileMutex.RLock()
defer fake.downloadFileMutex.RUnlock()
fake.deleteFileMutex.RLock()
defer fake.deleteFileMutex.RUnlock()
fake.deleteVersionedFileMutex.RLock()
defer fake.deleteVersionedFileMutex.RUnlock()
fake.uRLMutex.RLock()
defer fake.uRLMutex.RUnlock()
return fake.invocations
}

func (fake *FakeS3Client) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}

var _ s3resource.S3Client = new(FakeS3Client)
44 changes: 22 additions & 22 deletions integration/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-not-match-1"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-not-match-1"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -133,10 +133,10 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-2"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-2"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-1"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-1"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -194,7 +194,7 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -223,7 +223,7 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "file-does-not-match"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "file-does-not-match"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -263,10 +263,10 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -333,7 +333,7 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-not-match-1"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-not-match-1"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -368,13 +368,13 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-2"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-2"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-1"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-1"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-3"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-does-match-3"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -422,16 +422,16 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-1.2.0-rc.2"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-1.2.0-rc.2"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-1.2.0-rc.1"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-1.2.0-rc.1"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-1.1.0-rc.1"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-1.1.0-rc.1"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-1.1.0-rc.2"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, "file-1.1.0-rc.2"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -489,7 +489,7 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "file-does-not-match"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "file-does-not-match"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -535,13 +535,13 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

checkRequest.Source.VersionedFile = filepath.Join(directoryPrefix, "versioned-file")
Expand Down Expand Up @@ -598,13 +598,13 @@ var _ = Describe("check", func() {
Ω(err).ShouldNot(HaveOccurred())
tempFile.Close()

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "versioned-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())

checkRequest.Source.VersionedFile = filepath.Join(directoryPrefix, "versioned-file")
Expand Down
6 changes: 3 additions & 3 deletions integration/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var _ = Describe("in", func() {
err = ioutil.WriteFile(tempFile.Name(), []byte(fmt.Sprintf("some-file-%d", i)), 0755)
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, fmt.Sprintf("some-file-%d", i)), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, fmt.Sprintf("some-file-%d", i)), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())
}

Expand Down Expand Up @@ -192,7 +192,7 @@ var _ = Describe("in", func() {
err = ioutil.WriteFile(tempFile.Name(), []byte(fmt.Sprintf("some-file-%d", i)), 0755)
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "some-file"), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(versionedBucketName, filepath.Join(directoryPrefix, "some-file"), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())
}
err = os.Remove(tempFile.Name())
Expand Down Expand Up @@ -290,7 +290,7 @@ var _ = Describe("in", func() {
err = ioutil.WriteFile(tempFile.Name(), []byte(fmt.Sprintf("some-file-%d", i)), 0755)
Ω(err).ShouldNot(HaveOccurred())

_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, fmt.Sprintf("some-file-%d", i)), tempFile.Name(), "private", "", "")
_, err = s3client.UploadFile(bucketName, filepath.Join(directoryPrefix, fmt.Sprintf("some-file-%d", i)), tempFile.Name(), s3resource.NewUploadFileOptions())
Ω(err).ShouldNot(HaveOccurred())
}

Expand Down
Loading

0 comments on commit b4a70c6

Please sign in to comment.