-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinesis_formatter_test.go
67 lines (56 loc) · 1.51 KB
/
kinesis_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
58
59
60
61
62
63
64
65
66
67
package shuttle
import (
"compress/gzip"
"io/ioutil"
"testing"
)
func TestKinesisFormatter(t *testing.T) {
config := newTestConfig()
config.LogsURL = "https://key:secret@foo/Stream"
b := NewBatch(1)
b.Add(LogLineOne)
b.Add(LogLineTwo)
br := NewKinesisFormatter(b, noErrData, &config)
d, err := ioutil.ReadAll(br)
if err != nil {
t.Fatalf("Error reading everything from batch: %q", err)
}
t.Logf("%q", string(d))
}
func TestKinesisFormatterRequest(t *testing.T) {
config := newTestConfig()
config.LogsURL = "https://key:secret@kinesis.us-east-1.amazonaws.com/Stream"
b := NewBatch(1)
b.Add(LogLineOne)
b.Add(LogLineTwo)
kf := NewKinesisFormatter(b, noErrData, &config)
r, err := kf.Request()
if err != nil {
t.Fatal("Unexpected error calling Request: ", err)
}
// Read the body of the request
d, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatalf("Error reading everything from the request: %q", err)
}
t.Logf("%q", string(d))
}
func TestKinesisGzip(t *testing.T) {
config := newTestConfig()
config.LogsURL = "https://key:secret@foo/Stream"
b := NewBatch(1)
b.Add(LogLineOne)
kf := NewKinesisFormatter(b, noErrData, &config)
gf := NewGzipFormatter(kf)
// decompress the bytes and verify the message
gunzipper, err := gzip.NewReader(gf)
if err != nil {
t.Fatal("Error making a reader: ", err)
}
// read the uncompressed bytes
uncompressed, err := ioutil.ReadAll(gunzipper)
if err != nil {
t.Fatal("Errors reading the compressed bytes: ", err)
}
t.Log("Data: ", string(uncompressed))
}