github.com/vicanso/pike@v1.0.1-0.20210630235453-9099e041f6ec/compress/brotli_test.go (about)

     1  package compress
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestDoBrotli(t *testing.T) {
    10  	assert := assert.New(t)
    11  	// 压缩级别超出则与默认压缩级别一样
    12  	tests := []struct {
    13  		data       []byte
    14  		level      int
    15  		resultSize int
    16  	}{
    17  		{
    18  			data:       compressTestData,
    19  			level:      0,
    20  			resultSize: 589,
    21  		},
    22  		{
    23  			data:       compressTestData,
    24  			level:      12,
    25  			resultSize: 589,
    26  		},
    27  		{
    28  			data:       compressTestData,
    29  			level:      8,
    30  			resultSize: 592,
    31  		},
    32  	}
    33  	for _, tt := range tests {
    34  		data, err := doBrotli(tt.data, tt.level)
    35  		assert.Nil(err)
    36  		assert.Equal(tt.resultSize, len(data))
    37  		assert.NotEqual(tt.data, data)
    38  	}
    39  }
    40  
    41  func TestDoBrotliDecode(t *testing.T) {
    42  	assert := assert.New(t)
    43  	tests := []struct {
    44  		data []byte
    45  	}{
    46  		{
    47  			data: compressTestData,
    48  		},
    49  	}
    50  	for _, tt := range tests {
    51  		data, err := doBrotli(tt.data, 0)
    52  		assert.Nil(err)
    53  		assert.NotNil(data)
    54  		assert.NotEqual(tt.data, data)
    55  		data, err = doBrotliDecode(data)
    56  		assert.Nil(err)
    57  		assert.Equal(tt.data, data)
    58  	}
    59  }