Test compressed size
This commit is contained in:
parent
3f98aa33de
commit
51e536d31a
@ -1,6 +1,8 @@
|
|||||||
package drive
|
package drive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -41,6 +43,31 @@ type URLCacheIntegrationSuite struct {
|
|||||||
driveID string
|
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) {
|
func TestURLCacheIntegrationSuite(t *testing.T) {
|
||||||
suite.Run(t, &URLCacheIntegrationSuite{
|
suite.Run(t, &URLCacheIntegrationSuite{
|
||||||
Suite: tester.NewIntegrationSuite(
|
Suite: tester.NewIntegrationSuite(
|
||||||
@ -170,6 +197,12 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() {
|
|||||||
require.NotEmpty(t, props.downloadURL)
|
require.NotEmpty(t, props.downloadURL)
|
||||||
require.Equal(t, false, props.isDeleted)
|
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
|
// Validate download URL
|
||||||
c := graph.NewNoTimeoutHTTPWrapper(count.New())
|
c := graph.NewNoTimeoutHTTPWrapper(count.New())
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user