...
1 package testing
2
3 import (
4 "bytes"
5 "compress/gzip"
6 "fmt"
7 "io"
8 )
9
10 func GzipCompareCompressBytes(expect []byte, actual io.Reader) error {
11 content, err := gzip.NewReader(actual)
12 if err != nil {
13 return fmt.Errorf("error while reading request")
14 }
15
16 var actualBytes bytes.Buffer
17 _, err = actualBytes.ReadFrom(content)
18 if err != nil {
19 return fmt.Errorf("error while unzipping request payload")
20 }
21
22 if e, a := expect, actualBytes.Bytes(); !bytes.Equal(e, a) {
23 return fmt.Errorf("expect unzipped content to be %s, got %s", e, a)
24 }
25
26 return nil
27 }
28
View as plain text