diff --git a/pkg/cloud/data/artifact/scraper_integration_test.go b/pkg/cloud/data/artifact/scraper_integration_test.go index 8c132aaddef..673200c8d47 100644 --- a/pkg/cloud/data/artifact/scraper_integration_test.go +++ b/pkg/cloud/data/artifact/scraper_integration_test.go @@ -67,6 +67,7 @@ func TestCloudScraper_ArchiveFilesystemExtractor_Integration(t *testing.T) { ExecutionID: "my-execution-id", TestName: "my-test", TestSuiteName: "my-test-suite", + ContentType: "application/gzip", } mockExecutor. EXPECT(). @@ -77,6 +78,7 @@ func TestCloudScraper_ArchiveFilesystemExtractor_Integration(t *testing.T) { ExecutionID: "my-execution-id", TestName: "my-test", TestSuiteName: "my-test-suite", + ContentType: "text/plain", } mockExecutor. EXPECT(). @@ -154,6 +156,7 @@ func TestCloudScraper_RecursiveFilesystemExtractor_Integration(t *testing.T) { ExecutionID: "my-execution-id", TestName: "my-test", TestSuiteName: "my-test-suite", + ContentType: "text/plain", } mockExecutor. EXPECT(). @@ -165,6 +168,7 @@ func TestCloudScraper_RecursiveFilesystemExtractor_Integration(t *testing.T) { ExecutionID: "my-execution-id", TestName: "my-test", TestSuiteName: "my-test-suite", + ContentType: "text/plain", } mockExecutor. EXPECT(). @@ -176,6 +180,7 @@ func TestCloudScraper_RecursiveFilesystemExtractor_Integration(t *testing.T) { ExecutionID: "my-execution-id", TestName: "my-test", TestSuiteName: "my-test-suite", + ContentType: "text/plain", } mockExecutor. EXPECT(). diff --git a/pkg/cloud/data/artifact/uploader.go b/pkg/cloud/data/artifact/uploader.go index d6df1571612..ddeae1bf5d2 100644 --- a/pkg/cloud/data/artifact/uploader.go +++ b/pkg/cloud/data/artifact/uploader.go @@ -4,7 +4,6 @@ import ( "context" "crypto/tls" "encoding/json" - "io" "net/http" "path/filepath" @@ -33,18 +32,21 @@ func NewCloudUploader(executor executor.Executor, skipVerify bool) *CloudUploade func (u *CloudUploader) Upload(ctx context.Context, object *scraper.Object, execution testkube.Execution) error { log.DefaultLogger.Debugw("cloud uploader is requesting signed URL", "file", object.Name, "folder", execution.Id, "size", object.Size) + + contentType := getContentType(object.Name) req := &PutObjectSignedURLRequest{ Object: object.Name, ExecutionID: execution.Id, TestName: execution.TestName, TestSuiteName: execution.TestSuiteName, + ContentType: contentType, } signedURL, err := u.getSignedURL(ctx, req) if err != nil { return errors.Wrapf(err, "failed to get signed URL for object [%s]", req.Object) } - if err := u.putObject(ctx, signedURL, object.Data); err != nil { + if err := u.putObject(ctx, signedURL, object, contentType); err != nil { return errors.Wrapf(err, "failed to send object [%s] to cloud", req.Object) } @@ -65,13 +67,13 @@ func (u *CloudUploader) getSignedURL(ctx context.Context, req *PutObjectSignedUR return commandResponse.URL, nil } -func (u *CloudUploader) putObject(ctx context.Context, url string, data io.Reader) error { - req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, data) +func (u *CloudUploader) putObject(ctx context.Context, url string, object *scraper.Object, contentType string) error { + req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, object.Data) if err != nil { return err } - req.Header.Set("Content-Type", "application/octet-stream") + req.Header.Set("Content-Type", contentType) tr := http.DefaultTransport.(*http.Transport).Clone() tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: u.skipVerify} client := &http.Client{Transport: tr} diff --git a/pkg/cloud/data/artifact/uploader_test.go b/pkg/cloud/data/artifact/uploader_test.go index 2a78448920d..852edd9f6be 100644 --- a/pkg/cloud/data/artifact/uploader_test.go +++ b/pkg/cloud/data/artifact/uploader_test.go @@ -57,6 +57,7 @@ func TestCloudLoader_Load(t *testing.T) { ExecutionID: "my-execution-id", TestName: "my-test", TestSuiteName: "my-test-suite", + ContentType: "text/plain", } mockExecutor.EXPECT().Execute(gomock.Any(), cloudscraper.CmdScraperPutObjectSignedURL, gomock.Eq(req)).Return([]byte(`{"URL":"`+testServer.URL+`/dummy"}`), nil).Times(1) @@ -79,6 +80,7 @@ func TestCloudLoader_Load(t *testing.T) { ExecutionID: "my-execution-id", TestName: "my-test", TestSuiteName: "my-test-suite", + ContentType: "text/plain", } mockExecutor.EXPECT().Execute(gomock.Any(), cloudscraper.CmdScraperPutObjectSignedURL, gomock.Eq(req)).Return(nil, errors.New("connection error")).Times(1)