Skip to content

Commit 01b01bc

Browse files
fsouzajasdel
authored andcommitted
s3manager: ensure parity between UploadInput and PutObjectInput (#89)
Fixes Metadata, StorageClass, ACL, and RequestPayer fields in UploadInput. Also updates test unit to identify if the types go out of sync. Fix #88.
1 parent 14d1593 commit 01b01bc

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

service/s3/s3manager/upload.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (m multiUploadError) UploadID() string {
9898
// UploadInput contains all input for upload requests to Amazon S3.
9999
type UploadInput struct {
100100
// The canned ACL to apply to the object.
101-
ACL *string `location:"header" locationName:"x-amz-acl" type:"string"`
101+
ACL s3.ObjectCannedACL `location:"header" locationName:"x-amz-acl" type:"string"`
102102

103103
Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"`
104104

@@ -140,13 +140,13 @@ type UploadInput struct {
140140
Key *string `location:"uri" locationName:"Key" type:"string" required:"true"`
141141

142142
// A map of metadata to store with the object in S3.
143-
Metadata map[string]*string `location:"headers" locationName:"x-amz-meta-" type:"map"`
143+
Metadata map[string]string `location:"headers" locationName:"x-amz-meta-" type:"map"`
144144

145145
// Confirms that the requester knows that she or he will be charged for the
146146
// request. Bucket owners need not specify this parameter in their requests.
147147
// Documentation on downloading objects from requester pays buckets can be found
148148
// at http://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html
149-
RequestPayer *string `location:"header" locationName:"x-amz-request-payer" type:"string"`
149+
RequestPayer s3.RequestPayer `location:"header" locationName:"x-amz-request-payer" type:"string"`
150150

151151
// Specifies the algorithm to use to when encrypting the object (e.g., AES256,
152152
// aws:kms).
@@ -175,7 +175,7 @@ type UploadInput struct {
175175
ServerSideEncryption s3.ServerSideEncryption `location:"header" locationName:"x-amz-server-side-encryption" type:"string"`
176176

177177
// The type of storage to use for the object. Defaults to 'STANDARD'.
178-
StorageClass *string `location:"header" locationName:"x-amz-storage-class" type:"string"`
178+
StorageClass s3.StorageClass `location:"header" locationName:"x-amz-storage-class" type:"string"`
179179

180180
// The tag-set for the object. The tag-set must be encoded as URL Query parameters
181181
Tagging *string `location:"header" locationName:"x-amz-tagging" type:"string"`

service/s3/s3manager/upload_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
var emptyList = []string{}
2828

2929
func val(i interface{}, s string) interface{} {
30-
fmt.Println("INNER", i)
3130
v, err := awsutil.ValuesAtPath(i, s)
3231
if err != nil || len(v) == 0 {
3332
return nil
@@ -772,7 +771,10 @@ func TestUploadInputS3PutObjectInputPairity(t *testing.T) {
772771
bOnly := []string{}
773772

774773
for k, c := range matchings {
775-
if c == 1 && k != "ContentLength" {
774+
if strings.HasPrefix(k, "Body-") || strings.HasPrefix(k, "ContentLength-") {
775+
continue
776+
}
777+
if c == 1 {
776778
aOnly = append(aOnly, k)
777779
} else if c == 2 {
778780
bOnly = append(bOnly, k)
@@ -850,18 +852,24 @@ func compareStructType(a, b reflect.Type) map[string]int {
850852

851853
for i := 0; i < len(aFields) || i < len(bFields); i++ {
852854
if i < len(aFields) {
853-
c := matchings[aFields[i].Name]
854-
matchings[aFields[i].Name] = c + 1
855+
name := matchName(aFields[i])
856+
c := matchings[name]
857+
matchings[name] = c + 1
855858
}
856859
if i < len(bFields) {
857-
c := matchings[bFields[i].Name]
858-
matchings[bFields[i].Name] = c + 2
860+
name := matchName(bFields[i])
861+
c := matchings[name]
862+
matchings[name] = c + 2
859863
}
860864
}
861865

862866
return matchings
863867
}
864868

869+
func matchName(field reflect.StructField) string {
870+
return field.Name + "-" + field.Type.String()
871+
}
872+
865873
func enumFields(v reflect.Type) []reflect.StructField {
866874
fields := []reflect.StructField{}
867875

0 commit comments

Comments
 (0)