1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/sdk/go/arvadostest"
14 "github.com/aws/aws-sdk-go-v2/aws"
15 "github.com/aws/aws-sdk-go-v2/config"
16 "github.com/aws/aws-sdk-go-v2/credentials"
17 "github.com/aws/aws-sdk-go-v2/service/s3"
18 check "gopkg.in/check.v1"
21 func (s *IntegrationSuite) TestS3AWSSDK(c *check.C) {
23 defer stage.teardown(c)
25 cfg, err := config.LoadDefaultConfig(context.TODO(),
26 func(o *config.LoadOptions) error {
27 o.Credentials = credentials.StaticCredentialsProvider{
28 Value: aws.Credentials{
29 AccessKeyID: arvadostest.ActiveTokenUUID,
30 SecretAccessKey: arvadostest.ActiveToken,
31 Source: "test suite configuration",
34 o.EndpointResolverWithOptions = aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
37 URL: s.testServer.URL,
38 HostnameImmutable: true,
39 SigningRegion: "test-region",
40 Source: aws.EndpointSourceCustom,
44 return aws.Endpoint{}, &aws.EndpointNotFoundError{Err: errors.New("endpoint not overridden")}
48 c.Assert(err, check.IsNil)
49 client := s3.NewFromConfig(cfg, func(o *s3.Options) {
50 o.Region = "test-region"
53 resp, err := client.ListObjectsV2(context.Background(), &s3.ListObjectsV2Input{
54 Bucket: aws.String(arvadostest.FooCollection),
55 MaxKeys: aws.Int32(100),
56 Prefix: aws.String(""),
57 ContinuationToken: nil,
59 c.Assert(err, check.IsNil)
60 c.Check(resp.Contents, check.HasLen, 1)
61 for _, key := range resp.Contents {
62 c.Check(*key.Key, check.Equals, "foo")
65 p := make([]byte, 100000000)
69 _, err = client.PutObject(context.Background(), &s3.PutObjectInput{
70 Body: bytes.NewReader(p),
71 Bucket: aws.String(stage.collbucket.Name),
72 ContentType: aws.String("application/octet-stream"),
73 Key: aws.String("aaaa"),
75 c.Assert(err, check.IsNil)
77 getresp, err := client.GetObject(context.Background(), &s3.GetObjectInput{
78 Bucket: aws.String(stage.collbucket.Name),
79 Key: aws.String("aaaa"),
81 c.Assert(err, check.IsNil)
82 getdata, err := ioutil.ReadAll(getresp.Body)
83 c.Assert(err, check.IsNil)
84 c.Check(bytes.Equal(getdata, p), check.Equals, true)