github.com/simonmittag/ws@v1.1.0-rc.5.0.20210419231947-82b846128245/wsflate/helper_test.go (about)

     1  package wsflate
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/simonmittag/ws"
     8  )
     9  
    10  func TestHelperWriteAndRead(t *testing.T) {
    11  	const text = "hello, wsflate!"
    12  	f := ws.NewTextFrame([]byte(text))
    13  	c, err := CompressFrame(f)
    14  	if err != nil {
    15  		t.Fatalf("can't compress frame: %v", err)
    16  	}
    17  	d, err := DecompressFrame(c)
    18  	if err != nil {
    19  		t.Fatalf("can't decompress frame: %v", err)
    20  	}
    21  	if f.Header != d.Header {
    22  		t.Fatalf("original and decompressed headers are not equal")
    23  	}
    24  	if !bytes.Equal(f.Payload, d.Payload) {
    25  		t.Fatalf("original and decompressed payload are not equal")
    26  	}
    27  }