github.com/sandwich-go/boost@v1.3.29/xcompress/compress_test.go (about)

     1  package xcompress
     2  
     3  import (
     4  	. "github.com/smartystreets/goconvey/convey"
     5  	"testing"
     6  )
     7  
     8  func TestCompress(t *testing.T) {
     9  	Convey("init compressor", t, func() {
    10  		c, err := New(WithLevel(BestCompression + 1))
    11  		So(err, ShouldNotBeNil)
    12  		So(c, ShouldBeNil)
    13  
    14  		c, err = New(WithLevel(HuffmanOnly - 1))
    15  		So(err, ShouldNotBeNil)
    16  		So(c, ShouldBeNil)
    17  
    18  		c, err = New(WithLevel(HuffmanOnly))
    19  		So(err, ShouldBeNil)
    20  		So(c, ShouldNotBeNil)
    21  
    22  		c, err = New(WithType(GZIP))
    23  		So(err, ShouldBeNil)
    24  		So(c, ShouldNotBeNil)
    25  
    26  		c, err = New(WithType(Snappy))
    27  		So(err, ShouldBeNil)
    28  		So(c, ShouldNotBeNil)
    29  
    30  		c, err = New(WithType(Dummy))
    31  		So(err, ShouldBeNil)
    32  		So(c, ShouldNotBeNil)
    33  	})
    34  
    35  	Convey("flat/inflate", t, func() {
    36  		for _, frame := range getTestFrames() {
    37  			testFlatAndInflate(Default, frame)
    38  		}
    39  		for _, frame := range getTestFrames() {
    40  			for i := Dummy; i <= Snappy; i++ {
    41  				switch i {
    42  				case GZIP:
    43  					for lvl := HuffmanOnly; lvl <= BestCompression; lvl++ {
    44  						c, err := New(WithType(i), WithLevel(lvl))
    45  						So(err, ShouldBeNil)
    46  						So(c, ShouldNotBeNil)
    47  						testFlatAndInflate(c, frame)
    48  					}
    49  				default:
    50  					c, err := New(WithType(i))
    51  					So(err, ShouldBeNil)
    52  					So(c, ShouldNotBeNil)
    53  					testFlatAndInflate(c, frame)
    54  				}
    55  			}
    56  		}
    57  	})
    58  }