github.com/pingcap/badger@v1.5.1-0.20230103063557-828f39b09b6d/options/options_test.go (about)

     1  package options
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  )
     7  
     8  func TestCompressionType(t *testing.T) {
     9  	types := []CompressionType{None, Snappy, ZSTD}
    10  	data := make([]byte, 64)
    11  	for i := 0; i < len(data); i++ {
    12  		data[i] = byte(49)
    13  	}
    14  	for i := 0; i < len(types); i++ {
    15  		typ := types[i]
    16  		w := bytes.NewBuffer(nil)
    17  		err := typ.Compress(w, data)
    18  		if err != nil {
    19  			t.Errorf("Compress type:%d,error:%s", typ, err.Error())
    20  		}
    21  		v, err := typ.Decompress(w.Bytes())
    22  		if err != nil {
    23  			t.Errorf("Decompress type:%d,error:%s", typ, err.Error())
    24  		}
    25  		if string(data) != string(v) {
    26  			t.Errorf("Decompress src%s,decode%s", string(data), string(v))
    27  		}
    28  	}
    29  }