|
33 | 33 |
|
34 | 34 | # Now check all events for order and correctness. |
35 | 35 | events = tmp_file.map {|line| LogStash::Event.new(LogStash::Json.load(line))} |
36 | | - sorted = events.sort_by {|e| e['sequence']} |
| 36 | + sorted = events.sort_by {|e| e.get('sequence')} |
37 | 37 | sorted.each do |event| |
38 | | - insist {event["message"]} == "hello world" |
39 | | - insist {event["sequence"]} == line_num |
| 38 | + insist {event.get("message")} == "hello world" |
| 39 | + insist {event.get("sequence")} == line_num |
40 | 40 | line_num += 1 |
41 | 41 | end |
42 | 42 |
|
|
68 | 68 | line_num = 0 |
69 | 69 | # Now check all events for order and correctness. |
70 | 70 | events = Zlib::GzipReader.open(tmp_file.path).map {|line| LogStash::Event.new(LogStash::Json.load(line)) } |
71 | | - sorted = events.sort_by {|e| e["sequence"]} |
| 71 | + sorted = events.sort_by {|e| e.get("sequence")} |
72 | 72 | sorted.each do |event| |
73 | | - insist {event["message"]} == "hello world" |
74 | | - insist {event["sequence"]} == line_num |
| 73 | + insist {event.get("message")} == "hello world" |
| 74 | + insist {event.get("sequence")} == line_num |
75 | 75 | line_num += 1 |
76 | 76 | end |
77 | 77 | insist {line_num} == event_count |
|
165 | 165 | context "when trying to write outside the files root directory" do |
166 | 166 | let(:bad_event) do |
167 | 167 | event = LogStash::Event.new |
168 | | - event['error'] = '../uncool/directory' |
| 168 | + event.set('error', '../uncool/directory') |
169 | 169 | event |
170 | 170 | end |
171 | 171 |
|
|
178 | 178 |
|
179 | 179 | # Trying to write outside the file root |
180 | 180 | outside_path = "#{'../' * path.split(File::SEPARATOR).size}notcool" |
181 | | - bad_event["error"] = outside_path |
| 181 | + bad_event.set("error", outside_path) |
182 | 182 |
|
183 | 183 |
|
184 | 184 | output = LogStash::Outputs::File.new(config) |
|
200 | 200 | output = LogStash::Outputs::File.new({ "path" => "/#{path}/%{error}"}) |
201 | 201 | output.register |
202 | 202 |
|
203 | | - bad_event['error'] = encoded_once |
| 203 | + bad_event.set('error', encoded_once) |
204 | 204 | output.receive(bad_event) |
205 | 205 |
|
206 | | - bad_event['error'] = encoded_twice |
| 206 | + bad_event.set('error', encoded_twice) |
207 | 207 | output.receive(bad_event) |
208 | 208 |
|
209 | 209 | expect(Dir.glob(File.join(path, "*")).size).to eq(2) |
|
216 | 216 | output = LogStash::Outputs::File.new({ "path" => "/#{path}/%{error}"}) |
217 | 217 | output.register |
218 | 218 |
|
219 | | - bad_event['error'] = '../..//test' |
| 219 | + bad_event.set('error', '../..//test') |
220 | 220 | output.receive(bad_event) |
221 | 221 |
|
222 | 222 | expect(Dir.glob(File.join(path, "*")).size).to eq(1) |
|
228 | 228 | context 'when trying to write inside the file root directory' do |
229 | 229 | it 'write the event to the generated filename' do |
230 | 230 | good_event = LogStash::Event.new |
231 | | - good_event['error'] = '42.txt' |
| 231 | + good_event.set('error', '42.txt') |
232 | 232 |
|
233 | 233 | Stud::Temporary.directory do |path| |
234 | 234 | config = { "path" => "#{path}/%{error}" } |
235 | 235 | output = LogStash::Outputs::File.new(config) |
236 | 236 | output.register |
237 | 237 | output.receive(good_event) |
238 | 238 |
|
239 | | - good_file = File.join(path, good_event['error']) |
| 239 | + good_file = File.join(path, good_event.get('error')) |
240 | 240 | expect(File.exist?(good_file)).to eq(true) |
241 | 241 | output.close |
242 | 242 | end |
|
284 | 284 |
|
285 | 285 | it 'write the event to the generated filename with multiple deep' do |
286 | 286 | good_event = LogStash::Event.new |
287 | | - good_event['error'] = '/inside/errors/42.txt' |
| 287 | + good_event.set('error', '/inside/errors/42.txt') |
288 | 288 |
|
289 | 289 | Stud::Temporary.directory do |path| |
290 | 290 | config = { "path" => "#{path}/%{error}" } |
291 | 291 | output = LogStash::Outputs::File.new(config) |
292 | 292 | output.register |
293 | 293 | output.receive(good_event) |
294 | 294 |
|
295 | | - good_file = File.join(path, good_event['error']) |
| 295 | + good_file = File.join(path, good_event.get('error')) |
296 | 296 | expect(File.exist?(good_file)).to eq(true) |
297 | 297 | output.close |
298 | 298 | end |
|
303 | 303 | context "when using default configuration" do |
304 | 304 | it 'write the event as a json line' do |
305 | 305 | good_event = LogStash::Event.new |
306 | | - good_event['message'] = 'hello world' |
| 306 | + good_event.set('message', 'hello world') |
307 | 307 |
|
308 | 308 | Stud::Temporary.directory do |path| |
309 | 309 | config = { "path" => "#{path}/output.txt" } |
|
315 | 315 | output.close #teardown first to allow reading the file |
316 | 316 | File.open(good_file) {|f| |
317 | 317 | event = LogStash::Event.new(LogStash::Json.load(f.readline)) |
318 | | - expect(event["message"]).to eq("hello world") |
| 318 | + expect(event.get("message")).to eq("hello world") |
319 | 319 | } |
320 | 320 | end |
321 | 321 | end |
322 | 322 | end |
323 | 323 | context "when using line codec" do |
324 | 324 | it 'writes event using specified format' do |
325 | 325 | good_event = LogStash::Event.new |
326 | | - good_event['message'] = "hello world" |
| 326 | + good_event.set('message', "hello world") |
327 | 327 |
|
328 | 328 | Stud::Temporary.directory do |path| |
329 | 329 | config = { "path" => "#{path}/output.txt" } |
|
344 | 344 | context "when using deprecated message_format config" do |
345 | 345 | it 'falls back to line codec' do |
346 | 346 | good_event = LogStash::Event.new |
347 | | - good_event['message'] = 'hello world' |
| 347 | + good_event.set('message', 'hello world') |
348 | 348 |
|
349 | 349 | Stud::Temporary.directory do |path| |
350 | 350 | config = { "path" => "#{path}/output.txt", "message_format" => "Custom format: %{message}" } |
|
364 | 364 | context "when using file and dir modes" do |
365 | 365 | it 'dirs and files are created with correct atypical permissions' do |
366 | 366 | good_event = LogStash::Event.new |
367 | | - good_event['message'] = "hello world" |
| 367 | + good_event.set('message', "hello world") |
368 | 368 |
|
369 | 369 | Stud::Temporary.directory do |path| |
370 | 370 | config = { |
|
385 | 385 | output.close #teardown first to allow reading the file |
386 | 386 | File.open(good_file) {|f| |
387 | 387 | event = LogStash::Event.new(LogStash::Json.load(f.readline)) |
388 | | - expect(event["message"]).to eq("hello world") |
| 388 | + expect(event.get("message")).to eq("hello world") |
389 | 389 | } |
390 | 390 | end |
391 | 391 | end |
|
0 commit comments