forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 114
/
model_test.go
107 lines (99 loc) · 2.63 KB
/
model_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
102
103
104
105
106
107
package sls
import (
"encoding/json"
"fmt"
"testing"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
)
func TestIndex_MarshalJSON(t *testing.T) {
type fields struct {
Keys map[string]IndexKey
Line *IndexLine
Ttl uint32
MaxTextLen uint32
LogReduce bool
LogReduceWhiteListDict []string
LogReduceBlackListDict []string
}
tests := []struct {
name string
fields fields
want []byte
}{
{
name: "keys and line",
fields: fields{
Keys: map[string]IndexKey{
"test1": {},
},
Line: &IndexLine{},
},
want: []byte(`{"keys":{"test1":{"token":null,"caseSensitive":false,"type":"","chn":false}},"line":{"token":null,"caseSensitive":false,"chn":false},"log_reduce":false}`),
},
{
name: "only ttl",
fields: fields{
Ttl: 2,
MaxTextLen: 3,
},
want: []byte(`{"ttl":2,"max_text_len":3,"log_reduce":false}`),
},
{
name: "white & black",
fields: fields{
LogReduceWhiteListDict: []string{"key1"},
LogReduceBlackListDict: []string{"key2"},
LogReduce: true,
},
want: []byte(`{"log_reduce":true,"log_reduce_white_list":["key1"],"log_reduce_black_list":["key2"]}`),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
u := &Index{
Keys: tt.fields.Keys,
Line: tt.fields.Line,
Ttl: tt.fields.Ttl,
MaxTextLen: tt.fields.MaxTextLen,
LogReduce: tt.fields.LogReduce,
LogReduceWhiteListDict: tt.fields.LogReduceWhiteListDict,
LogReduceBlackListDict: tt.fields.LogReduceBlackListDict,
}
got, _ := json.Marshal(u)
fmt.Printf("%s", got)
assert.Equalf(t, tt.want, got, "MarshalJSON()")
})
}
}
func TestLogGroupIdentity(t *testing.T) {
sampleLog := &Log{
Time: proto.Uint32(1732774880),
Contents: []*LogContent{
{
Key: proto.String("test"),
Value: proto.String("test"),
},
},
}
logGroupList := &LogGroupList{
LogGroups: []*LogGroup{
{
Logs: []*Log{sampleLog},
},
{
Logs: []*Log{sampleLog, sampleLog},
},
{
Logs: []*Log{sampleLog, sampleLog, sampleLog},
},
},
}
err := logGroupList.addCursorIfPossible("1729070618428044655")
assert.NoError(t, err)
assert.Equal(t, "MTcyOTA3MDYxODQyODA0NDY1NQ==", logGroupList.LogGroups[2].GetCursor())
assert.Equal(t, "MTcyOTA3MDYxODQyODA0NDY1NA==", logGroupList.LogGroups[1].GetCursor())
assert.Equal(t, "MTcyOTA3MDYxODQyODA0NDY1Mw==", logGroupList.LogGroups[0].GetCursor())
empty := &LogGroup{}
assert.Equal(t, empty.GetCursor(), "")
}