forked from aliyun/aliyun-log-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel_test.go
72 lines (67 loc) · 1.77 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
package sls
import (
"encoding/json"
"fmt"
"testing"
"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()")
})
}
}