fluent-plugin-http-pull 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/README.md +4 -0
- data/appveyor.yml +1 -1
- data/fluent-plugin-http-pull.gemspec +1 -1
- data/lib/fluent/plugin/in_http_pull.rb +5 -1
- data/test/plugin/test_in_http_pull.rb +4 -560
- data/test/plugin/test_in_http_pull_auth.rb +116 -0
- data/test/plugin/test_in_http_pull_basic.rb +227 -0
- data/test/plugin/test_in_http_pull_http_header.rb +126 -0
- data/test/plugin/test_in_http_pull_proxy.rb +119 -0
- data/test/plugin/test_in_http_pull_request_method.rb +79 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e3619cf826d85851de1718106ba6184f72f1bc2
|
4
|
+
data.tar.gz: 4ecc716ba91a880d13c7ce3ca021f678c8c20243
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cca5ffc95191262f47ceca1207477415f44f233ccec6f2b2befd7ed5104a93c6758df4ce970e107be2f99ec88d46b2f7196de9a94ea2549a1e2def87a41520bd
|
7
|
+
data.tar.gz: b60ee55a581523bc46564d6f63fc5c901f48f98e9d319fdf7fb19dd3dce0fb65a98062f780c12873cfca44f0b4399e1832ec0942645e4c1f139df84cdf843294
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -120,6 +120,10 @@ The tag of the event.
|
|
120
120
|
|
121
121
|
The url of remote server.
|
122
122
|
|
123
|
+
### agent (string) (optional, default: fluent-plugin-http-pull)
|
124
|
+
|
125
|
+
The user agent string of request.
|
126
|
+
|
123
127
|
### interval (time) (required)
|
124
128
|
|
125
129
|
The interval time between periodic request.
|
data/appveyor.yml
CHANGED
@@ -35,6 +35,9 @@ module Fluent
|
|
35
35
|
desc 'The interval time between periodic request'
|
36
36
|
config_param :interval, :time
|
37
37
|
|
38
|
+
desc 'The user agent string of request'
|
39
|
+
config_param :agent, :string, default: "fluent-plugin-http-pull"
|
40
|
+
|
38
41
|
desc 'status_only'
|
39
42
|
config_param :status_only, :bool, default: false
|
40
43
|
|
@@ -72,7 +75,8 @@ module Fluent
|
|
72
75
|
|
73
76
|
@parser = parser_create unless @status_only
|
74
77
|
@_request_headers = {
|
75
|
-
"Content-Type" => "application/x-www-form-urlencoded"
|
78
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
79
|
+
"User-Agent" => @agent
|
76
80
|
}.merge(@request_headers.map do |section|
|
77
81
|
header = section["header"]
|
78
82
|
value = section["value"]
|
@@ -3,18 +3,7 @@ require "fluent/plugin/in_http_pull.rb"
|
|
3
3
|
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
|
-
class
|
7
|
-
@stub_server = nil
|
8
|
-
|
9
|
-
setup do
|
10
|
-
@stub_server = StubServer.new
|
11
|
-
@stub_server.start
|
12
|
-
end
|
13
|
-
|
14
|
-
teardown do
|
15
|
-
@stub_server.shutdown
|
16
|
-
end
|
17
|
-
|
6
|
+
class HttpPullInputTestDefaultOptions < Test::Unit::TestCase
|
18
7
|
sub_test_case "default value of each options" do
|
19
8
|
TEST_DEFAULT_VALUE_CONFIG = %[
|
20
9
|
tag test
|
@@ -65,557 +54,12 @@ class HttpPullInputTest < Test::Unit::TestCase
|
|
65
54
|
|
66
55
|
assert_equal(:get, d.instance.http_method)
|
67
56
|
end
|
68
|
-
end
|
69
|
-
|
70
|
-
sub_test_case "success case" do
|
71
|
-
TEST_INTERVAL_3_CONFIG = %[
|
72
|
-
tag test
|
73
|
-
url http://127.0.0.1:3939
|
74
|
-
|
75
|
-
interval 3s
|
76
|
-
format none
|
77
|
-
status_only true
|
78
|
-
]
|
79
|
-
|
80
|
-
TEST_INTERVAL_5_CONFIG = %[
|
81
|
-
tag test
|
82
|
-
url http://127.0.0.1:3939
|
83
|
-
|
84
|
-
interval 5s
|
85
|
-
format json
|
86
|
-
]
|
87
|
-
|
88
|
-
TEST_INTERVAL_3_REDIRECT_CONFIG = %[
|
89
|
-
tag test
|
90
|
-
url http://127.0.0.1:3939/redirect
|
91
|
-
|
92
|
-
interval 3s
|
93
|
-
format json
|
94
|
-
]
|
95
|
-
|
96
|
-
test 'interval 3 with status_only' do
|
97
|
-
d = create_driver TEST_INTERVAL_3_CONFIG
|
98
|
-
assert_equal("test", d.instance.tag)
|
99
|
-
assert_equal(3, d.instance.interval)
|
100
|
-
|
101
|
-
d.run(timeout: 8) do
|
102
|
-
sleep 7
|
103
|
-
end
|
104
|
-
assert_equal(2, d.events.size)
|
105
|
-
|
106
|
-
d.events.each do |tag, time, record|
|
107
|
-
assert_equal("test", tag)
|
108
|
-
|
109
|
-
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200}, record)
|
110
|
-
assert(time.is_a?(Fluent::EventTime))
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
test 'interval 5' do
|
115
|
-
d = create_driver TEST_INTERVAL_5_CONFIG
|
116
|
-
assert_equal("test", d.instance.tag)
|
117
|
-
assert_equal(5, d.instance.interval)
|
118
|
-
|
119
|
-
d.run(timeout: 12) do
|
120
|
-
sleep 11
|
121
|
-
end
|
122
|
-
assert_equal(2, d.events.size)
|
123
|
-
|
124
|
-
d.events.each do |tag, time, record|
|
125
|
-
assert_equal("test", tag)
|
126
|
-
|
127
|
-
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
128
|
-
assert(time.is_a?(Fluent::EventTime))
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
test 'interval 3 with redirect' do
|
133
|
-
d = create_driver TEST_INTERVAL_3_REDIRECT_CONFIG
|
134
|
-
assert_equal("test", d.instance.tag)
|
135
|
-
assert_equal(3, d.instance.interval)
|
136
|
-
|
137
|
-
d.run(timeout: 8) do
|
138
|
-
sleep 7
|
139
|
-
end
|
140
|
-
assert_equal(2, d.events.size)
|
141
|
-
|
142
|
-
d.events.each do |tag, time, record|
|
143
|
-
assert_equal("test", tag)
|
144
|
-
|
145
|
-
assert_equal({"url"=>"http://127.0.0.1:3939/redirect","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
146
|
-
assert(time.is_a?(Fluent::EventTime))
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
sub_test_case "fail when not 200 OK" do
|
152
|
-
TEST_404_INTERVAL_3_CONFIG = %[
|
153
|
-
tag test
|
154
|
-
url http://127.0.0.1:3939/not_exist
|
155
|
-
|
156
|
-
interval 3s
|
157
|
-
format none
|
158
|
-
status_only true
|
159
|
-
]
|
160
|
-
|
161
|
-
TEST_500_INTERVAL_3_CONFIG = %[
|
162
|
-
tag test
|
163
|
-
url http://127.0.0.1:3939/internal_error
|
164
|
-
|
165
|
-
interval 3s
|
166
|
-
format none
|
167
|
-
status_only true
|
168
|
-
]
|
169
|
-
|
170
|
-
test '404' do
|
171
|
-
d = create_driver TEST_404_INTERVAL_3_CONFIG
|
172
|
-
assert_equal("test", d.instance.tag)
|
173
|
-
assert_equal(3, d.instance.interval)
|
174
|
-
|
175
|
-
d.run(timeout: 8) do
|
176
|
-
sleep 7
|
177
|
-
end
|
178
|
-
assert_equal(2, d.events.size)
|
179
|
-
|
180
|
-
d.events.each do |tag, time, record|
|
181
|
-
assert_equal("test", tag)
|
182
|
-
|
183
|
-
assert_equal("http://127.0.0.1:3939/not_exist", record["url"])
|
184
|
-
assert(time.is_a?(Fluent::EventTime))
|
185
|
-
|
186
|
-
assert_equal(404, record["status"])
|
187
|
-
assert_not_nil(record["error"])
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
test '500' do
|
192
|
-
d = create_driver TEST_500_INTERVAL_3_CONFIG
|
193
|
-
assert_equal("test", d.instance.tag)
|
194
|
-
assert_equal(3, d.instance.interval)
|
195
|
-
|
196
|
-
d.run(timeout: 8) do
|
197
|
-
sleep 7
|
198
|
-
end
|
199
|
-
assert_equal(2, d.events.size)
|
200
|
-
|
201
|
-
d.events.each do |tag, time, record|
|
202
|
-
assert_equal("test", tag)
|
203
|
-
|
204
|
-
assert_equal("http://127.0.0.1:3939/internal_error", record["url"])
|
205
|
-
assert(time.is_a?(Fluent::EventTime))
|
206
|
-
|
207
|
-
assert_equal(500, record["status"])
|
208
|
-
assert_not_nil(record["error"])
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
sub_test_case "fail when remote down" do
|
214
|
-
TEST_REFUSED_CONFIG = %[
|
215
|
-
tag test
|
216
|
-
url http://127.0.0.1:5927
|
217
|
-
interval 1s
|
218
|
-
|
219
|
-
format json
|
220
|
-
]
|
221
|
-
test "connection refused by remote" do
|
222
|
-
d = create_driver TEST_REFUSED_CONFIG
|
223
|
-
assert_equal("test", d.instance.tag)
|
224
|
-
|
225
|
-
d.run(timeout: 4) do
|
226
|
-
sleep 3
|
227
|
-
end
|
228
|
-
|
229
|
-
assert_equal(3, d.events.size)
|
230
|
-
d.events.each do |tag, time, record|
|
231
|
-
assert_equal("test", tag)
|
232
|
-
|
233
|
-
assert_equal("http://127.0.0.1:5927", record["url"])
|
234
|
-
assert(time.is_a?(Fluent::EventTime))
|
235
|
-
|
236
|
-
assert_equal(0, record["status"])
|
237
|
-
assert_not_nil(record["error"])
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
sub_test_case "fail when remote timeout" do
|
243
|
-
TEST_TIMEOUT_FAIL_CONFIG = %[
|
244
|
-
tag test
|
245
|
-
url http://127.0.0.1:3939/timeout
|
246
|
-
timeout 2s
|
247
|
-
|
248
|
-
interval 3s
|
249
|
-
format json
|
250
|
-
]
|
251
|
-
|
252
|
-
test "timeout" do
|
253
|
-
d = create_driver TEST_TIMEOUT_FAIL_CONFIG
|
254
|
-
assert_equal("test", d.instance.tag)
|
255
|
-
assert_equal(2, d.instance.timeout)
|
256
|
-
|
257
|
-
d.run(timeout: 8) do
|
258
|
-
sleep 7
|
259
|
-
end
|
260
|
-
assert_equal(2, d.events.size)
|
261
|
-
|
262
|
-
d.events.each do |tag, time, record|
|
263
|
-
assert_equal("test", tag)
|
264
|
-
|
265
|
-
assert_equal("http://127.0.0.1:3939/timeout", record["url"])
|
266
|
-
assert(time.is_a?(Fluent::EventTime))
|
267
|
-
|
268
|
-
assert_equal(0, record["status"])
|
269
|
-
assert_not_nil(record["error"])
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
sub_test_case "remote is prtected by basic auth" do
|
275
|
-
TEST_AUTH_SUCCESS_CONFIG = %[
|
276
|
-
tag test
|
277
|
-
url http://127.0.0.1:3939/protected
|
278
|
-
timeout 2s
|
279
|
-
user HatsuneMiku
|
280
|
-
password 3939
|
281
|
-
|
282
|
-
interval 3s
|
283
|
-
format json
|
284
|
-
]
|
285
|
-
|
286
|
-
TEST_AUTH_FAIL_CONFIG = %[
|
287
|
-
tag test
|
288
|
-
url http://127.0.0.1:3939/protected
|
289
|
-
timeout 2s
|
290
|
-
user HatsuneMiku
|
291
|
-
password wrong_password
|
292
|
-
|
293
|
-
interval 3s
|
294
|
-
format json
|
295
|
-
]
|
296
|
-
|
297
|
-
TEST_AUTH_FAIL_NOT_GIVEN_CONFIG = %[
|
298
|
-
tag test
|
299
|
-
url http://127.0.0.1:3939/protected
|
300
|
-
timeout 2s
|
301
|
-
|
302
|
-
interval 3s
|
303
|
-
format json
|
304
|
-
]
|
305
|
-
|
306
|
-
test 'interval 3 with corrent password' do
|
307
|
-
d = create_driver TEST_AUTH_SUCCESS_CONFIG
|
308
|
-
assert_equal("test", d.instance.tag)
|
309
|
-
assert_equal(3, d.instance.interval)
|
310
|
-
|
311
|
-
d.run(timeout: 8) do
|
312
|
-
sleep 7
|
313
|
-
end
|
314
|
-
assert_equal(2, d.events.size)
|
315
|
-
|
316
|
-
d.events.each do |tag, time, record|
|
317
|
-
assert_equal("test", tag)
|
318
|
-
|
319
|
-
assert_equal({"url"=>"http://127.0.0.1:3939/protected","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
320
|
-
assert(time.is_a?(Fluent::EventTime))
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
test 'interval 3 with wrong password' do
|
325
|
-
d = create_driver TEST_AUTH_FAIL_CONFIG
|
326
|
-
assert_equal("test", d.instance.tag)
|
327
|
-
assert_equal(3, d.instance.interval)
|
328
|
-
|
329
|
-
d.run(timeout: 8) do
|
330
|
-
sleep 7
|
331
|
-
end
|
332
|
-
assert_equal(2, d.events.size)
|
333
|
-
|
334
|
-
d.events.each do |tag, time, record|
|
335
|
-
assert_equal("test", tag)
|
336
|
-
|
337
|
-
assert_equal("http://127.0.0.1:3939/protected", record["url"])
|
338
|
-
assert(time.is_a?(Fluent::EventTime))
|
339
|
-
|
340
|
-
assert_equal(401, record["status"])
|
341
|
-
assert_not_nil(record["error"])
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
test 'interval 3 without auth info' do
|
346
|
-
d = create_driver TEST_AUTH_FAIL_CONFIG
|
347
|
-
assert_equal("test", d.instance.tag)
|
348
|
-
assert_equal(3, d.instance.interval)
|
349
|
-
|
350
|
-
d.run(timeout: 8) do
|
351
|
-
sleep 7
|
352
|
-
end
|
353
|
-
assert_equal(2, d.events.size)
|
354
|
-
|
355
|
-
d.events.each do |tag, time, record|
|
356
|
-
assert_equal("test", tag)
|
357
|
-
|
358
|
-
assert_equal("http://127.0.0.1:3939/protected", record["url"])
|
359
|
-
assert(time.is_a?(Fluent::EventTime))
|
360
|
-
|
361
|
-
assert_equal(401, record["status"])
|
362
|
-
assert_not_nil(record["error"])
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
sub_test_case "success case behind proxy" do
|
368
|
-
TEST_INTERVAL_3_PROXY_CONFIG = %[
|
369
|
-
tag test
|
370
|
-
url http://127.0.0.1:3939
|
371
|
-
proxy http://127.0.0.1:4040
|
372
|
-
|
373
|
-
interval 3s
|
374
|
-
format none
|
375
|
-
status_only true
|
376
|
-
]
|
377
|
-
|
378
|
-
TEST_INTERVAL_3_REDIRECT_PROXY_CONFIG = %[
|
379
|
-
tag test
|
380
|
-
url http://127.0.0.1:3939/redirect
|
381
|
-
proxy http://127.0.0.1:4040
|
382
|
-
|
383
|
-
interval 3s
|
384
|
-
format json
|
385
|
-
]
|
386
|
-
|
387
|
-
TEST_AUTH_SUCCESS_PROXY_CONFIG = %[
|
388
|
-
tag test
|
389
|
-
url http://127.0.0.1:3939/protected
|
390
|
-
proxy http://127.0.0.1:4040
|
391
|
-
timeout 2s
|
392
|
-
user HatsuneMiku
|
393
|
-
password 3939
|
394
|
-
|
395
|
-
interval 3s
|
396
|
-
format json
|
397
|
-
]
|
398
|
-
|
399
|
-
setup do
|
400
|
-
@proxy_server = StubProxy.new
|
401
|
-
@proxy_server.start
|
402
|
-
end
|
403
|
-
|
404
|
-
teardown do
|
405
|
-
@proxy_server.shutdown
|
406
|
-
end
|
407
|
-
|
408
|
-
test 'interval 3 with status_only' do
|
409
|
-
d = create_driver TEST_INTERVAL_3_PROXY_CONFIG
|
410
|
-
assert_equal("test", d.instance.tag)
|
411
|
-
assert_equal(3, d.instance.interval)
|
412
|
-
|
413
|
-
d.run(timeout: 8) do
|
414
|
-
sleep 7
|
415
|
-
end
|
416
|
-
assert_equal(2, d.events.size)
|
417
|
-
|
418
|
-
d.events.each do |tag, time, record|
|
419
|
-
assert_equal("test", tag)
|
420
|
-
|
421
|
-
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200}, record)
|
422
|
-
assert(time.is_a?(Fluent::EventTime))
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
test 'interval 3 with redirect' do
|
427
|
-
d = create_driver TEST_INTERVAL_3_REDIRECT_PROXY_CONFIG
|
428
|
-
assert_equal("test", d.instance.tag)
|
429
|
-
assert_equal(3, d.instance.interval)
|
430
|
-
|
431
|
-
d.run(timeout: 8) do
|
432
|
-
sleep 7
|
433
|
-
end
|
434
|
-
assert_equal(2, d.events.size)
|
435
|
-
|
436
|
-
d.events.each do |tag, time, record|
|
437
|
-
assert_equal("test", tag)
|
438
|
-
|
439
|
-
assert_equal({"url"=>"http://127.0.0.1:3939/redirect","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
440
|
-
assert(time.is_a?(Fluent::EventTime))
|
441
|
-
end
|
442
|
-
end
|
443
|
-
|
444
|
-
test 'interval 3 with corrent password' do
|
445
|
-
d = create_driver TEST_AUTH_SUCCESS_PROXY_CONFIG
|
446
|
-
assert_equal("test", d.instance.tag)
|
447
|
-
assert_equal(3, d.instance.interval)
|
448
|
-
|
449
|
-
d.run(timeout: 8) do
|
450
|
-
sleep 7
|
451
|
-
end
|
452
|
-
assert_equal(2, d.events.size)
|
453
|
-
|
454
|
-
d.events.each do |tag, time, record|
|
455
|
-
assert_equal("test", tag)
|
456
|
-
|
457
|
-
assert_equal({"url"=>"http://127.0.0.1:3939/protected","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
458
|
-
assert(time.is_a?(Fluent::EventTime))
|
459
|
-
end
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
sub_test_case "capture response header" do
|
464
|
-
TEST_INTERVAL_3_RES_HEADER_CONFIG = %[
|
465
|
-
tag test
|
466
|
-
url http://127.0.0.1:3939
|
467
|
-
|
468
|
-
interval 3s
|
469
|
-
format json
|
470
|
-
|
471
|
-
<response_header>
|
472
|
-
header Content-Type
|
473
|
-
</response_header>
|
474
|
-
]
|
475
|
-
|
476
|
-
TEST_INTERVAL_3_RES_MULTI_HEADER_CONFIG = %[
|
477
|
-
tag test
|
478
|
-
url http://127.0.0.1:3939
|
479
|
-
|
480
|
-
interval 3s
|
481
|
-
format json
|
482
|
-
|
483
|
-
<response_header>
|
484
|
-
header Content-Type
|
485
|
-
</response_header>
|
486
|
-
|
487
|
-
<response_header>
|
488
|
-
header Content-Length
|
489
|
-
</response_header>
|
490
|
-
]
|
491
|
-
|
492
|
-
test 'interval 3 with single header' do
|
493
|
-
d = create_driver TEST_INTERVAL_3_RES_HEADER_CONFIG
|
494
|
-
assert_equal("test", d.instance.tag)
|
495
|
-
assert_equal(3, d.instance.interval)
|
496
|
-
|
497
|
-
d.run(timeout: 8) do
|
498
|
-
sleep 7
|
499
|
-
end
|
500
|
-
assert_equal(2, d.events.size)
|
501
|
-
|
502
|
-
d.events.each do |tag, time, record|
|
503
|
-
assert_equal("test", tag)
|
504
|
-
|
505
|
-
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"Content-Type"=>"application/json"}}, record)
|
506
|
-
assert(time.is_a?(Fluent::EventTime))
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
test 'interval 3 with multiple header' do
|
511
|
-
d = create_driver TEST_INTERVAL_3_RES_MULTI_HEADER_CONFIG
|
512
|
-
assert_equal("test", d.instance.tag)
|
513
|
-
assert_equal(3, d.instance.interval)
|
514
|
-
|
515
|
-
d.run(timeout: 8) do
|
516
|
-
sleep 7
|
517
|
-
end
|
518
|
-
assert_equal(2, d.events.size)
|
519
|
-
|
520
|
-
d.events.each do |tag, time, record|
|
521
|
-
assert_equal("test", tag)
|
522
|
-
|
523
|
-
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"Content-Type"=>"application/json","Content-Length"=>"18"}}, record)
|
524
|
-
assert(time.is_a?(Fluent::EventTime))
|
525
|
-
end
|
526
|
-
end
|
527
|
-
end
|
528
|
-
|
529
|
-
sub_test_case "custom request header" do
|
530
|
-
TEST_INTERVAL_3_CUSTOM_HEADER_CONFIG = %[
|
531
|
-
tag test
|
532
|
-
url http://127.0.0.1:3939/custom_header
|
533
|
-
|
534
|
-
interval 3s
|
535
|
-
format json
|
536
|
-
|
537
|
-
<request_header>
|
538
|
-
header HATSUNE-MIKU
|
539
|
-
value 3939
|
540
|
-
</request_header>
|
541
|
-
|
542
|
-
<response_header>
|
543
|
-
header HATSUNE-MIKU
|
544
|
-
</response_header>
|
545
|
-
]
|
546
|
-
|
547
|
-
test 'interval 3 with single header' do
|
548
|
-
d = create_driver TEST_INTERVAL_3_CUSTOM_HEADER_CONFIG
|
549
|
-
assert_equal("test", d.instance.tag)
|
550
|
-
assert_equal(3, d.instance.interval)
|
551
|
-
|
552
|
-
d.run(timeout: 8) do
|
553
|
-
sleep 7
|
554
|
-
end
|
555
|
-
assert_equal(2, d.events.size)
|
556
|
-
|
557
|
-
d.events.each do |tag, time, record|
|
558
|
-
assert_equal("test", tag)
|
559
|
-
|
560
|
-
assert_equal({"url"=>"http://127.0.0.1:3939/custom_header","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"HATSUNE-MIKU"=>"3939"}}, record)
|
561
|
-
assert(time.is_a?(Fluent::EventTime))
|
562
|
-
end
|
563
|
-
end
|
564
|
-
end
|
565
|
-
|
566
|
-
sub_test_case "request method" do
|
567
|
-
TEST_INTERVAL_3_POST = %[
|
568
|
-
tag test
|
569
|
-
url http://127.0.0.1:3939/method_post
|
570
|
-
|
571
|
-
interval 3s
|
572
|
-
format json
|
573
|
-
http_method post
|
574
|
-
]
|
575
|
-
|
576
|
-
TEST_INTERVAL_3_DELETE = %[
|
577
|
-
tag test
|
578
|
-
url http://127.0.0.1:3939/method_delete
|
579
|
-
|
580
|
-
interval 3s
|
581
|
-
format json
|
582
|
-
http_method delete
|
583
|
-
]
|
584
|
-
|
585
|
-
test 'interval 3 with :post' do
|
586
|
-
d = create_driver TEST_INTERVAL_3_POST
|
587
|
-
assert_equal("test", d.instance.tag)
|
588
|
-
assert_equal(3, d.instance.interval)
|
589
|
-
|
590
|
-
d.run(timeout: 8) do
|
591
|
-
sleep 7
|
592
|
-
end
|
593
|
-
assert_equal(2, d.events.size)
|
594
|
-
|
595
|
-
d.events.each do |tag, time, record|
|
596
|
-
assert_equal("test", tag)
|
597
|
-
|
598
|
-
assert_equal({"url"=>"http://127.0.0.1:3939/method_post","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
599
|
-
assert(time.is_a?(Fluent::EventTime))
|
600
|
-
end
|
601
|
-
end
|
602
57
|
|
603
|
-
test '
|
604
|
-
d = create_driver
|
58
|
+
test 'agent' do
|
59
|
+
d = create_driver TEST_DEFAULT_VALUE_CONFIG
|
605
60
|
assert_equal("test", d.instance.tag)
|
606
|
-
assert_equal(3, d.instance.interval)
|
607
|
-
|
608
|
-
d.run(timeout: 8) do
|
609
|
-
sleep 7
|
610
|
-
end
|
611
|
-
assert_equal(2, d.events.size)
|
612
|
-
|
613
|
-
d.events.each do |tag, time, record|
|
614
|
-
assert_equal("test", tag)
|
615
61
|
|
616
|
-
|
617
|
-
assert(time.is_a?(Fluent::EventTime))
|
618
|
-
end
|
62
|
+
assert_equal("fluent-plugin-http-pull", d.instance.agent)
|
619
63
|
end
|
620
64
|
end
|
621
65
|
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/in_http_pull.rb"
|
3
|
+
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
class HttpPullInputTestAuth < Test::Unit::TestCase
|
7
|
+
@stub_server = nil
|
8
|
+
|
9
|
+
setup do
|
10
|
+
@stub_server = StubServer.new
|
11
|
+
@stub_server.start
|
12
|
+
end
|
13
|
+
|
14
|
+
teardown do
|
15
|
+
@stub_server.shutdown
|
16
|
+
end
|
17
|
+
|
18
|
+
sub_test_case "remote is prtected by basic auth" do
|
19
|
+
TEST_AUTH_SUCCESS_CONFIG = %[
|
20
|
+
tag test
|
21
|
+
url http://127.0.0.1:3939/protected
|
22
|
+
timeout 2s
|
23
|
+
user HatsuneMiku
|
24
|
+
password 3939
|
25
|
+
|
26
|
+
interval 3s
|
27
|
+
format json
|
28
|
+
]
|
29
|
+
|
30
|
+
TEST_AUTH_FAIL_CONFIG = %[
|
31
|
+
tag test
|
32
|
+
url http://127.0.0.1:3939/protected
|
33
|
+
timeout 2s
|
34
|
+
user HatsuneMiku
|
35
|
+
password wrong_password
|
36
|
+
|
37
|
+
interval 3s
|
38
|
+
format json
|
39
|
+
]
|
40
|
+
|
41
|
+
TEST_AUTH_FAIL_NOT_GIVEN_CONFIG = %[
|
42
|
+
tag test
|
43
|
+
url http://127.0.0.1:3939/protected
|
44
|
+
timeout 2s
|
45
|
+
|
46
|
+
interval 3s
|
47
|
+
format json
|
48
|
+
]
|
49
|
+
|
50
|
+
test 'interval 3 with corrent password' do
|
51
|
+
d = create_driver TEST_AUTH_SUCCESS_CONFIG
|
52
|
+
assert_equal("test", d.instance.tag)
|
53
|
+
assert_equal(3, d.instance.interval)
|
54
|
+
|
55
|
+
d.run(timeout: 8) do
|
56
|
+
sleep 7
|
57
|
+
end
|
58
|
+
assert_equal(2, d.events.size)
|
59
|
+
|
60
|
+
d.events.each do |tag, time, record|
|
61
|
+
assert_equal("test", tag)
|
62
|
+
|
63
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/protected","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
64
|
+
assert(time.is_a?(Fluent::EventTime))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'interval 3 with wrong password' do
|
69
|
+
d = create_driver TEST_AUTH_FAIL_CONFIG
|
70
|
+
assert_equal("test", d.instance.tag)
|
71
|
+
assert_equal(3, d.instance.interval)
|
72
|
+
|
73
|
+
d.run(timeout: 8) do
|
74
|
+
sleep 7
|
75
|
+
end
|
76
|
+
assert_equal(2, d.events.size)
|
77
|
+
|
78
|
+
d.events.each do |tag, time, record|
|
79
|
+
assert_equal("test", tag)
|
80
|
+
|
81
|
+
assert_equal("http://127.0.0.1:3939/protected", record["url"])
|
82
|
+
assert(time.is_a?(Fluent::EventTime))
|
83
|
+
|
84
|
+
assert_equal(401, record["status"])
|
85
|
+
assert_not_nil(record["error"])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'interval 3 without auth info' do
|
90
|
+
d = create_driver TEST_AUTH_FAIL_CONFIG
|
91
|
+
assert_equal("test", d.instance.tag)
|
92
|
+
assert_equal(3, d.instance.interval)
|
93
|
+
|
94
|
+
d.run(timeout: 8) do
|
95
|
+
sleep 7
|
96
|
+
end
|
97
|
+
assert_equal(2, d.events.size)
|
98
|
+
|
99
|
+
d.events.each do |tag, time, record|
|
100
|
+
assert_equal("test", tag)
|
101
|
+
|
102
|
+
assert_equal("http://127.0.0.1:3939/protected", record["url"])
|
103
|
+
assert(time.is_a?(Fluent::EventTime))
|
104
|
+
|
105
|
+
assert_equal(401, record["status"])
|
106
|
+
assert_not_nil(record["error"])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def create_driver(conf)
|
114
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpPullInput).configure(conf)
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/in_http_pull.rb"
|
3
|
+
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
class HttpPullInputTestBasic < Test::Unit::TestCase
|
7
|
+
@stub_server = nil
|
8
|
+
|
9
|
+
setup do
|
10
|
+
@stub_server = StubServer.new
|
11
|
+
@stub_server.start
|
12
|
+
end
|
13
|
+
|
14
|
+
teardown do
|
15
|
+
@stub_server.shutdown
|
16
|
+
end
|
17
|
+
|
18
|
+
sub_test_case "success case" do
|
19
|
+
TEST_INTERVAL_3_CONFIG = %[
|
20
|
+
tag test
|
21
|
+
url http://127.0.0.1:3939
|
22
|
+
|
23
|
+
interval 3s
|
24
|
+
format none
|
25
|
+
status_only true
|
26
|
+
]
|
27
|
+
|
28
|
+
TEST_INTERVAL_5_CONFIG = %[
|
29
|
+
tag test
|
30
|
+
url http://127.0.0.1:3939
|
31
|
+
|
32
|
+
interval 5s
|
33
|
+
format json
|
34
|
+
]
|
35
|
+
|
36
|
+
TEST_INTERVAL_3_REDIRECT_CONFIG = %[
|
37
|
+
tag test
|
38
|
+
url http://127.0.0.1:3939/redirect
|
39
|
+
|
40
|
+
interval 3s
|
41
|
+
format json
|
42
|
+
]
|
43
|
+
|
44
|
+
test 'interval 3 with status_only' do
|
45
|
+
d = create_driver TEST_INTERVAL_3_CONFIG
|
46
|
+
assert_equal("test", d.instance.tag)
|
47
|
+
assert_equal(3, d.instance.interval)
|
48
|
+
|
49
|
+
d.run(timeout: 8) do
|
50
|
+
sleep 7
|
51
|
+
end
|
52
|
+
assert_equal(2, d.events.size)
|
53
|
+
|
54
|
+
d.events.each do |tag, time, record|
|
55
|
+
assert_equal("test", tag)
|
56
|
+
|
57
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200}, record)
|
58
|
+
assert(time.is_a?(Fluent::EventTime))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'interval 5' do
|
63
|
+
d = create_driver TEST_INTERVAL_5_CONFIG
|
64
|
+
assert_equal("test", d.instance.tag)
|
65
|
+
assert_equal(5, d.instance.interval)
|
66
|
+
|
67
|
+
d.run(timeout: 12) do
|
68
|
+
sleep 11
|
69
|
+
end
|
70
|
+
assert_equal(2, d.events.size)
|
71
|
+
|
72
|
+
d.events.each do |tag, time, record|
|
73
|
+
assert_equal("test", tag)
|
74
|
+
|
75
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
76
|
+
assert(time.is_a?(Fluent::EventTime))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
test 'interval 3 with redirect' do
|
81
|
+
d = create_driver TEST_INTERVAL_3_REDIRECT_CONFIG
|
82
|
+
assert_equal("test", d.instance.tag)
|
83
|
+
assert_equal(3, d.instance.interval)
|
84
|
+
|
85
|
+
d.run(timeout: 8) do
|
86
|
+
sleep 7
|
87
|
+
end
|
88
|
+
assert_equal(2, d.events.size)
|
89
|
+
|
90
|
+
d.events.each do |tag, time, record|
|
91
|
+
assert_equal("test", tag)
|
92
|
+
|
93
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/redirect","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
94
|
+
assert(time.is_a?(Fluent::EventTime))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
sub_test_case "fail when not 200 OK" do
|
100
|
+
TEST_404_INTERVAL_3_CONFIG = %[
|
101
|
+
tag test
|
102
|
+
url http://127.0.0.1:3939/not_exist
|
103
|
+
|
104
|
+
interval 3s
|
105
|
+
format none
|
106
|
+
status_only true
|
107
|
+
]
|
108
|
+
|
109
|
+
TEST_500_INTERVAL_3_CONFIG = %[
|
110
|
+
tag test
|
111
|
+
url http://127.0.0.1:3939/internal_error
|
112
|
+
|
113
|
+
interval 3s
|
114
|
+
format none
|
115
|
+
status_only true
|
116
|
+
]
|
117
|
+
|
118
|
+
test '404' do
|
119
|
+
d = create_driver TEST_404_INTERVAL_3_CONFIG
|
120
|
+
assert_equal("test", d.instance.tag)
|
121
|
+
assert_equal(3, d.instance.interval)
|
122
|
+
|
123
|
+
d.run(timeout: 8) do
|
124
|
+
sleep 7
|
125
|
+
end
|
126
|
+
assert_equal(2, d.events.size)
|
127
|
+
|
128
|
+
d.events.each do |tag, time, record|
|
129
|
+
assert_equal("test", tag)
|
130
|
+
|
131
|
+
assert_equal("http://127.0.0.1:3939/not_exist", record["url"])
|
132
|
+
assert(time.is_a?(Fluent::EventTime))
|
133
|
+
|
134
|
+
assert_equal(404, record["status"])
|
135
|
+
assert_not_nil(record["error"])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
test '500' do
|
140
|
+
d = create_driver TEST_500_INTERVAL_3_CONFIG
|
141
|
+
assert_equal("test", d.instance.tag)
|
142
|
+
assert_equal(3, d.instance.interval)
|
143
|
+
|
144
|
+
d.run(timeout: 8) do
|
145
|
+
sleep 7
|
146
|
+
end
|
147
|
+
assert_equal(2, d.events.size)
|
148
|
+
|
149
|
+
d.events.each do |tag, time, record|
|
150
|
+
assert_equal("test", tag)
|
151
|
+
|
152
|
+
assert_equal("http://127.0.0.1:3939/internal_error", record["url"])
|
153
|
+
assert(time.is_a?(Fluent::EventTime))
|
154
|
+
|
155
|
+
assert_equal(500, record["status"])
|
156
|
+
assert_not_nil(record["error"])
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
sub_test_case "fail when remote down" do
|
162
|
+
TEST_REFUSED_CONFIG = %[
|
163
|
+
tag test
|
164
|
+
url http://127.0.0.1:5927
|
165
|
+
interval 1s
|
166
|
+
|
167
|
+
format json
|
168
|
+
]
|
169
|
+
test "connection refused by remote" do
|
170
|
+
d = create_driver TEST_REFUSED_CONFIG
|
171
|
+
assert_equal("test", d.instance.tag)
|
172
|
+
|
173
|
+
d.run(timeout: 4) do
|
174
|
+
sleep 3
|
175
|
+
end
|
176
|
+
|
177
|
+
assert_equal(3, d.events.size)
|
178
|
+
d.events.each do |tag, time, record|
|
179
|
+
assert_equal("test", tag)
|
180
|
+
|
181
|
+
assert_equal("http://127.0.0.1:5927", record["url"])
|
182
|
+
assert(time.is_a?(Fluent::EventTime))
|
183
|
+
|
184
|
+
assert_equal(0, record["status"])
|
185
|
+
assert_not_nil(record["error"])
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
sub_test_case "fail when remote timeout" do
|
191
|
+
TEST_TIMEOUT_FAIL_CONFIG = %[
|
192
|
+
tag test
|
193
|
+
url http://127.0.0.1:3939/timeout
|
194
|
+
timeout 2s
|
195
|
+
|
196
|
+
interval 3s
|
197
|
+
format json
|
198
|
+
]
|
199
|
+
|
200
|
+
test "timeout" do
|
201
|
+
d = create_driver TEST_TIMEOUT_FAIL_CONFIG
|
202
|
+
assert_equal("test", d.instance.tag)
|
203
|
+
assert_equal(2, d.instance.timeout)
|
204
|
+
|
205
|
+
d.run(timeout: 8) do
|
206
|
+
sleep 7
|
207
|
+
end
|
208
|
+
assert_equal(2, d.events.size)
|
209
|
+
|
210
|
+
d.events.each do |tag, time, record|
|
211
|
+
assert_equal("test", tag)
|
212
|
+
|
213
|
+
assert_equal("http://127.0.0.1:3939/timeout", record["url"])
|
214
|
+
assert(time.is_a?(Fluent::EventTime))
|
215
|
+
|
216
|
+
assert_equal(0, record["status"])
|
217
|
+
assert_not_nil(record["error"])
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
private
|
223
|
+
|
224
|
+
def create_driver(conf)
|
225
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpPullInput).configure(conf)
|
226
|
+
end
|
227
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/in_http_pull.rb"
|
3
|
+
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
class HttpPullInputTestHttpHeader < Test::Unit::TestCase
|
7
|
+
@stub_server = nil
|
8
|
+
|
9
|
+
setup do
|
10
|
+
@stub_server = StubServer.new
|
11
|
+
@stub_server.start
|
12
|
+
end
|
13
|
+
|
14
|
+
teardown do
|
15
|
+
@stub_server.shutdown
|
16
|
+
end
|
17
|
+
|
18
|
+
sub_test_case "capture response header" do
|
19
|
+
TEST_INTERVAL_3_RES_HEADER_CONFIG = %[
|
20
|
+
tag test
|
21
|
+
url http://127.0.0.1:3939
|
22
|
+
|
23
|
+
interval 3s
|
24
|
+
format json
|
25
|
+
|
26
|
+
<response_header>
|
27
|
+
header Content-Type
|
28
|
+
</response_header>
|
29
|
+
]
|
30
|
+
|
31
|
+
TEST_INTERVAL_3_RES_MULTI_HEADER_CONFIG = %[
|
32
|
+
tag test
|
33
|
+
url http://127.0.0.1:3939
|
34
|
+
|
35
|
+
interval 3s
|
36
|
+
format json
|
37
|
+
|
38
|
+
<response_header>
|
39
|
+
header Content-Type
|
40
|
+
</response_header>
|
41
|
+
|
42
|
+
<response_header>
|
43
|
+
header Content-Length
|
44
|
+
</response_header>
|
45
|
+
]
|
46
|
+
|
47
|
+
test 'interval 3 with single header' do
|
48
|
+
d = create_driver TEST_INTERVAL_3_RES_HEADER_CONFIG
|
49
|
+
assert_equal("test", d.instance.tag)
|
50
|
+
assert_equal(3, d.instance.interval)
|
51
|
+
|
52
|
+
d.run(timeout: 8) do
|
53
|
+
sleep 7
|
54
|
+
end
|
55
|
+
assert_equal(2, d.events.size)
|
56
|
+
|
57
|
+
d.events.each do |tag, time, record|
|
58
|
+
assert_equal("test", tag)
|
59
|
+
|
60
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"Content-Type"=>"application/json"}}, record)
|
61
|
+
assert(time.is_a?(Fluent::EventTime))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
test 'interval 3 with multiple header' do
|
66
|
+
d = create_driver TEST_INTERVAL_3_RES_MULTI_HEADER_CONFIG
|
67
|
+
assert_equal("test", d.instance.tag)
|
68
|
+
assert_equal(3, d.instance.interval)
|
69
|
+
|
70
|
+
d.run(timeout: 8) do
|
71
|
+
sleep 7
|
72
|
+
end
|
73
|
+
assert_equal(2, d.events.size)
|
74
|
+
|
75
|
+
d.events.each do |tag, time, record|
|
76
|
+
assert_equal("test", tag)
|
77
|
+
|
78
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"Content-Type"=>"application/json","Content-Length"=>"18"}}, record)
|
79
|
+
assert(time.is_a?(Fluent::EventTime))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
sub_test_case "custom request header" do
|
85
|
+
TEST_INTERVAL_3_CUSTOM_HEADER_CONFIG = %[
|
86
|
+
tag test
|
87
|
+
url http://127.0.0.1:3939/custom_header
|
88
|
+
|
89
|
+
interval 3s
|
90
|
+
format json
|
91
|
+
|
92
|
+
<request_header>
|
93
|
+
header HATSUNE-MIKU
|
94
|
+
value 3939
|
95
|
+
</request_header>
|
96
|
+
|
97
|
+
<response_header>
|
98
|
+
header HATSUNE-MIKU
|
99
|
+
</response_header>
|
100
|
+
]
|
101
|
+
|
102
|
+
test 'interval 3 with single header' do
|
103
|
+
d = create_driver TEST_INTERVAL_3_CUSTOM_HEADER_CONFIG
|
104
|
+
assert_equal("test", d.instance.tag)
|
105
|
+
assert_equal(3, d.instance.interval)
|
106
|
+
|
107
|
+
d.run(timeout: 8) do
|
108
|
+
sleep 7
|
109
|
+
end
|
110
|
+
assert_equal(2, d.events.size)
|
111
|
+
|
112
|
+
d.events.each do |tag, time, record|
|
113
|
+
assert_equal("test", tag)
|
114
|
+
|
115
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/custom_header","status"=>200,"message"=>{"status"=>"OK"},"header"=>{"HATSUNE-MIKU"=>"3939"}}, record)
|
116
|
+
assert(time.is_a?(Fluent::EventTime))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def create_driver(conf)
|
124
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpPullInput).configure(conf)
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/in_http_pull.rb"
|
3
|
+
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
class HttpPullInputTestProxy < Test::Unit::TestCase
|
7
|
+
@stub_server = nil
|
8
|
+
|
9
|
+
setup do
|
10
|
+
@stub_server = StubServer.new
|
11
|
+
@stub_server.start
|
12
|
+
end
|
13
|
+
|
14
|
+
teardown do
|
15
|
+
@stub_server.shutdown
|
16
|
+
end
|
17
|
+
|
18
|
+
sub_test_case "success case behind proxy" do
|
19
|
+
TEST_INTERVAL_3_PROXY_CONFIG = %[
|
20
|
+
tag test
|
21
|
+
url http://127.0.0.1:3939
|
22
|
+
proxy http://127.0.0.1:4040
|
23
|
+
|
24
|
+
interval 3s
|
25
|
+
format none
|
26
|
+
status_only true
|
27
|
+
]
|
28
|
+
|
29
|
+
TEST_INTERVAL_3_REDIRECT_PROXY_CONFIG = %[
|
30
|
+
tag test
|
31
|
+
url http://127.0.0.1:3939/redirect
|
32
|
+
proxy http://127.0.0.1:4040
|
33
|
+
|
34
|
+
interval 3s
|
35
|
+
format json
|
36
|
+
]
|
37
|
+
|
38
|
+
TEST_AUTH_SUCCESS_PROXY_CONFIG = %[
|
39
|
+
tag test
|
40
|
+
url http://127.0.0.1:3939/protected
|
41
|
+
proxy http://127.0.0.1:4040
|
42
|
+
timeout 2s
|
43
|
+
user HatsuneMiku
|
44
|
+
password 3939
|
45
|
+
|
46
|
+
interval 3s
|
47
|
+
format json
|
48
|
+
]
|
49
|
+
|
50
|
+
setup do
|
51
|
+
@proxy_server = StubProxy.new
|
52
|
+
@proxy_server.start
|
53
|
+
end
|
54
|
+
|
55
|
+
teardown do
|
56
|
+
@proxy_server.shutdown
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'interval 3 with status_only' do
|
60
|
+
d = create_driver TEST_INTERVAL_3_PROXY_CONFIG
|
61
|
+
assert_equal("test", d.instance.tag)
|
62
|
+
assert_equal(3, d.instance.interval)
|
63
|
+
|
64
|
+
d.run(timeout: 8) do
|
65
|
+
sleep 7
|
66
|
+
end
|
67
|
+
assert_equal(2, d.events.size)
|
68
|
+
|
69
|
+
d.events.each do |tag, time, record|
|
70
|
+
assert_equal("test", tag)
|
71
|
+
|
72
|
+
assert_equal({"url"=>"http://127.0.0.1:3939","status"=>200}, record)
|
73
|
+
assert(time.is_a?(Fluent::EventTime))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'interval 3 with redirect' do
|
78
|
+
d = create_driver TEST_INTERVAL_3_REDIRECT_PROXY_CONFIG
|
79
|
+
assert_equal("test", d.instance.tag)
|
80
|
+
assert_equal(3, d.instance.interval)
|
81
|
+
|
82
|
+
d.run(timeout: 8) do
|
83
|
+
sleep 7
|
84
|
+
end
|
85
|
+
assert_equal(2, d.events.size)
|
86
|
+
|
87
|
+
d.events.each do |tag, time, record|
|
88
|
+
assert_equal("test", tag)
|
89
|
+
|
90
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/redirect","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
91
|
+
assert(time.is_a?(Fluent::EventTime))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
test 'interval 3 with corrent password' do
|
96
|
+
d = create_driver TEST_AUTH_SUCCESS_PROXY_CONFIG
|
97
|
+
assert_equal("test", d.instance.tag)
|
98
|
+
assert_equal(3, d.instance.interval)
|
99
|
+
|
100
|
+
d.run(timeout: 8) do
|
101
|
+
sleep 7
|
102
|
+
end
|
103
|
+
assert_equal(2, d.events.size)
|
104
|
+
|
105
|
+
d.events.each do |tag, time, record|
|
106
|
+
assert_equal("test", tag)
|
107
|
+
|
108
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/protected","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
109
|
+
assert(time.is_a?(Fluent::EventTime))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def create_driver(conf)
|
117
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpPullInput).configure(conf)
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/in_http_pull.rb"
|
3
|
+
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
class HttpPullInputTestRequestMethod < Test::Unit::TestCase
|
7
|
+
@stub_server = nil
|
8
|
+
|
9
|
+
setup do
|
10
|
+
@stub_server = StubServer.new
|
11
|
+
@stub_server.start
|
12
|
+
end
|
13
|
+
|
14
|
+
teardown do
|
15
|
+
@stub_server.shutdown
|
16
|
+
end
|
17
|
+
|
18
|
+
sub_test_case "request method" do
|
19
|
+
TEST_INTERVAL_3_POST = %[
|
20
|
+
tag test
|
21
|
+
url http://127.0.0.1:3939/method_post
|
22
|
+
|
23
|
+
interval 3s
|
24
|
+
format json
|
25
|
+
http_method post
|
26
|
+
]
|
27
|
+
|
28
|
+
TEST_INTERVAL_3_DELETE = %[
|
29
|
+
tag test
|
30
|
+
url http://127.0.0.1:3939/method_delete
|
31
|
+
|
32
|
+
interval 3s
|
33
|
+
format json
|
34
|
+
http_method delete
|
35
|
+
]
|
36
|
+
|
37
|
+
test 'interval 3 with :post' do
|
38
|
+
d = create_driver TEST_INTERVAL_3_POST
|
39
|
+
assert_equal("test", d.instance.tag)
|
40
|
+
assert_equal(3, d.instance.interval)
|
41
|
+
|
42
|
+
d.run(timeout: 8) do
|
43
|
+
sleep 7
|
44
|
+
end
|
45
|
+
assert_equal(2, d.events.size)
|
46
|
+
|
47
|
+
d.events.each do |tag, time, record|
|
48
|
+
assert_equal("test", tag)
|
49
|
+
|
50
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/method_post","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
51
|
+
assert(time.is_a?(Fluent::EventTime))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'interval 3 with :delete' do
|
56
|
+
d = create_driver TEST_INTERVAL_3_DELETE
|
57
|
+
assert_equal("test", d.instance.tag)
|
58
|
+
assert_equal(3, d.instance.interval)
|
59
|
+
|
60
|
+
d.run(timeout: 8) do
|
61
|
+
sleep 7
|
62
|
+
end
|
63
|
+
assert_equal(2, d.events.size)
|
64
|
+
|
65
|
+
d.events.each do |tag, time, record|
|
66
|
+
assert_equal("test", tag)
|
67
|
+
|
68
|
+
assert_equal({"url"=>"http://127.0.0.1:3939/method_delete","status"=>200, "message"=>{"status"=>"OK"}}, record)
|
69
|
+
assert(time.is_a?(Fluent::EventTime))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def create_driver(conf)
|
77
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpPullInput).configure(conf)
|
78
|
+
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-http-pull
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- filepang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -147,6 +147,11 @@ files:
|
|
147
147
|
- test/helper/stub_proxy.rb
|
148
148
|
- test/helper/stub_server.rb
|
149
149
|
- test/plugin/test_in_http_pull.rb
|
150
|
+
- test/plugin/test_in_http_pull_auth.rb
|
151
|
+
- test/plugin/test_in_http_pull_basic.rb
|
152
|
+
- test/plugin/test_in_http_pull_http_header.rb
|
153
|
+
- test/plugin/test_in_http_pull_proxy.rb
|
154
|
+
- test/plugin/test_in_http_pull_request_method.rb
|
150
155
|
homepage: https://github.com/HatsuneMiku3939/fluent-plugin-http-pull
|
151
156
|
licenses:
|
152
157
|
- Apache-2.0
|
@@ -167,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
172
|
version: '0'
|
168
173
|
requirements: []
|
169
174
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.
|
175
|
+
rubygems_version: 2.6.13
|
171
176
|
signing_key:
|
172
177
|
specification_version: 4
|
173
178
|
summary: fluent-plugin-http-pull
|
@@ -176,3 +181,8 @@ test_files:
|
|
176
181
|
- test/helper/stub_proxy.rb
|
177
182
|
- test/helper/stub_server.rb
|
178
183
|
- test/plugin/test_in_http_pull.rb
|
184
|
+
- test/plugin/test_in_http_pull_auth.rb
|
185
|
+
- test/plugin/test_in_http_pull_basic.rb
|
186
|
+
- test/plugin/test_in_http_pull_http_header.rb
|
187
|
+
- test/plugin/test_in_http_pull_proxy.rb
|
188
|
+
- test/plugin/test_in_http_pull_request_method.rb
|