| 255 | } |
| 256 | |
| 257 | func (s) TestEncode(t *testing.T) { |
| 258 | for _, test := range []struct { |
| 259 | // input |
| 260 | msg proto.Message |
| 261 | // outputs |
| 262 | hdr []byte |
| 263 | data []byte |
| 264 | err error |
| 265 | }{ |
| 266 | {nil, []byte{0, 0, 0, 0, 0}, []byte{}, nil}, |
| 267 | } { |
| 268 | data, err := encode(getCodec(protoenc.Name), test.msg) |
| 269 | if err != test.err || !bytes.Equal(data.Materialize(), test.data) { |
| 270 | t.Errorf("encode(_, %v) = %v, %v; want %v, %v", test.msg, data, err, test.data, test.err) |
| 271 | continue |
| 272 | } |
| 273 | if hdr, _ := msgHeader(data, nil, compressionNone); !bytes.Equal(hdr, test.hdr) { |
| 274 | t.Errorf("msgHeader(%v, false) = %v; want %v", data, hdr, test.hdr) |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | func (s) TestCompress(t *testing.T) { |
| 280 | bestCompressor, err := NewGZIPCompressorWithLevel(gzip.BestCompression) |