-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathkinesis_types_test.go
101 lines (77 loc) · 2.2 KB
/
kinesis_types_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package shuttle
import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"
)
func TestKinesisRecord_MarshalJSONToWriter(t *testing.T) {
config := newTestConfig()
llf := NewLogplexLineFormatter(LogLineOne, &config)
b := new(bytes.Buffer)
r := KinesisRecord{llf: llf}
if _, err := r.WriteTo(b); err != nil {
t.Fatal("Unexpected error calling MarshalJSONToWriter: ", err)
}
tr := struct {
Data []byte
PartitionKey string
}{}
t.Logf("%+q\n", b.Bytes())
if err := json.Unmarshal(b.Bytes(), &tr); err != nil {
t.Fatal("Unexpected error unmashalling KinesisRecord: ", err)
}
t.Logf("%+q\n", tr)
if tr.PartitionKey == "" {
t.Fatal("Expected PartitonKey to not be empty, but was.")
}
llf.Reset()
d, _ := ioutil.ReadAll(llf)
if string(tr.Data) != string(d) {
t.Logf("tr.Data: %q\n, d: %q\n", string(tr.Data), string(d))
t.Fatal("Expected Data to be equal to reading all the formatted bytes of the log line, but wasn't.")
}
}
func TestKinesisRecordSharding(t *testing.T) {
config := newTestConfig()
config.KinesisShards = 2
llf := NewLogplexLineFormatter(LogLineOne, &config)
llf2 := NewLogplexLineFormatter(LogLineTwo, &config)
b := new(bytes.Buffer)
r := KinesisRecord{llf: llf, shard: 1}
r2 := KinesisRecord{llf: llf2, shard: 2}
_, err := r.WriteTo(b)
if err != nil {
t.Fatal("Unexpected error calling MarshalJSONToWriter: ", err)
}
tr := struct {
Data []byte
PartitionKey string
}{}
t.Logf("%+q\n", b.Bytes())
if err := json.Unmarshal(b.Bytes(), &tr); err != nil {
t.Fatal("Unexpected error unmashalling KinesisRecord: ", err)
}
t.Logf("%+q\n", tr)
expected := "shuttle1"
if tr.PartitionKey != expected {
t.Fatalf("Expected PartitonKey to be `%s`, but was `%s`.", expected, tr.PartitionKey)
}
b = new(bytes.Buffer)
_, err = r2.WriteTo(b)
if err != nil {
t.Fatal("Unexpected error calling MarshalJSONToWriter: ", err)
}
tr = struct {
Data []byte
PartitionKey string
}{}
t.Logf("%+q\n", b.Bytes())
if err := json.Unmarshal(b.Bytes(), &tr); err != nil {
t.Fatal("Unexpected error unmashalling KinesisRecord: ", err)
}
t.Logf("%+q\n", tr)
if tr.PartitionKey != "shuttle2" {
t.Fatal("Expected PartitonKey to not be empty, but was.")
}
}