fluent-plugin-scalyr 0.8.10 → 0.8.15

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.
data/test/test_events.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Scalyr Output Plugin for Fluentd
3
5
  #
@@ -15,234 +17,388 @@
15
17
  # See the License for the specific language governing permissions and
16
18
  # limitations under the License.
17
19
 
18
-
19
- require 'helper'
20
- require 'fluent/event'
20
+ require "helper"
21
+ require "flexmock/test_unit"
22
+ require "fluent/event"
21
23
 
22
24
  class EventsTest < Scalyr::ScalyrOutTest
23
-
24
25
  def test_format
25
26
  d = create_driver
26
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
27
- mock = flexmock( d.instance )
28
- mock.should_receive( :post_request ).with_any_args.and_return( response )
29
-
30
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
31
- d.emit( { "a" => 1 }, time )
32
- d.expect_format [ "test", time, { "a" => 1 } ].to_msgpack
33
- d.run
27
+
28
+ time = event_time("2015-04-01 10:00:00 UTC")
29
+
30
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
31
+ mock = flexmock(d.instance)
32
+ mock.should_receive(:post_request).with_any_args.and_return(response)
33
+
34
+ d.run(default_tag: "test") do
35
+ d.feed(time, {"a" => 1})
36
+ end
37
+
38
+ expected = [
39
+ ["test", time.sec, time.nsec, {"a" => 1}].to_msgpack
40
+ ]
41
+
42
+ assert_equal(expected, d.formatted)
34
43
  end
35
44
 
36
45
  def test_build_add_events_body_basic_values
37
46
  d = create_driver
38
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
39
- mock = flexmock( d.instance )
40
47
 
41
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
42
- attrs = { "a" => 1 }
43
- d.emit( attrs, time )
48
+ time = event_time("2015-04-01 10:00:00 UTC")
49
+ attrs = {"a" => 1}
50
+ attrs["logfile"] = "/fluentd/test"
51
+
52
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
53
+ mock = flexmock(d.instance)
44
54
 
45
- attrs["logfile"] = "/fluentd/test";
55
+ mock_called = false
46
56
 
