github.com/zly-app/zapp@v1.3.3/pkg/compactor/gzip_test.go (about)

     1  package compactor
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestGzip(t *testing.T) {
    11  	r := bytes.NewBufferString(testData)
    12  	w := bytes.NewBuffer(nil)
    13  	c := NewGzipCompactor()
    14  	err := c.Compress(r, w)
    15  	require.Nil(t, err)
    16  	t.Log(len(testData), ">>", w.Len())
    17  
    18  	w2 := bytes.NewBuffer(nil)
    19  	err = c.UnCompress(w, w2)
    20  	require.Nil(t, err)
    21  	require.Equal(t, testData, w2.String())
    22  }
    23  
    24  func TestGzipBytes(t *testing.T) {
    25  	in := []byte(testData)
    26  	c := NewGzipCompactor()
    27  	temp, err := c.CompressBytes(in)
    28  	require.Nil(t, err)
    29  	t.Log(len(testData), ">>", len(temp))
    30  
    31  	in2, err := c.UnCompressBytes(temp)
    32  	require.Nil(t, err)
    33  	require.Equal(t, in, in2)
    34  }