fluent-plugin-http-pull 0.7.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,71 +1,92 @@
1
- require "helper"
2
- require "fluent/plugin/in_http_pull.rb"
3
-
4
- require 'ostruct'
5
-
6
- class HttpPullInputTestDefaultOptions < Test::Unit::TestCase
7
- sub_test_case "default value of each options" do
8
- TEST_DEFAULT_VALUE_CONFIG = %[
9
- tag test
10
- url http://127.0.0.1:3939
11
-
12
- interval 3s
13
- format json
14
- ]
15
-
16
- test 'status_only' do
17
- d = create_driver TEST_DEFAULT_VALUE_CONFIG
18
- assert_equal("test", d.instance.tag)
19
-
20
- assert_equal(false, d.instance.status_only)
21
- end
22
-
23
- test 'timeout' do
24
- d = create_driver TEST_DEFAULT_VALUE_CONFIG
25
- assert_equal("test", d.instance.tag)
26
-
27
- assert_equal(10, d.instance.timeout)
28
- end
29
-
30
- test 'user' do
31
- d = create_driver TEST_DEFAULT_VALUE_CONFIG
32
- assert_equal("test", d.instance.tag)
33
-
34
- assert_equal(nil, d.instance.user)
35
- end
36
-
37
- test 'password' do
38
- d = create_driver TEST_DEFAULT_VALUE_CONFIG
39
- assert_equal("test", d.instance.tag)
40
-
41
- assert_equal(nil, d.instance.password)
42
- end
43
-
44
- test 'proxy' do
45
- d = create_driver TEST_DEFAULT_VALUE_CONFIG
46
- assert_equal("test", d.instance.tag)
47
-
48
- assert_equal(nil, d.instance.proxy)
49
- end
50
-
51
- test 'http_method' do
52
- d = create_driver TEST_DEFAULT_VALUE_CONFIG
53
- assert_equal("test", d.instance.tag)
54
-
55
- assert_equal(:get, d.instance.http_method)
56
- end
57
-
58
- test 'agent' do
59
- d = create_driver TEST_DEFAULT_VALUE_CONFIG
60
- assert_equal("test", d.instance.tag)
61
-
62
- assert_equal("fluent-plugin-http-pull", d.instance.agent)
63
- end
64
- end
65
-
66
- private
67
-
68
- def create_driver(conf)
69
- Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpPullInput).configure(conf)
70
- end
71
- end
1
+ require "helper"
2
+ require "fluent/plugin/in_http_pull.rb"
3
+
4
+ require 'ostruct'
5
+
6
+ class HttpPullInputTestDefaultOptions < Test::Unit::TestCase
7
+ sub_test_case "default value of each options" do
8
+ TEST_DEFAULT_VALUE_CONFIG = %[
9
+ tag test
10
+ url http://localhost:3939
11
+
12
+ interval 3s
13
+ format json
14
+ ]
15
+
16
+ test 'status_only' do
17
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
18
+ assert_equal("test", d.instance.tag)
19
+
20
+ assert_equal(false, d.instance.status_only)
21
+ end
22
+
23
+ test 'timeout' do
24
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
25
+ assert_equal("test", d.instance.tag)
26
+
27
+ assert_equal(10, d.instance.timeout)
28
+ end
29
+
30
+ test 'user' do
31
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
32
+ assert_equal("test", d.instance.tag)
33
+
34
+ assert_equal(nil, d.instance.user)
35
+ end
36
+
37
+ test 'password' do
38
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
39
+ assert_equal("test", d.instance.tag)
40
+
41
+ assert_equal(nil, d.instance.password)
42
+ end
43
+
44
+ test 'proxy' do
45
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
46
+ assert_equal("test", d.instance.tag)
47
+
48
+ assert_equal(nil, d.instance.proxy)
49
+ end
50
+
51
+ test 'http_method' do
52
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
53
+ assert_equal("test", d.instance.tag)
54
+
55
+ assert_equal(:get, d.instance.http_method)
56
+ end
57
+
58
+ test 'agent' do
59
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
60
+ assert_equal("test", d.instance.tag)
61
+
62
+ assert_equal("fluent-plugin-http-pull", d.instance.agent)
63
+ end
64
+
65
+ test 'verify_ssl' do
66
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
67
+ assert_equal("test", d.instance.tag)
68
+
69
+ assert_equal(true, d.instance.verify_ssl)
70
+ end
71
+
72
+ test 'ca_path' do
73
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
74
+ assert_equal("test", d.instance.tag)
75
+
76
+ assert_equal(nil, d.instance.ca_path)
77
+ end
78
+
79
+ test 'ca_file' do
80
+ d = create_driver TEST_DEFAULT_VALUE_CONFIG
81
+ assert_equal("test", d.instance.tag)
82
+
83
+ assert_equal(nil, d.instance.ca_file)
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def create_driver(conf)
90
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpPullInput).configure(conf)
91
+ end
92
+ end
@@ -1,116 +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
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://localhost: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://localhost: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://localhost: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://localhost: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://localhost: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://localhost: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
@@ -1,227 +1,228 @@
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
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://localhost: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://localhost:3939
31
+
32
+ interval 5s
33
+ format json
34
+ ]
35
+
36
+ TEST_INTERVAL_3_REDIRECT_CONFIG = %[
37
+ tag test
38
+ url http://localhost: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://localhost: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://localhost: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://localhost: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://localhost: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://localhost: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://localhost: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://localhost: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://localhost:5927
165
+ interval 1s
166
+ timeout 1s
167
+
168
+ format json
169
+ ]
170
+ test "connection refused by remote" do
171
+ d = create_driver TEST_REFUSED_CONFIG
172
+ assert_equal("test", d.instance.tag)
173
+
174
+ d.run(timeout: 4) do
175
+ sleep 3
176
+ end
177
+
178
+ assert_equal(3, d.events.size)
179
+ d.events.each do |tag, time, record|
180
+ assert_equal("test", tag)
181
+
182
+ assert_equal("http://localhost:5927", record["url"])
183
+ assert(time.is_a?(Fluent::EventTime))
184
+
185
+ assert_equal(0, record["status"])
186
+ assert_not_nil(record["error"])
187
+ end
188
+ end
189
+ end
190
+
191
+ sub_test_case "fail when remote timeout" do
192
+ TEST_TIMEOUT_FAIL_CONFIG = %[
193
+ tag test
194
+ url http://localhost:3939/timeout
195
+ timeout 2s
196
+
197
+ interval 3s
198
+ format json
199
+ ]
200
+
201
+ test "timeout" do
202
+ d = create_driver TEST_TIMEOUT_FAIL_CONFIG
203
+ assert_equal("test", d.instance.tag)
204
+ assert_equal(2, d.instance.timeout)
205
+
206
+ d.run(timeout: 8) do
207
+ sleep 7
208
+ end
209
+ assert_equal(2, d.events.size)
210
+
211
+ d.events.each do |tag, time, record|
212
+ assert_equal("test", tag)
213
+
214
+ assert_equal("http://localhost:3939/timeout", record["url"])
215
+ assert(time.is_a?(Fluent::EventTime))
216
+
217
+ assert_equal(0, record["status"])
218
+ assert_not_nil(record["error"])
219
+ end
220
+ end
221
+ end
222
+
223
+ private
224
+
225
+ def create_driver(conf)
226
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpPullInput).configure(conf)
227
+ end
228
+ end