github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/middle/packer/packet_test.go (about) 1 package packer 2 3 import "testing" 4 5 func TestGzip(t *testing.T) { 6 gz := &Gzip{} 7 bigBytes := make([]byte, 1<<20) 8 initStr := "hello world" 9 for i := 0; i < len(bigBytes); i += len(initStr) { 10 copy(bigBytes[i:], initStr) 11 } 12 bytes, err := gz.EnPacket(bigBytes) 13 if err != nil { 14 t.Fatal(err) 15 } 16 bytes, err = gz.UnPacket(bytes) 17 if err != nil { 18 t.Fatal(err) 19 } 20 } 21 22 func TestText(t *testing.T) { 23 text := &Text{} 24 bigBytes := make([]byte, 1<<20) 25 initStr := "hello world" 26 for i := 0; i < len(bigBytes); i += len(initStr) { 27 copy(bigBytes[i:], initStr) 28 } 29 // text encoder并不允许真实的调用 30 defer func() { 31 err := recover() 32 if err == interface{}(nil) { 33 t.Fatal("text encoder call no panic") 34 } 35 }() 36 bytes, _ := text.EnPacket(bigBytes) 37 bytes, _ = text.UnPacket(bytes) 38 }