Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/content-service/pkg/storage/s3_test.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package storage_test
6
7
import (
8
"context"
9
"testing"
10
11
"github.com/aws/aws-sdk-go-v2/aws"
12
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
13
"github.com/aws/aws-sdk-go-v2/service/s3"
14
"github.com/aws/aws-sdk-go-v2/service/s3/types"
15
"github.com/gitpod-io/gitpod/content-service/pkg/storage"
16
"github.com/gitpod-io/gitpod/content-service/pkg/storage/mock"
17
"github.com/golang/mock/gomock"
18
)
19
20
type mockedS3PresignedAccess struct {
21
storage.PresignedAccess
22
}
23
24
func (m mockedS3PresignedAccess) ForTestCreateObj(ctx context.Context, bucket, path, content string) error {
25
return nil
26
}
27
28
func (m mockedS3PresignedAccess) ForTestReset(ctx context.Context) error {
29
return nil
30
}
31
32
func TestS3PresignedHappyPath(t *testing.T) {
33
ctrl := gomock.NewController(t)
34
defer ctrl.Finish()
35
36
s3c := mock.NewMockS3Client(ctrl)
37
s3c.EXPECT().GetObjectAttributes(gomock.Any(), gomock.Any()).Return(&s3.GetObjectAttributesOutput{
38
ETag: aws.String("foobar"),
39
ObjectSize: aws.Int64(100),
40
}, nil).AnyTimes()
41
s3c.EXPECT().ListObjectsV2(gomock.Any(), gomock.Any()).Return(&s3.ListObjectsV2Output{
42
Contents: []types.Object{
43
{Size: aws.Int64(100)},
44
},
45
}, nil)
46
47
ps3c := mock.NewMockPresignedS3Client(ctrl)
48
ps3c.EXPECT().PresignGetObject(gomock.Any(), gomock.Any()).Return(&v4.PresignedHTTPRequest{
49
URL: "some value",
50
}, nil).AnyTimes()
51
ps3c.EXPECT().PresignPutObject(gomock.Any(), gomock.Any()).Return(&v4.PresignedHTTPRequest{
52
URL: "some value",
53
}, nil).AnyTimes()
54
55
dut := storage.NewPresignedS3Access(s3c, storage.S3Config{Bucket: "test-bucket"})
56
dut.PresignedFactory = func() storage.PresignedS3Client { return ps3c }
57
58
ps := mockedS3PresignedAccess{
59
PresignedAccess: dut,
60
}
61
62
SuiteTestPresignedAccess(t, ps)
63
}
64
65