forked from heroku/log-shuttle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgzip_formatter_test.go
57 lines (48 loc) · 1.02 KB
/
gzip_formatter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package shuttle
import (
"bytes"
"compress/gzip"
"io"
"io/ioutil"
"net/http"
"strings"
"testing"
)
type fakeFormatter struct {
r io.Reader
}
func (f *fakeFormatter) MsgCount() int {
return 1
}
func (f *fakeFormatter) Request() (*http.Request, error) {
return http.NewRequest("POST", "http://localhost/", f.r)
}
func (f *fakeFormatter) Read(p []byte) (int, error) {
return f.r.Read(p)
}
func TestGzipFormatter(t *testing.T) {
testString := "Hi there!"
f := &fakeFormatter{strings.NewReader(testString)}
gr := NewGzipFormatter(f)
if gr.MsgCount() != 1 {
t.Fatal(gr.MsgCount())
}
// read the compressed bytes
compressed, err := ioutil.ReadAll(gr)
if err != nil {
t.Fatal(err)
}
// decompress the bytes and verify the message
gunzipper, err := gzip.NewReader(bytes.NewReader(compressed))
if err != nil {
t.Fatal(err)
}
// read the uncompressed bytes
uncompressed, err := ioutil.ReadAll(gunzipper)
if err != nil {
t.Fatal(err)
}
if string(uncompressed) != testString {
t.Fatal(string(uncompressed))
}
}