|
| 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 service |
| 6 | + |
| 7 | +import ( |
| 8 | + "context" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/gitpod-io/gitpod/content-service/api" |
| 12 | + "github.com/gitpod-io/gitpod/content-service/api/config" |
| 13 | + "github.com/gitpod-io/gitpod/content-service/pkg/storage" |
| 14 | + storagemock "github.com/gitpod-io/gitpod/content-service/pkg/storage/mock" |
| 15 | + "github.com/golang/mock/gomock" |
| 16 | + "github.com/stretchr/testify/require" |
| 17 | +) |
| 18 | + |
| 19 | +// TestUploadURL tests that usageReportService.UploadURL interacts with PresignedAccess |
| 20 | +// correctly to produce an upload URL for the correct bucket and filename. |
| 21 | +func TestUploadURL(t *testing.T) { |
| 22 | + ctrl := gomock.NewController(t) |
| 23 | + s := storagemock.NewMockPresignedAccess(ctrl) |
| 24 | + const fileName = "some-report-filename" |
| 25 | + |
| 26 | + s.EXPECT().EnsureExists(gomock.Any(), usageReportBucketName). |
| 27 | + Return(nil) |
| 28 | + s.EXPECT().SignUpload(gomock.Any(), usageReportBucketName, fileName, gomock.Any()). |
| 29 | + Return(&storage.UploadInfo{URL: "http://example.com/some-path"}, nil) |
| 30 | + |
| 31 | + svc := &UsageReportService{cfg: config.StorageConfig{}, s: s} |
| 32 | + resp, err := svc.UploadURL(context.Background(), &api.UsageReportUploadURLRequest{Name: fileName}) |
| 33 | + |
| 34 | + require.NoError(t, err) |
| 35 | + require.Equal(t, "http://example.com/some-path", resp.Url) |
| 36 | +} |
0 commit comments