-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[s3] Fix a bug in CopyObject and improve Metadata handling
- Loading branch information
Showing
7 changed files
with
119 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
common --enable_bzlmod | ||
common --experimental_output_paths=strip | ||
|
||
common --test_output=errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package itest | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
) | ||
|
||
func TestCopyObject(t *testing.T) { | ||
ctx := context.Background() | ||
client, srv := makeClientServerPair() | ||
defer srv.Shutdown(ctx) | ||
|
||
key := "test-key" | ||
_, err := client.PutObject(ctx, &s3.PutObjectInput{ | ||
Bucket: &bucket, | ||
Key: &key, | ||
Body: strings.NewReader("hello"), | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, err = client.CopyObject(ctx, &s3.CopyObjectInput{ | ||
Bucket: &bucket, | ||
Key: &key, | ||
CopySource: aws.String("/" + bucket + "/" + key), | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package itest | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
) | ||
|
||
func TestGetObject_Metadata(t *testing.T) { | ||
// See https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.html | ||
ctx := context.Background() | ||
client, srv := makeClientServerPair() | ||
defer srv.Shutdown(ctx) | ||
|
||
key := "test-key" | ||
_, err := client.PutObject(ctx, &s3.PutObjectInput{ | ||
Bucket: &bucket, | ||
Key: &key, | ||
Body: strings.NewReader("hello"), | ||
Metadata: map[string]string{ | ||
"ascii": "AMAZONS3", | ||
"non-ascii": "ÄMÄZÕÑ S3", | ||
}, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
resp, err := client.GetObject(ctx, &s3.GetObjectInput{ | ||
Bucket: &bucket, | ||
Key: &key, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
got := resp.Metadata | ||
want := map[string]string{ | ||
"ascii": "AMAZONS3", | ||
// Encoding doesn't match exactly but maybe compatible enough? | ||
"non-ascii": "=?utf-8?b?w4RNw4Raw5XDkSBTMw==?=", | ||
// "non-ascii": "=?UTF-8?B?w4PChE3Dg8KEWsODwpXDg8KRIFMz?=", | ||
} | ||
|
||
if !reflect.DeepEqual(got, want) { | ||
t.Fatalf("Wanted %v, got %v", want, got) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters