@@ -19,6 +19,7 @@ package utils
1919
2020import (
2121 "compress/gzip"
22+ "compress/zlib"
2223 "testing"
2324
2425 v2 "github.com/apache/rocketmq-clients/golang/v5/protocol/v2"
@@ -111,6 +112,33 @@ func TestMatchMessageType(t *testing.T) {
111112 }
112113}
113114
115+ func TestAutoDecode (t * testing.T ) {
116+ _ , err := AutoDecode ([]byte {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 })
117+ if err != zlib .ErrHeader {
118+ t .Error ()
119+ }
120+ _ , err = AutoDecode ([]byte {0 })
121+ if err == nil {
122+ t .Error ()
123+ }
124+ // gzip
125+ bytes , err := AutoDecode ([]byte {31 , 139 , 8 , 0 , 0 , 0 , 0 , 0 , 0 , 255 , 42 , 202 , 79 , 206 , 78 , 45 , 201 , 45 , 212 , 77 , 206 , 201 , 76 , 205 , 43 , 209 , 77 , 207 , 7 , 0 , 0 , 0 , 255 , 255 , 1 , 0 , 0 , 255 , 255 , 97 , 36 , 132 , 114 , 18 , 0 , 0 , 0 })
126+ if err != nil {
127+ t .Error ()
128+ }
129+ if string (bytes ) != "rocketmq-client-go" {
130+ t .Error ()
131+ }
132+ // zlib
133+ bytes , err = AutoDecode ([]byte {120 , 156 , 42 , 202 , 79 , 206 , 78 , 45 , 201 , 45 , 212 , 77 , 206 , 201 , 76 , 205 , 43 , 209 , 77 , 207 , 7 , 4 , 0 , 0 , 255 , 255 , 68 , 223 , 7 , 22 })
134+ if err != nil {
135+ t .Error ()
136+ }
137+ if string (bytes ) != "rocketmq-client-go" {
138+ t .Error ()
139+ }
140+ }
141+
114142func TestGZIPDecode (t * testing.T ) {
115143 _ , err := GZIPDecode ([]byte {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 })
116144 if err != gzip .ErrHeader {
@@ -125,6 +153,20 @@ func TestGZIPDecode(t *testing.T) {
125153 }
126154}
127155
156+ func TestZlibDecode (t * testing.T ) {
157+ _ , err := ZlibDecode ([]byte {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 })
158+ if err != zlib .ErrHeader {
159+ t .Error ()
160+ }
161+ bytes , err := ZlibDecode ([]byte {120 , 156 , 42 , 202 , 79 , 206 , 78 , 45 , 201 , 45 , 212 , 77 , 206 , 201 , 76 , 205 , 43 , 209 , 77 , 207 , 7 , 4 , 0 , 0 , 255 , 255 , 68 , 223 , 7 , 22 })
162+ if err != nil {
163+ t .Error ()
164+ }
165+ if string (bytes ) != "rocketmq-client-go" {
166+ t .Error ()
167+ }
168+ }
169+
128170func TestSelectAnAddress (t * testing.T ) {
129171 if SelectAnAddress (nil ) != nil {
130172 t .Error ()
0 commit comments