From 51e536d31a84449713f8fec28d81020f0dd4a5ab Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Tue, 5 Dec 2023 16:17:36 -0800 Subject: [PATCH] Test compressed size --- .../m365/collection/drive/url_cache_test.go | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/internal/m365/collection/drive/url_cache_test.go b/src/internal/m365/collection/drive/url_cache_test.go index 90c8d129a..2d6368ea6 100644 --- a/src/internal/m365/collection/drive/url_cache_test.go +++ b/src/internal/m365/collection/drive/url_cache_test.go @@ -1,6 +1,8 @@ package drive import ( + "bytes" + "compress/gzip" "errors" "fmt" "io" @@ -41,6 +43,31 @@ type URLCacheIntegrationSuite struct { driveID string } +func CompressWithGZIP(input []byte) (bytes.Buffer, error) { + var encoder *gzip.Writer + var err error + var tmpBuffer bytes.Buffer + + encoder, err = gzip.NewWriterLevel( + &tmpBuffer, + gzip.BestCompression) + + if err != nil { + return tmpBuffer, err + } + + _, err = encoder.Write(input) + if err != nil { + return tmpBuffer, err + } + + if err := encoder.Close(); err != nil { + return tmpBuffer, err + } + + return tmpBuffer, nil +} + func TestURLCacheIntegrationSuite(t *testing.T) { suite.Run(t, &URLCacheIntegrationSuite{ Suite: tester.NewIntegrationSuite( @@ -170,6 +197,12 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() { require.NotEmpty(t, props.downloadURL) require.Equal(t, false, props.isDeleted) + compressed, err := CompressWithGZIP([]byte(props.downloadURL)) + require.NoError(t, err, clues.ToCore(err)) + + newDownloadUrl := compressed.String() + + fmt.Printf("download url size, orig %d compressed %d\n", len(props.downloadURL), len(newDownloadUrl)) // Validate download URL c := graph.NewNoTimeoutHTTPWrapper(count.New())