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