47
- mock.should_receive( :post_request ).with(
57
+ mock.should_receive(:post_request).with(
48
58
  URI,
49
- on { |request_body|
50
- body = JSON.parse( request_body )
51
- assert( body.key?( "token" ), "Missing token field" )
52
- assert( body.key?( "client_timestamp" ), "Missing client_timestamp field" )
53
- assert( body.key?( "session" ), "Missing session field" )
54
- assert( !body.key?( "sessionInfo"), "sessionInfo field set, but no sessionInfo" )
55
- assert( body.key?( "events" ), "missing events field" )
56
- assert( body.key?( "threads" ), "missing threads field" )
57
- assert_equal( 1, body['events'].length, "Only expecting 1 event" )
58
- assert_equal( d.instance.to_nanos( time ), body['events'][0]['ts'].to_i, "Event timestamp differs" )
59
- assert_equal( attrs, body['events'][0]['attrs'], "Value of attrs differs from log" )
60
- true
59
+ on {|request_body|
60
+ body = JSON.parse(request_body)
61
+ assert(body.key?("token"), "Missing token field")
62
+ assert(body.key?("client_timestamp"), "Missing client_timestamp field")
63
+ assert(body.key?("sessionInfo"), "sessionInfo field set, but no sessionInfo")
64
+ assert(body.key?("events"), "missing events field")
65
+ assert(body.key?("threads"), "missing threads field")
66
+ assert_equal(1, body["events"].length, "Only expecting 1 event")
67
+ assert_equal(time.sec * 1_000_000_000, body["events"][0]["ts"].to_i,
68
+ "Event timestamp differs")
69
+ assert_equal(attrs, body["events"][0]["attrs"], "Value of attrs differs from log")
70
+ mock_called = true
61
71
  }
62
- ).and_return( response )
72
+ ).once.and_return(response)
73
+
74
+ d.run(default_tag: "test") do
75
+ d.feed(time, attrs)
76
+ end
63
77
 
64
- d.run
78
+ assert_equal(mock_called, true, "mock method was never called!")
65
79
  end
66
80
 
67
81
  def test_build_add_events_body_dont_override_logfile_field
68
82
  d = create_driver
69
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
70
- mock = flexmock( d.instance )
71
83
 
72
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
73
- attrs = { "a" => 1 }
74
- attrs["logfile"] = "/some/log/file";
75
- d.emit( attrs, time )
84
+ time = event_time("2015-04-01 10:00:00 UTC")
85
+ attrs = {"a" => 1}
86
+ attrs["logfile"] = "/some/log/file"
76
87
 
77
- mock.should_receive( :post_request ).with(
88
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
89
+ mock = flexmock(d.instance)
90
+
91
+ mock_called = false
92
+
93
+ mock.should_receive(:post_request).with(
78
94
  URI,
79
- on { |request_body|
80
- body = JSON.parse( request_body )
81
- assert_equal( attrs, body['events'][0]['attrs'], "Value of attrs differs from log" )
95
+ on {|request_body|
96
+ body = JSON.parse(request_body)
97
+ assert_equal(attrs, body["events"][0]["attrs"], "Value of attrs differs from log")
98
+ mock_called = true
82
99
  true
83
100
  }
84
- ).and_return( response )
101
+ ).once.and_return(response)
102
+
103
+ d.run(default_tag: "test") do
104
+ d.feed(time, attrs)
105
+ end
85
106
 
86
- d.run
107
+ assert_equal(mock_called, true, "mock method was never called!")
87
108
  end
88
109
 
89
110
  def test_build_add_events_body_with_server_attributes
90
111
  d = create_driver CONFIG + 'server_attributes { "test":"value" }'
91
112
 
92
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
93
- mock = flexmock( d.instance )
113
+ time = event_time("2015-04-01 10:00:00 UTC")
114
+ attrs = {"a" => 1}
94
115
 
95
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
96
- attrs = { "a" => 1 }
97
- d.emit( attrs, time )
116
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
117
+ mock = flexmock(d.instance)
98
118
 
99
- mock.should_receive( :post_request ).with(
119
+ mock_called = false
120
+
121
+ mock.should_receive(:post_request).with(
100
122
  URI,
101
- on { |request_body|
102
- body = JSON.parse( request_body )
103
- assert( body.key?( "sessionInfo"), "sessionInfo field set, but no sessionInfo" )
104
- assert_equal( "value", body["sessionInfo"]["test"] )
123
+ on {|request_body|
124
+ body = JSON.parse(request_body)
125
+ assert(body.key?("sessionInfo"), "sessionInfo field set, but no sessionInfo")
126
+ assert_equal("value", body["sessionInfo"]["test"])
127
+ mock_called = true
105
128
  true
106
129
  }
107
- ).and_return( response )
130
+ ).once.and_return(response)
131
+
132
+ d.run(default_tag: "test") do
133
+ d.feed(time, attrs)
134
+ end
108
135
 
109
- d.run
136
+ assert_equal(mock_called, true, "mock method was never called!")
110
137
  end
111
138
 
112
- def test_build_add_events_body_incrementing_timestamps
113
- d = create_driver
114
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
115
- mock = flexmock( d.instance )
139
+ def test_build_add_events_body_with_parser
140
+ d = create_driver CONFIG + "parser test_parser"
116
141
 
117
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
118
- d.emit( { "a" => 1 }, time )
119
- d.emit( { "a" => 2 }, time )
142
+ time = event_time("2015-04-01 10:00:00 UTC")
143
+ attrs = {"a" => 1}
120
144
 
121
- time = Time.parse("2015-04-01 09:59:00 UTC").to_i
122
- d.emit( { "a" => 3 }, time )
145
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
146
+ mock = flexmock(d.instance)
123
147
 
124
- mock.should_receive( :post_request ).with(
148
+ mock_called = false
149
+
150
+ mock.should_receive(:post_request).with(
125
151
  URI,
126
- on { |request_body|
127
- body = JSON.parse( request_body )
128
- events = body['events']
129
- assert_equal( 3, events.length, "Expecting 3 events" )
130
- #test equal timestamps are increased
131
- assert events[1]['ts'].to_i > events[0]['ts'].to_i, "Event timestamps must increase"
152
+ on {|request_body|
153
+ body = JSON.parse(request_body)
154
+ assert_equal("test_parser", body["events"][0]["attrs"]["parser"])
155
+ mock_called = true
156
+ true
157
+ }
158
+ ).once.and_return(response)
159
+
160
+ d.run(default_tag: "test") do
161
+ d.feed(time, attrs)
162
+ end
163
+
164
+ assert_equal(mock_called, true, "mock method was never called!")
165
+ end
166
+
167
+ def test_build_add_events_body_incrementing_timestamps
168
+ d = create_driver
132
169
 
133
- #test earlier timestamps are increased
134
- assert events[2]['ts'].to_i > events[1]['ts'].to_i, "Event timestamps must increase"
170
+ time1 = event_time("2015-04-01 10:00:00 UTC")
171
+ time2 = event_time("2015-04-01 09:59:00 UTC")
135
172
 
173
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
174
+ mock = flexmock(d.instance)
175
+
176
+ mock_called = false
177
+
178
+ mock.should_receive(:post_request).with(
179
+ URI,
180
+ on {|request_body|
181
+ body = JSON.parse(request_body)
182
+ events = body["events"]
183
+ assert_equal(3, events.length, "Expecting 3 events")
184
+ # Since 0.8.10 timestamps dont need to increase anymore
185
+ assert events[1]["ts"].to_i == events[0]["ts"].to_i, "Event timestamps must be the same"
186
+ assert events[2]["ts"].to_i < events[0]["ts"].to_i, "Event timestamps must be less"
187
+ mock_called = true
136
188
  true
137
189
  }
138
- ).and_return( response )
190
+ ).once.and_return(response)
191
+
192
+ d.run(default_tag: "test") do
193
+ d.feed(time1, {"a" => 1})
194
+ d.feed(time1, {"a" => 2})
195
+ d.feed(time2, {"a" => 3})
196
+ end
139
197
 
140
- d.run
198
+ assert_equal(mock_called, true, "mock method was never called!")
141
199
  end
142
200
 
143
- def test_build_add_events_body_thread_ids
201
+ def test_build_add_events_body_non_json_serializable_value
144
202
  d = create_driver
145
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
146
- mock = flexmock( d.instance )
147
203
 
148
- entries = []
204
+ time = event_time("2015-04-01 10:00:00 UTC")
205
+ attrs = {"a" => 1}
206
+ attrs["int1"] = 1_601_923_119
207
+ attrs["int2"] = Integer(1_601_923_119)
208
+ attrs["int3"] = Integer(9_223_372_036_854_775_807)
209
+ attrs["int4"] = Integer(-1)
210
+ attrs["nil"] = nil
211
+ attrs["array"] = [1, 2, "a", "b", nil]
212
+ attrs["hash"] = {
213
+ "a" => "1",
214
+ "b" => "c"
215
+ }
216
+ attrs["logfile"] = "/some/log/file"
217
+
218
+ # This partial unicode sequence will fail encoding so we make sure it doesn't break the plugin
219
+ # and we correctly cast it to a value which we can send to the API
220
+ attrs["partial_unicode_sequence"] = "\xC2"
221
+ attrs["array_with_partial_unicode_sequence"] = [1, 2, "a", "b", nil, "7", "\xC2"]
222
+ attrs["nested_array_with_partial_unicode_sequence"] = [1, 2, "a", "b", nil, "7",
223
+ [8, 9, [10, "\xC2"]],
224
+ {"a" => 1, "b" => "\xC2"}]
225
+ attrs["hash_with_partial_unicode_sequence"] = {
226
+ "a" => "1",
227
+ "b" => "\xC2",
228
+ "c" => nil
229
+ }
230
+ attrs["nested_hash_with_partial_unicode_sequence"] = {
231
+ "a" => "1",
232
+ "b" => {
233
+ "c" => "\xC2",
234
+ "d" => "e",
235
+ "f" => nil,
236
+ "g" => {
237
+ "h" => "\xC2",
238
+ "b" => 3
239
+ }
240
+ }
241
+ }
242
+
243
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
244
+ mock = flexmock(d.instance)
149
245
 
150
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
151
- entries << [time, { "a" => 1 }]
246
+ mock_called = false
152
247
 
153
- es = Fluent::ArrayEventStream.new(entries)
154
- buffer = d.instance.format_stream("test1", es)
248
+ # NOTE: We need to perform a deep clone / copy
249
+ expected_attrs = Marshal.load(Marshal.dump(attrs))
155
250
 
156
- chunk = d.instance.buffer.new_chunk('')
157
- chunk << buffer
251
+ expected_attrs["partial_unicode_sequence"] = "<?>"
252
+ expected_attrs["array_with_partial_unicode_sequence"][-1] = "<?>"
253
+ expected_attrs["nested_array_with_partial_unicode_sequence"][-2][-1][-1] = "<?>"
254
+ expected_attrs["nested_array_with_partial_unicode_sequence"][-1]["b"] = "<?>"
255
+ expected_attrs["hash_with_partial_unicode_sequence"]["b"] = "<?>"
256
+ expected_attrs["nested_hash_with_partial_unicode_sequence"]["b"]["c"] = "<?>"
257
+ expected_attrs["nested_hash_with_partial_unicode_sequence"]["b"]["g"]["h"] = "<?>"
158
258
 
159
- buffer = d.instance.format_stream("test2", es)
160
- chunk << buffer
259
+ # Verify that clone / copy was correct and the original object wasn't modified
260
+ assert_not_equal(expected_attrs, attrs, "Objects are the same but should be different")
261
+ assert_not_equal(Marshal.load(Marshal.dump(attrs)), Marshal.load(Marshal.dump(expected_attrs)))
262
+ assert_equal(attrs["partial_unicode_sequence"], "\xC2")
263
+ assert_equal(attrs["array_with_partial_unicode_sequence"][-1], "\xC2")
264
+ assert_equal(attrs["nested_hash_with_partial_unicode_sequence"]["b"]["g"]["h"], "\xC2")
161
265
 
162
- mock.should_receive( :post_request ).with(
266
+ mock.should_receive(:post_request).with(
163
267
  URI,
164
- on { |request_body|
165
- body = JSON.parse( request_body )
166
- events = body['events']
167
- threads = body['threads']
168
-
169
- assert_equal( 2, threads.length, "Expecting 2 threads, #{threads.length} found" )
170
- assert_equal( 2, events.length, "Expecting 2 events, #{events.length} found" )
171
- assert_equal( events[0]['thread'], threads[0]['id'].to_s, "thread id should match event thread id" )
172
- assert_equal( events[1]['thread'], threads[1]['id'].to_s, "thread id should match event thread id" )
268
+ on {|request_body|
269
+ body = JSON.parse(request_body)
270
+ assert_equal(expected_attrs, body["events"][0]["attrs"], "Value of attrs differs from log")
271
+ mock_called = true
173
272
  true
174
273
  }
175
- ).at_least.once.and_return( response )
274
+ ).once.and_return(response)
275
+
276
+ d.run(default_tag: "test") do
277
+ d.feed(time, attrs)
278
+ end
176
279
 
177
- d.instance.start
178
- d.instance.write( chunk )
179
- d.instance.shutdown
280
+ assert_equal(mock_called, true, "mock method was never called!")
180
281
  end
181
282
 
182
283
  def test_default_message_field
183
284
  d = create_driver CONFIG
184
285
 
185
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
186
- mock = flexmock( d.instance )
286
+ time = event_time("2015-04-01 10:00:00 UTC")
287
+ attrs = {"log" => "this is a test", "logfile" => "/fluentd/test"}
187
288
 
188
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
189
- attrs = { "log" => "this is a test", "logfile" => "/fluentd/test" }
190
- d.emit( attrs, time )
289
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
290
+ mock = flexmock(d.instance)
191
291
 
192
- mock.should_receive( :post_request ).with(
292
+ mock_called = false
293
+
294
+ mock.should_receive(:post_request).with(
193
295
  URI,
194
- on { |request_body|
195
- body = JSON.parse( request_body )
196
- events = body['events']
197
- assert_equal( attrs, body['events'][0]['attrs'], "Value of attrs differs from log" )
296
+ on {|request_body|
297
+ body = JSON.parse(request_body)
298
+ assert_equal(attrs, body["events"][0]["attrs"], "Value of attrs differs from log")
299
+ mock_called = true
198
300
  true
199
301
  }
200
- ).and_return( response )
302
+ ).once.and_return(response)
303
+
304
+ d.run(default_tag: "test") do
305
+ d.feed(time, attrs)
306
+ end
201
307
 
202
- d.run
308
+ assert_equal(mock_called, true, "mock method was never called!")
203
309
  end
204
310
 
205
311
  def test_different_message_field
206
- d = create_driver CONFIG + 'message_field log'
312
+ d = create_driver CONFIG + "message_field log"
207
313
 
208
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
209
- mock = flexmock( d.instance )
314
+ time = event_time("2015-04-01 10:00:00 UTC")
315
+ attrs = {"log" => "this is a test"}
210
316
 
211
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
212
- attrs = { "log" => "this is a test" }
213
- d.emit( attrs, time )
317
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
318
+ mock = flexmock(d.instance)
214
319
 
215
- mock.should_receive( :post_request ).with(
320
+ mock_called = false
321
+
322
+ mock.should_receive(:post_request).with(
216
323
  URI,
217
- on { |request_body|
218
- body = JSON.parse( request_body )
219
- events = body['events']
220
- assert( events[0]['attrs'].key?( 'message'), "'message' field not found in event" )
221
- assert_equal( "this is a test", events[0]['attrs']['message'], "'message' field incorrect" )
222
- assert( !events[0]['attrs'].key?( 'log' ), "'log' field should no longer exist in event" )
324
+ on {|request_body|
325
+ body = JSON.parse(request_body)
326
+ events = body["events"]
327
+ assert(events[0]["attrs"].key?("message"), "'message' field not found in event")
328
+ assert_equal("this is a test", events[0]["attrs"]["message"], "'message' field incorrect")
329
+ assert(!events[0]["attrs"].key?("log"), "'log' field should no longer exist in event")
330
+ mock_called = true
223
331
  true
224
332
  }
225
- ).and_return( response )
333
+ ).once.and_return(response)
334
+
335
+ d.run(default_tag: "test") do
336
+ d.feed(time, attrs)
337
+ end
226
338
 
227
- d.run
339
+ assert_equal(mock_called, true, "mock method was never called!")
228
340
  end
229
341
 
230
342
  def test_different_message_field_message_already_exists
231
- d = create_driver CONFIG + 'message_field log'
343
+ d = create_driver CONFIG + "message_field log"
232
344
 
233
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
234
- mock = flexmock( d.instance )
235
- mock.should_receive( :post_request ).and_return( response )
345
+ time = event_time("2015-04-01 10:00:00 UTC")
346
+ attrs = {"log" => "this is a test", "message" => "uh oh"}
236
347
 
237
- time = Time.parse("2015-04-01 10:00:00 UTC").to_i
238
- attrs = { "log" => "this is a test", "message" => "uh oh" }
239
- d.emit( attrs, time )
348
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
349
+ mock = flexmock(d.instance)
240
350
 
241
- logger = flexmock( $log )
242
- logger.should_receive( :warn ).with( /overwriting log record field 'message'/i ).at_least().once()
351
+ mock.should_receive(:post_request).once.and_return(response)
243
352
 
244
- d.run
353
+ logger = flexmock($log)
354
+ logger.should_receive(:warn).with(/overwriting log record field 'message'/i).at_least.once
355
+
356
+ d.run(default_tag: "test") do
357
+ d.feed(time, attrs)
358
+ end
245
359
  end
246
360
 
247
- end
361
+ def test_truncated_large_event
362
+ d = create_driver CONFIG + "max_request_buffer 4000"
363
+
364
+ time = event_time("2015-04-01 10:00:00 UTC")
365
+ attrs = {"log" => "this is a test", "message" => "0123456789" * 500}
248
366
 
367
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
368
+ mock = flexmock(d.instance)
369
+
370
+ mock.should_receive(:post_request).with(
371
+ URI,
372
+ on {|request_body|
373
+ body = JSON.parse(request_body)
374
+ events = body["events"]
375
+ assert(events[0]["attrs"].key?("message"), "'message' field not found in event")
376
+ assert_equal(
377
+ "0123456789" * 388 + "012...",
378
+ events[0]["attrs"]["message"],
379
+ "'message' field incorrect"
380
+ )
381
+ true
382
+ }
383
+ ).once.and_return(response)
384
+
385
+ d.run(default_tag: "test") do
386
+ d.feed(time, attrs)
387
+ end
388
+ end
389
+
390
+ def test_dropped_large_event
391
+ d = create_driver CONFIG + "max_request_buffer 4000"
392
+
393
+ time = event_time("2015-04-01 10:00:00 UTC")
394
+ attrs = {"message" => "this is a test", "not_message" => "0123456789" * 500}
395
+
396
+ mock = flexmock(d.instance)
397
+
398
+ mock.should_receive(:post_request).never
399
+
400
+ d.run(default_tag: "test") do
401
+ d.feed(time, attrs)
402
+ end
403
+ end
404
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Scalyr Output Plugin for Fluentd
3
5
  #
@@ -15,76 +17,73 @@
15
17
  # See the License for the specific language governing permissions and
16
18
  # limitations under the License.
17
19
 
20
+ require "helper"
21
+ require "flexmock/test_unit"
18
22
 
19
- require 'helper'
20
- require 'flexmock/test_unit'
21
-
23
+ # rubocop:disable Layout/LineLength
22
24
  class HandleResponseTest < Scalyr::ScalyrOutTest
23
-
24
25
  def test_handle_response_missing_status
25
26
  d = create_driver
26
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "message":"An invalid message" }' )
27
- exception = assert_raise( Scalyr::ServerError, "Server error not raised for missing status" ) {
28
- d.instance.handle_response( response )
27
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message" }')
28
+ exception = assert_raise(Scalyr::ServerError, "Server error not raised for missing status") {
29
+ d.instance.handle_response(response)
29
30
  }
30
31
 
31
- assert_equal( "JSON response does not contain status message", exception.message )
32
+ assert_equal("JSON response does not contain status message", exception.message)
32
33
  end
33
34
 
34
35
  def test_handle_response_discard_buffer
35
36
  d = create_driver
36
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "message":"An invalid message", "status":"error/server/discardBuffer" }' )
37
- logger = flexmock( $log )
38
- logger.should_receive( :warn ).with( /buffer dropped/i )
39
- assert_nothing_raised( Scalyr::ServerError, Scalyr::ClientError, "Nothing should be raised when discarding the buffer" ) {
40
- d.instance.handle_response( response )
37
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message", "status":"error/server/discardBuffer" }')
38
+ logger = flexmock($log)
39
+ logger.should_receive(:warn).once.with(/buffer dropped/i)
40
+ assert_nothing_raised(Scalyr::ServerError, Scalyr::ClientError, "Nothing should be raised when discarding the buffer") {
41
+ d.instance.handle_response(response)
41
42
  }
42
-
43
43
  end
44
44
 
45
45
  def test_handle_response_unknown_error
46
46
  d = create_driver
47
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "message":"An invalid message", "status":"error/other" }' )
48
- exception = assert_raise( Scalyr::ServerError, "Server error not raised for error status" ) {
49
- d.instance.handle_response( response )
47
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message", "status":"error/other" }')
48
+ exception = assert_raise(Scalyr::ServerError, "Server error not raised for error status") {
49
+ d.instance.handle_response(response)
50
50
  }
51
- assert_equal( "error/other", exception.message )
51
+ assert_equal("error/other", exception.message)
52
52
  end
53
53
 
54
54
  def test_handle_response_client_error
55
55
  d = create_driver
56
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "message":"An invalid message", "status":"error/client/test" }' )
57
- exception = assert_raise( Scalyr::ClientError, "Client error not raised for error status" ) {
58
- d.instance.handle_response( response )
56
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message", "status":"error/client/test" }')
57
+ exception = assert_raise(Scalyr::ClientError, "Client error not raised for error status") {
58
+ d.instance.handle_response(response)
59
59
  }
60
- assert_equal( "error/client/test", exception.message )
60
+ assert_equal("error/client/test", exception.message)
61
61
  end
62
62
 
63
63
  def test_handle_response_server_error
64
64
  d = create_driver
65
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "message":"An invalid message", "status":"error/server/test" }' )
66
- exception = assert_raise( Scalyr::ServerError, "Server error not raised for error status" ) {
67
- d.instance.handle_response( response )
65
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "message":"An invalid message", "status":"error/server/test" }')
66
+ exception = assert_raise(Scalyr::ServerError, "Server error not raised for error status") {
67
+ d.instance.handle_response(response)
68
68
  }
69
- assert_equal( "error/server/test", exception.message )
69
+ assert_equal("error/server/test", exception.message)
70
70
  end
71
71
 
72
72
  def test_handle_response_code_4xx
73
73
  d = create_driver
74
- response = flexmock( Net::HTTPResponse, :code => '404', :body =>'{ "status":"error/server/fileNotFound" }' )
75
- exception = assert_raise( Scalyr::Client4xxError, "No 4xx exception raised" ) {
76
- d.instance.handle_response( response )
74
+ response = flexmock(Net::HTTPResponse, code: "404", body: '{ "status":"error/server/fileNotFound" }')
75
+ exception = assert_raise(Scalyr::Client4xxError, "No 4xx exception raised") {
76
+ d.instance.handle_response(response)
77
77
  }
78
- assert_equal( "error/server/fileNotFound", exception.message )
78
+ assert_equal("error/server/fileNotFound", exception.message)
79
79
  end
80
80
 
81
81
  def test_handle_response_code_200
82
82
  d = create_driver
83
- response = flexmock( Net::HTTPResponse, :code => '200', :body =>'{ "status":"success" }' )
84
- exception = assert_nothing_raised( Scalyr::ServerError, Scalyr::ClientError, "Error raised on success" ) {
85
- d.instance.handle_response( response )
83
+ response = flexmock(Net::HTTPResponse, code: "200", body: '{ "status":"success" }')
84
+ assert_nothing_raised(Scalyr::ServerError, Scalyr::ClientError, "Error raised on success") {
85
+ d.instance.handle_response(response)
86
86
  }
87
87
  end
88
-
89
88
  end
90
-
89
+ # rubocop:enable Layout/LineLength