(t *testing.T)
| 277 | } |
| 278 | |
| 279 | func (s) TestCompress(t *testing.T) { |
| 280 | bestCompressor, err := NewGZIPCompressorWithLevel(gzip.BestCompression) |
| 281 | if err != nil { |
| 282 | t.Fatalf("Could not initialize gzip compressor with best compression.") |
| 283 | } |
| 284 | bestSpeedCompressor, err := NewGZIPCompressorWithLevel(gzip.BestSpeed) |
| 285 | if err != nil { |
| 286 | t.Fatalf("Could not initialize gzip compressor with best speed compression.") |
| 287 | } |
| 288 | |
| 289 | defaultCompressor, err := NewGZIPCompressorWithLevel(gzip.BestSpeed) |
| 290 | if err != nil { |
| 291 | t.Fatalf("Could not initialize gzip compressor with default compression.") |
| 292 | } |
| 293 | |
| 294 | level5, err := NewGZIPCompressorWithLevel(5) |
| 295 | if err != nil { |
| 296 | t.Fatalf("Could not initialize gzip compressor with level 5 compression.") |
| 297 | } |
| 298 | |
| 299 | for _, test := range []struct { |
| 300 | // input |
| 301 | data []byte |
| 302 | cp Compressor |
| 303 | dc Decompressor |
| 304 | // outputs |
| 305 | err error |
| 306 | }{ |
| 307 | {make([]byte, 1024), NewGZIPCompressor(), NewGZIPDecompressor(), nil}, |
| 308 | {make([]byte, 1024), bestCompressor, NewGZIPDecompressor(), nil}, |
| 309 | {make([]byte, 1024), bestSpeedCompressor, NewGZIPDecompressor(), nil}, |
| 310 | {make([]byte, 1024), defaultCompressor, NewGZIPDecompressor(), nil}, |
| 311 | {make([]byte, 1024), level5, NewGZIPDecompressor(), nil}, |
| 312 | } { |
| 313 | b := new(bytes.Buffer) |
| 314 | if err := test.cp.Do(b, test.data); err != test.err { |
| 315 | t.Fatalf("Compressor.Do(_, %v) = %v, want %v", test.data, err, test.err) |
| 316 | } |
| 317 | if b.Len() >= len(test.data) { |
| 318 | t.Fatalf("The compressor fails to compress data.") |
| 319 | } |
| 320 | if p, err := test.dc.Do(b); err != nil || !bytes.Equal(test.data, p) { |
| 321 | t.Fatalf("Decompressor.Do(%v) = %v, %v, want %v, <nil>", b, p, err, test.data) |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | func (s) TestToRPCErr(t *testing.T) { |
| 327 | for _, test := range []struct { |
nothing calls this directly
no test coverage detected