-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconf_test.go
More file actions
254 lines (243 loc) · 6.32 KB
/
Copy pathconf_test.go
File metadata and controls
254 lines (243 loc) · 6.32 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package sts
import (
"encoding/json"
"strings"
"testing"
"github.com/davecgh/go-spew/spew"
yaml "gopkg.in/yaml.v2"
)
func TestJSON(t *testing.T) {
confEncoded := `
{
"OUT": {
"dirs": {
"cache": ".sts/out",
"logs": "data/log",
"out": "data/out",
"out-follow": true
},
"sources": [
{
"name": "stsout-1",
"threads": 4,
"scan-delay": "10s",
"cache-age": "5m",
"min-age": "5s",
"max-age": "0s",
"bin-size": "20MB",
"compress": 0,
"stat-payload": "true",
"poll-delay": "2s",
"poll-interval": "5s",
"poll-attempts": 1,
"target": {
"name": "aname",
"key": "akey",
"http-host": "host:port",
"http-tls-cert-encoded": "blahblahblah"
},
"tags": [
{
"pattern": "DEFAULT",
"delete": "true"
}
]
}
]
}
}
`
var conf Conf
if err := json.Unmarshal([]byte(confEncoded), &conf); err != nil {
t.Fatal(err)
}
// spew.Dump(conf)
}
func TestYAML(t *testing.T) {
confEncoded := `
IN:
sources:
- stsout-1
- stsout-2
keys:
- 'testing123'
dirs:
stage : data/stage
final : data/in
logs : data/log
server:
http-host : localhost
http-port : 1992
http-tls-cert : ../../sts.server.crt
http-tls-key : ../../sts.server.key
compress : 4
OUT:
dirs:
cache : .sts/out
logs : data/log
out : data/out
out-follow : true
sources:
- name : stsout-1
threads : 3
scan-delay : 5s
min-age : 0s
max-age : 0s
timeout : 5m
bin-size : 20MB
compress : 0
stat-payload : true
poll-delay : 2s
poll-interval : 5s
poll-attempts : 1
target:
name : stsin-1
key : 'testing123'
http-host : localhost:1992
http-tls-cert : ../../sts.server.crt
tags:
- pattern : DEFAULT
priority : 0
order : fifo
delete : true
method : http
- pattern : ^info/
priority : 3
- pattern : ^comlogs/
priority : 2
- pattern : ^collection/
priority : 1
rename:
- from: '/(?P<prefix>[^/]+)\.(?P<YMD>\d{8})\.(?P<HMS>\d{6})\.(?P<rest>[^/]+)$'
to: '{{.prefix}}/{{.YMD}}-{{.HMS}}.{{.rest}}'
- name: stsout-2
target:
name: stsin-2
`
var conf Conf
encoded := strings.Trim(
strings.ReplaceAll(confEncoded, "\t", " "),
"\n ",
)
if err := yaml.Unmarshal([]byte(encoded), &conf); err != nil {
t.Fatal(err)
}
if conf.Client.Dirs == nil {
t.Fatal(spew.Sdump(conf))
}
if len(conf.Client.Sources) != 2 {
t.Fatal(spew.Sdump(conf))
}
// spew.Dump(conf)
}
func TestYAMLQUICWindowFriendlySizes(t *testing.T) {
confEncoded := `
IN:
dirs:
stage : data/stage
final : data/in
logs : data/log
server:
http-host: localhost
http-port: 1992
quic-max-stream-receive-window: 64MB
quic-max-connection-receive-window: 268435456
OUT:
dirs:
cache: .sts/out
logs: data/log
out: data/out
sources:
- name: stsout-1
target:
http-host: localhost:1992
quic-max-stream-receive-window: 33554432
quic-max-connection-receive-window: 128MB
`
var conf Conf
encoded := strings.Trim(
strings.ReplaceAll(confEncoded, "\t", " "),
"\n ",
)
if err := yaml.Unmarshal([]byte(encoded), &conf); err != nil {
t.Fatal(err)
}
if conf.Server == nil || conf.Server.Server == nil {
t.Fatal("missing server config")
}
if conf.Server.Server.QUICMaxStreamReceiveWindow != 64*1024*1024 {
t.Fatalf("unexpected server stream window: %d", conf.Server.Server.QUICMaxStreamReceiveWindow)
}
if conf.Server.Server.QUICMaxConnectionReceiveWindow != 256*1024*1024 {
t.Fatalf("unexpected server connection window: %d", conf.Server.Server.QUICMaxConnectionReceiveWindow)
}
if conf.Client == nil || len(conf.Client.Sources) != 1 || conf.Client.Sources[0].Target == nil {
t.Fatal("missing target config")
}
target := conf.Client.Sources[0].Target
if target.QUICMaxStreamReceiveWindow != 32*1024*1024 {
t.Fatalf("unexpected target stream window: %d", target.QUICMaxStreamReceiveWindow)
}
if target.QUICMaxConnectionReceiveWindow != 128*1024*1024 {
t.Fatalf("unexpected target connection window: %d", target.QUICMaxConnectionReceiveWindow)
}
}
func TestJSONQUICWindowFriendlySizes(t *testing.T) {
confEncoded := `
{
"IN": {
"dirs": {
"stage": "data/stage",
"final": "data/in",
"logs": "data/log"
},
"server": {
"http-host": "localhost",
"http-port": 1992,
"quic-max-stream-receive-window": "64MB",
"quic-max-connection-receive-window": 268435456
}
},
"OUT": {
"dirs": {
"cache": ".sts/out",
"logs": "data/log",
"out": "data/out"
},
"sources": [
{
"name": "stsout-1",
"target": {
"http-host": "localhost:1992",
"quic-max-stream-receive-window": 33554432,
"quic-max-connection-receive-window": "128MB"
}
}
]
}
}
`
var conf Conf
if err := json.Unmarshal([]byte(confEncoded), &conf); err != nil {
t.Fatal(err)
}
if conf.Server == nil || conf.Server.Server == nil {
t.Fatal("missing server config")
}
if conf.Server.Server.QUICMaxStreamReceiveWindow != 64*1024*1024 {
t.Fatalf("unexpected server stream window: %d", conf.Server.Server.QUICMaxStreamReceiveWindow)
}
if conf.Server.Server.QUICMaxConnectionReceiveWindow != 256*1024*1024 {
t.Fatalf("unexpected server connection window: %d", conf.Server.Server.QUICMaxConnectionReceiveWindow)
}
if conf.Client == nil || len(conf.Client.Sources) != 1 || conf.Client.Sources[0].Target == nil {
t.Fatal("missing target config")
}
target := conf.Client.Sources[0].Target
if target.QUICMaxStreamReceiveWindow != 32*1024*1024 {
t.Fatalf("unexpected target stream window: %d", target.QUICMaxStreamReceiveWindow)
}
if target.QUICMaxConnectionReceiveWindow != 128*1024*1024 {
t.Fatalf("unexpected target connection window: %d", target.QUICMaxConnectionReceiveWindow)
}
}