Path: blob/main/components/content-service/pkg/storage/s3_test.go
2501 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package storage_test56import (7"context"8"testing"910"github.com/aws/aws-sdk-go-v2/aws"11v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"12"github.com/aws/aws-sdk-go-v2/service/s3"13"github.com/aws/aws-sdk-go-v2/service/s3/types"14"github.com/gitpod-io/gitpod/content-service/pkg/storage"15"github.com/gitpod-io/gitpod/content-service/pkg/storage/mock"16"github.com/golang/mock/gomock"17)1819type mockedS3PresignedAccess struct {20storage.PresignedAccess21}2223func (m mockedS3PresignedAccess) ForTestCreateObj(ctx context.Context, bucket, path, content string) error {24return nil25}2627func (m mockedS3PresignedAccess) ForTestReset(ctx context.Context) error {28return nil29}3031func TestS3PresignedHappyPath(t *testing.T) {32ctrl := gomock.NewController(t)33defer ctrl.Finish()3435s3c := mock.NewMockS3Client(ctrl)36s3c.EXPECT().GetObjectAttributes(gomock.Any(), gomock.Any()).Return(&s3.GetObjectAttributesOutput{37ETag: aws.String("foobar"),38ObjectSize: aws.Int64(100),39}, nil).AnyTimes()40s3c.EXPECT().ListObjectsV2(gomock.Any(), gomock.Any()).Return(&s3.ListObjectsV2Output{41Contents: []types.Object{42{Size: aws.Int64(100)},43},44}, nil)4546ps3c := mock.NewMockPresignedS3Client(ctrl)47ps3c.EXPECT().PresignGetObject(gomock.Any(), gomock.Any()).Return(&v4.PresignedHTTPRequest{48URL: "some value",49}, nil).AnyTimes()50ps3c.EXPECT().PresignPutObject(gomock.Any(), gomock.Any()).Return(&v4.PresignedHTTPRequest{51URL: "some value",52}, nil).AnyTimes()5354dut := storage.NewPresignedS3Access(s3c, storage.S3Config{Bucket: "test-bucket"})55dut.PresignedFactory = func() storage.PresignedS3Client { return ps3c }5657ps := mockedS3PresignedAccess{58PresignedAccess: dut,59}6061SuiteTestPresignedAccess(t, ps)62}636465