systemd-journal 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -4
- data/Rakefile +2 -4
- data/lib/systemd/id128.rb +7 -9
- data/lib/systemd/journal/native.rb +1 -1
- data/lib/systemd/journal/navigable.rb +1 -1
- data/lib/systemd/journal/version.rb +1 -1
- data/lib/systemd/journal.rb +0 -5
- data/spec/fixtures/test.journal +0 -0
- data/spec/fixtures/test.json +463 -0
- data/spec/spec_helper.rb +21 -32
- data/spec/systemd/journal_spec.rb +73 -489
- data/systemd-journal.gemspec +6 -2
- metadata +70 -17
- data/.travis.yml +0 -5
- data/spec/no_ffi.rb +0 -4
- data/spec/systemd/id128_spec.rb +0 -39
- data/spec/systemd/journal_entry_spec.rb +0 -97
data/spec/spec_helper.rb
CHANGED
@@ -1,43 +1,32 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'json'
|
2
3
|
require 'simplecov'
|
3
4
|
|
5
|
+
module SpecHelper
|
6
|
+
def fixture_dir
|
7
|
+
@path ||= File.join(File.expand_path(__dir__), 'fixtures')
|
8
|
+
end
|
9
|
+
|
10
|
+
def journal_file
|
11
|
+
@file ||= File.join(fixture_dir, 'test.journal')
|
12
|
+
end
|
13
|
+
|
14
|
+
def journal_json
|
15
|
+
@json ||= JSON.parse(File.read(File.join(fixture_dir, 'test.json')))
|
16
|
+
end
|
17
|
+
|
18
|
+
def entry_field(index, name)
|
19
|
+
journal_json[index][name.to_s.upcase]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
4
23
|
SimpleCov.start do
|
5
24
|
add_filter '.bundle/'
|
6
25
|
end
|
7
26
|
require 'systemd/journal'
|
8
27
|
|
9
28
|
RSpec.configure do |config|
|
10
|
-
config.before(:each) do
|
11
|
-
|
12
|
-
# Stub open and close calls
|
13
|
-
dummy_open = ->(ptr, flags, path = nil) do
|
14
|
-
ptr.write_pointer(nil)
|
15
|
-
0
|
16
|
-
end
|
17
|
-
|
18
|
-
['', '_directory', '_files', '_container'].each do |suffix|
|
19
|
-
Systemd::Journal::Native.stub(:"sd_journal_open#{suffix}", &dummy_open)
|
20
|
-
end
|
21
|
-
Systemd::Journal::Native.stub(:sd_journal_close).and_return(0)
|
22
|
-
|
23
|
-
# Raise an exception if any native calls are actually called
|
24
|
-
native_calls = Systemd::Journal::Native.methods.select do |m|
|
25
|
-
m.to_s.start_with?('sd_')
|
26
|
-
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
:sd_journal_open_files, :sd_journal_open_container
|
31
|
-
]
|
32
|
-
|
33
|
-
build_err_proc = ->(method_name) do
|
34
|
-
return ->(*params) do
|
35
|
-
raise RuntimeError.new("#{method_name} called without being stubbed.")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
native_calls.each do |meth|
|
40
|
-
Systemd::Journal::Native.stub(meth, &build_err_proc.call(meth))
|
41
|
-
end
|
42
|
-
end
|
30
|
+
config.disable_monkey_patching!
|
31
|
+
config.include SpecHelper
|
43
32
|
end
|
@@ -1,556 +1,140 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Systemd::Journal do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Systemd::Journal::Native.should_not_receive(:sd_journal_open)
|
9
|
-
Systemd::Journal.new(path: '/path/to/journal')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'accepts flags as an argument' do
|
13
|
-
Systemd::Journal::Native.should_receive(:sd_journal_open)
|
14
|
-
.with(anything, 1234)
|
15
|
-
|
16
|
-
Systemd::Journal.new(flags: 1234)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'accepts a files argument to open specific files' do
|
20
|
-
Systemd::Journal::Native.should_receive(:sd_journal_open_files)
|
21
|
-
Systemd::Journal.new(files: ['/path/to/journal/1', '/path/to/journal/2'])
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'accepts a machine name to open a container' do
|
25
|
-
Systemd::Journal::Native.should_receive(:sd_journal_open_container)
|
26
|
-
Systemd::Journal.new(container: 'bobs-machine')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'raises a Journal Error if a native call fails' do
|
30
|
-
Systemd::Journal::Native.should_receive(:sd_journal_open).and_return(-1)
|
31
|
-
expect { Systemd::Journal.new }.to raise_error(Systemd::JournalError)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'raises an argument error if conflicting options are passed' do
|
35
|
-
expect do
|
36
|
-
Systemd::Journal.new(path: 'p', files: %w{a b})
|
37
|
-
end.to raise_error(ArgumentError)
|
38
|
-
expect do
|
39
|
-
Systemd::Journal.new(container: 'c', files: %w{a b})
|
40
|
-
end.to raise_error(ArgumentError)
|
3
|
+
RSpec.describe Systemd::Journal do
|
4
|
+
subject(:j) do
|
5
|
+
Systemd::Journal.new(files: [journal_file]).tap do |j|
|
6
|
+
j.seek(:head)
|
7
|
+
j.move_next
|
41
8
|
end
|
42
9
|
end
|
43
10
|
|
44
|
-
describe '
|
45
|
-
|
46
|
-
j = Systemd::Journal.new
|
47
|
-
j.should_receive(:move_next_skip).with(5)
|
48
|
-
j.move(5)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'calls move_next_previous otherwise' do
|
52
|
-
j = Systemd::Journal.new
|
53
|
-
j.should_receive(:move_previous_skip).with(5)
|
54
|
-
j.move(-5)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
%w{next previous}.each do |direction|
|
59
|
-
describe "#move_#{direction}" do
|
60
|
-
it 'returns true on a successful move' do
|
61
|
-
j = Systemd::Journal.new
|
62
|
-
Systemd::Journal::Native
|
63
|
-
.should_receive(:"sd_journal_#{direction}")
|
64
|
-
.and_return(1)
|
65
|
-
|
66
|
-
j.send(:"move_#{direction}").should eq(true)
|
67
|
-
end
|
11
|
+
describe 'initialize' do
|
12
|
+
subject(:j) { Systemd::Journal }
|
68
13
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
.and_return(0)
|
74
|
-
|
75
|
-
j.send(:"move_#{direction}").should eq(false)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'raises an exception on failure' do
|
79
|
-
j = Systemd::Journal.new
|
80
|
-
Systemd::Journal::Native
|
81
|
-
.should_receive(:"sd_journal_#{direction}")
|
82
|
-
.and_return(-1)
|
83
|
-
|
84
|
-
expect do
|
85
|
-
j.send(:"move_#{direction}")
|
86
|
-
end.to raise_error(Systemd::JournalError)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "#move_#{direction}_skip" do
|
91
|
-
it 'returns the number of records moved by' do
|
92
|
-
Systemd::Journal::Native
|
93
|
-
.should_receive(:"sd_journal_#{direction}_skip")
|
94
|
-
.with(anything, 10)
|
95
|
-
.and_return(10)
|
96
|
-
|
97
|
-
Systemd::Journal.new.send(:"move_#{direction}_skip", 10).should eq(10)
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'raises an exception on failure' do
|
101
|
-
Systemd::Journal::Native
|
102
|
-
.should_receive(:"sd_journal_#{direction}_skip")
|
103
|
-
.with(anything, 10)
|
104
|
-
.and_return(-1)
|
105
|
-
|
106
|
-
j = Systemd::Journal.new
|
107
|
-
|
108
|
-
expect do
|
109
|
-
j.send(:"move_#{direction}_skip", 10)
|
110
|
-
end.to raise_error(Systemd::JournalError)
|
111
|
-
end
|
14
|
+
it 'detects invalid argument combinations' do
|
15
|
+
expect { j.new(path: '/', files: []) }.to raise_error(ArgumentError)
|
16
|
+
expect { j.new(container: '', files: []) }.to raise_error(ArgumentError)
|
17
|
+
expect { j.new(container: '', path: '/') }.to raise_error(ArgumentError)
|
112
18
|
end
|
113
19
|
end
|
114
20
|
|
115
|
-
describe '
|
116
|
-
it '
|
117
|
-
|
118
|
-
j.should_receive(:seek).with(:head).and_return(0)
|
119
|
-
j.stub(:move_next).and_return(nil)
|
120
|
-
j.each { |e| nil }
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should return an enumerator if no block is given' do
|
124
|
-
j = Systemd::Journal.new
|
125
|
-
j.each.class.should eq(Enumerator)
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'should return each entry in the journal' do
|
129
|
-
entries = [{ '_PID' => 1 }, { '_PID' => 2 }]
|
130
|
-
entry = nil
|
131
|
-
|
132
|
-
j = Systemd::Journal.new
|
133
|
-
j.stub(:seek).and_return(0)
|
134
|
-
j.stub(:current_entry) { entry }
|
135
|
-
j.stub(:move_next) { entry = entries.shift }
|
136
|
-
|
137
|
-
j.map { |e| e['_PID'] }.should eq([1, 2])
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
describe '#seek' do
|
143
|
-
it 'moves to the first entry of the file' do
|
144
|
-
j = Systemd::Journal.new
|
145
|
-
Systemd::Journal::Native
|
146
|
-
.should_receive(:sd_journal_seek_head)
|
147
|
-
.and_return(0)
|
148
|
-
|
149
|
-
j.seek(:head).should eq(true)
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'moves to the last entry of the file' do
|
153
|
-
j = Systemd::Journal.new
|
154
|
-
Systemd::Journal::Native
|
155
|
-
.should_receive(:sd_journal_seek_tail)
|
156
|
-
.and_return(0)
|
157
|
-
|
158
|
-
j.seek(:tail).should eq(true)
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'seeks based on time when a time is provided' do
|
162
|
-
j = Systemd::Journal.new
|
163
|
-
Systemd::Journal::Native
|
164
|
-
.should_receive(:sd_journal_seek_realtime_usec)
|
165
|
-
.and_return(0)
|
166
|
-
|
167
|
-
j.seek(Time.now).should eq(true)
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'seeks based on a cursor when a string is provided' do
|
171
|
-
j = Systemd::Journal.new
|
172
|
-
|
173
|
-
Systemd::Journal::Native
|
174
|
-
.should_receive(:sd_journal_seek_cursor)
|
175
|
-
.with(anything, '123')
|
176
|
-
.and_return(0)
|
177
|
-
|
178
|
-
j.seek('123')
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'throws an exception if it doesnt understand the type' do
|
182
|
-
j = Systemd::Journal.new
|
183
|
-
expect { j.seek(Object.new) }.to raise_error(ArgumentError)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
describe '#read_field' do
|
188
|
-
it 'raises an exception if the call fails' do
|
189
|
-
j = Systemd::Journal.new
|
190
|
-
Systemd::Journal::Native
|
191
|
-
.should_receive(:sd_journal_get_data)
|
192
|
-
.and_return(-1)
|
193
|
-
|
194
|
-
expect { j.read_field(:message) }.to raise_error(Systemd::JournalError)
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'parses the returned value correctly.' do
|
198
|
-
j = Systemd::Journal.new
|
199
|
-
Systemd::Journal::Native
|
200
|
-
.should_receive(:sd_journal_get_data) do |ptr, field, out_ptr, len_ptr|
|
201
|
-
dummy = 'MESSAGE=hello world'
|
202
|
-
out_ptr.write_pointer(FFI::MemoryPointer.from_string(dummy))
|
203
|
-
len_ptr.write_size_t(dummy.size)
|
204
|
-
0
|
205
|
-
end
|
206
|
-
|
207
|
-
j.read_field(:message).should eq('hello world')
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe '#current_entry' do
|
212
|
-
before(:each) do
|
213
|
-
Systemd::Journal::Native
|
214
|
-
.should_receive(:sd_journal_restart_data)
|
215
|
-
.and_return(nil)
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'raises an exception if the call fails' do
|
219
|
-
j = Systemd::Journal.new
|
220
|
-
Systemd::Journal::Native
|
221
|
-
.should_receive(:sd_journal_enumerate_data)
|
222
|
-
.and_return(-1)
|
223
|
-
|
224
|
-
expect { j.current_entry }.to raise_error(Systemd::JournalError)
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'returns the correct data' do
|
228
|
-
j = Systemd::Journal.new
|
229
|
-
results = ['_PID=100', 'MESSAGE=hello world']
|
230
|
-
|
231
|
-
Systemd::Journal::Native
|
232
|
-
.should_receive(:sd_journal_enumerate_data)
|
233
|
-
.exactly(3).times do |ptr, out_ptr, len_ptr|
|
234
|
-
if results.any?
|
235
|
-
x = results.shift
|
236
|
-
out_ptr.write_pointer(FFI::MemoryPointer.from_string(x))
|
237
|
-
len_ptr.write_size_t(x.length)
|
238
|
-
1
|
239
|
-
else
|
240
|
-
0
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
entry = j.current_entry
|
245
|
-
|
246
|
-
entry._pid.should eq('100')
|
247
|
-
entry.message.should eq('hello world')
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
describe '#query_unique' do
|
252
|
-
before(:each) do
|
253
|
-
Systemd::Journal::Native
|
254
|
-
.should_receive(:sd_journal_restart_unique)
|
255
|
-
.and_return(nil)
|
256
|
-
end
|
257
|
-
|
258
|
-
it 'raises an exception if the call fails' do
|
259
|
-
j = Systemd::Journal.new
|
260
|
-
Systemd::Journal::Native
|
261
|
-
.should_receive(:sd_journal_query_unique)
|
262
|
-
.and_return(-1)
|
263
|
-
|
264
|
-
expect { j.query_unique(:_pid) }.to raise_error(Systemd::JournalError)
|
265
|
-
end
|
266
|
-
|
267
|
-
it 'raises an exception if the call fails (2)' do
|
268
|
-
j = Systemd::Journal.new
|
269
|
-
Systemd::Journal::Native
|
270
|
-
.should_receive(:sd_journal_query_unique)
|
271
|
-
.and_return(0)
|
272
|
-
|
273
|
-
Systemd::Journal::Native
|
274
|
-
.should_receive(:sd_journal_enumerate_unique)
|
21
|
+
describe 'query_unique' do
|
22
|
+
it 'throws a JournalError on invalid return code' do
|
23
|
+
expect(Systemd::Journal::Native).to receive(:sd_journal_enumerate_unique)
|
275
24
|
.and_return(-1)
|
276
25
|
|
277
26
|
expect { j.query_unique(:_pid) }.to raise_error(Systemd::JournalError)
|
278
27
|
end
|
279
28
|
|
280
|
-
it '
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
Systemd::Journal::Native
|
285
|
-
.should_receive(:sd_journal_query_unique)
|
286
|
-
.and_return(0)
|
29
|
+
it 'lists all the unique values for the given field' do
|
30
|
+
values = j.query_unique(:_transport)
|
31
|
+
transports = %w(syslog journal stdout kernel driver)
|
287
32
|
|
288
|
-
|
289
|
-
|
290
|
-
.exactly(4).times do |ptr, out_ptr, len_ptr|
|
291
|
-
if results.any?
|
292
|
-
x = results.shift
|
293
|
-
out_ptr.write_pointer(FFI::MemoryPointer.from_string(x))
|
294
|
-
len_ptr.write_size_t(x.length)
|
295
|
-
1
|
296
|
-
else
|
297
|
-
0
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
j.query_unique(:_pid).should eq(%w{100 200 300})
|
33
|
+
expect(values.length).to eq(5)
|
34
|
+
expect(values).to include(*transports)
|
302
35
|
end
|
303
|
-
|
304
36
|
end
|
305
37
|
|
306
|
-
describe '
|
307
|
-
it '
|
308
|
-
Systemd::Journal::Native.
|
309
|
-
|
310
|
-
j = Systemd::Journal.new
|
311
|
-
expect { j.wait(100) }.to raise_error(Systemd::JournalError)
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'returns the reason we were woken up' do
|
315
|
-
j = Systemd::Journal.new
|
316
|
-
Systemd::Journal::Native
|
317
|
-
.should_receive(:sd_journal_wait)
|
318
|
-
.and_return(:append)
|
319
|
-
|
320
|
-
j.wait(100).should eq(:append)
|
321
|
-
end
|
322
|
-
|
323
|
-
it 'returns nil if we reached the timeout.' do
|
324
|
-
j = Systemd::Journal.new
|
325
|
-
Systemd::Journal::Native
|
326
|
-
.should_receive(:sd_journal_wait)
|
327
|
-
.and_return(:nop)
|
328
|
-
|
329
|
-
j.wait(100).should eq(nil)
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
describe '#add_filter' do
|
334
|
-
it 'raises an exception if the call fails' do
|
335
|
-
j = Systemd::Journal.new
|
336
|
-
Systemd::Journal::Native
|
337
|
-
.should_receive(:sd_journal_add_match)
|
38
|
+
describe 'disk_usage' do
|
39
|
+
it 'throws a JournalError on invalid return code' do
|
40
|
+
expect(Systemd::Journal::Native).to receive(:sd_journal_get_usage)
|
338
41
|
.and_return(-1)
|
339
42
|
|
340
|
-
expect
|
341
|
-
j.add_filter(:message, 'test')
|
342
|
-
end.to raise_error(Systemd::JournalError)
|
343
|
-
end
|
344
|
-
|
345
|
-
it 'formats the arguments appropriately' do
|
346
|
-
Systemd::Journal::Native
|
347
|
-
.should_receive(:sd_journal_add_match)
|
348
|
-
.with(anything, 'MESSAGE=test', 'MESSAGE=test'.length)
|
349
|
-
.and_return(0)
|
350
|
-
|
351
|
-
Systemd::Journal.new.add_filter(:message, 'test')
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
describe '#add_filters' do
|
356
|
-
it 'calls add_filter for each parameter' do
|
357
|
-
j = Systemd::Journal.new
|
358
|
-
j.should_receive(:add_filter).with(:priority, 1)
|
359
|
-
j.should_receive(:add_filter).with(:_exe, '/usr/bin/sshd')
|
360
|
-
|
361
|
-
j.add_filters(priority: 1, _exe: '/usr/bin/sshd')
|
43
|
+
expect { j.disk_usage }.to raise_error(Systemd::JournalError)
|
362
44
|
end
|
363
45
|
|
364
|
-
it '
|
365
|
-
j
|
366
|
-
j.should_receive(:add_filter).with(:priority, 1)
|
367
|
-
j.should_receive(:add_filter).with(:priority, 2)
|
368
|
-
j.should_receive(:add_filter).with(:priority, 3)
|
369
|
-
|
370
|
-
j.add_filters(priority: [1, 2, 3])
|
46
|
+
it 'returns the disk usage of the example journal file' do
|
47
|
+
expect(j.disk_usage).to eq(4005888)
|
371
48
|
end
|
372
49
|
end
|
373
50
|
|
374
|
-
describe '
|
375
|
-
it '
|
376
|
-
|
377
|
-
|
51
|
+
describe 'data_threshold' do
|
52
|
+
it 'throws a JournalError on invalid return code' do
|
53
|
+
expect(Systemd::Journal::Native).to receive(:sd_journal_get_data_threshold)
|
54
|
+
.and_return(-1)
|
378
55
|
|
379
|
-
j.
|
56
|
+
expect { j.data_threshold }.to raise_error(Systemd::JournalError)
|
380
57
|
end
|
381
58
|
|
382
|
-
it '
|
383
|
-
j
|
384
|
-
j.stub(:clear_filters).and_return(nil)
|
385
|
-
|
386
|
-
j.should_receive(:add_filter).with(:priority, 1).ordered
|
387
|
-
j.should_receive(:add_disjunction).ordered
|
388
|
-
j.should_receive(:add_filter).with(:message, 'hello').ordered
|
389
|
-
|
390
|
-
j.filter({ priority: 1 }, { message: 'hello' })
|
391
|
-
|
59
|
+
it 'returns the default 64K' do
|
60
|
+
expect(j.data_threshold).to eq(0x0010000)
|
392
61
|
end
|
393
62
|
end
|
394
63
|
|
395
|
-
describe '
|
396
|
-
it '
|
397
|
-
|
398
|
-
Systemd::Journal::Native
|
399
|
-
.should_receive(:sd_journal_add_conjunction)
|
64
|
+
describe 'data_threshold=' do
|
65
|
+
it 'throws a JournalError on invalid return code' do
|
66
|
+
expect(Systemd::Journal::Native).to receive(:sd_journal_set_data_threshold)
|
400
67
|
.and_return(-1)
|
401
68
|
|
402
|
-
expect { j.
|
69
|
+
expect { j.data_threshold = 10 }.to raise_error(Systemd::JournalError)
|
403
70
|
end
|
404
71
|
end
|
405
72
|
|
406
|
-
describe '
|
407
|
-
it '
|
408
|
-
|
409
|
-
Systemd::Journal::Native
|
410
|
-
.should_receive(:sd_journal_add_disjunction)
|
73
|
+
describe 'read_field' do
|
74
|
+
it 'throws a JournalError on invalid return code' do
|
75
|
+
expect(Systemd::Journal::Native).to receive(:sd_journal_get_data)
|
411
76
|
.and_return(-1)
|
412
77
|
|
413
|
-
expect { j.
|
78
|
+
expect { j.read_field(:message) }.to raise_error(Systemd::JournalError)
|
414
79
|
end
|
415
|
-
end
|
416
80
|
|
417
|
-
|
418
|
-
|
419
|
-
j = Systemd::Journal.new
|
420
|
-
Systemd::Journal::Native
|
421
|
-
.should_receive(:sd_journal_flush_matches)
|
422
|
-
.and_return(nil)
|
423
|
-
|
424
|
-
j.clear_filters
|
81
|
+
it 'returns the correct value' do
|
82
|
+
expect(j.read_field(:_hostname)).to eq('arch')
|
425
83
|
end
|
426
84
|
end
|
427
85
|
|
428
|
-
describe '
|
429
|
-
it '
|
430
|
-
|
431
|
-
Systemd::Journal::Native
|
432
|
-
.should_receive(:sd_journal_get_usage) do |ptr, size_ptr|
|
433
|
-
size_ptr.write_size_t(12)
|
434
|
-
0
|
435
|
-
end
|
436
|
-
|
437
|
-
j.disk_usage.should eq(12)
|
438
|
-
end
|
439
|
-
|
440
|
-
it 'raises an error if the call fails' do
|
441
|
-
j = Systemd::Journal.new
|
442
|
-
Systemd::Journal::Native
|
443
|
-
.should_receive(:sd_journal_get_usage)
|
86
|
+
describe 'current_entry' do
|
87
|
+
it 'throws a JournalError on invalid return code' do
|
88
|
+
expect(Systemd::Journal::Native).to receive(:sd_journal_enumerate_data)
|
444
89
|
.and_return(-1)
|
445
90
|
|
446
|
-
expect { j.
|
447
|
-
end
|
448
|
-
end
|
449
|
-
|
450
|
-
describe '#data_threshold=' do
|
451
|
-
it 'sets the data threshold' do
|
452
|
-
j = Systemd::Journal.new
|
453
|
-
Systemd::Journal::Native
|
454
|
-
.should_receive(:sd_journal_set_data_threshold)
|
455
|
-
.with(anything, 0x1234)
|
456
|
-
.and_return(0)
|
457
|
-
|
458
|
-
j.data_threshold = 0x1234
|
459
|
-
end
|
460
|
-
|
461
|
-
it 'raises a JournalError on failure' do
|
462
|
-
j = Systemd::Journal.new
|
463
|
-
Systemd::Journal::Native
|
464
|
-
.should_receive(:sd_journal_set_data_threshold)
|
465
|
-
.with(anything, 0x1234)
|
466
|
-
.and_return(-1)
|
467
|
-
|
468
|
-
expect do
|
469
|
-
j.data_threshold = 0x1234
|
470
|
-
end.to raise_error(Systemd::JournalError)
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
describe '#data_threshold' do
|
475
|
-
it 'gets the data threshold' do
|
476
|
-
j = Systemd::Journal.new
|
477
|
-
Systemd::Journal::Native
|
478
|
-
.should_receive(:sd_journal_get_data_threshold) do |ptr, size_ptr|
|
479
|
-
size_ptr.write_size_t(0x1234)
|
480
|
-
0
|
481
|
-
end
|
482
|
-
|
483
|
-
j.data_threshold.should eq(0x1234)
|
91
|
+
expect { j.current_entry }.to raise_error(Systemd::JournalError)
|
484
92
|
end
|
485
93
|
|
486
|
-
it '
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
.and_return(-3)
|
491
|
-
|
492
|
-
expect { j.data_threshold }.to raise_error(Systemd::JournalError)
|
94
|
+
it 'returns a JournalEntry with the correct values' do
|
95
|
+
entry = j.current_entry
|
96
|
+
expect(entry._hostname).to eq('arch')
|
97
|
+
expect(entry.message).to start_with('Allowing runtime journal')
|
493
98
|
end
|
494
|
-
|
495
99
|
end
|
496
100
|
|
497
|
-
describe '
|
498
|
-
it 'returns
|
499
|
-
j
|
500
|
-
Systemd::Journal::Native
|
501
|
-
.should_receive(:sd_journal_test_cursor)
|
502
|
-
.with(anything, '1234').and_return(1)
|
503
|
-
|
504
|
-
j.cursor?('1234').should eq(true)
|
101
|
+
describe 'each' do
|
102
|
+
it 'returns an enumerator' do
|
103
|
+
expect(j.each.class).to be Enumerator
|
505
104
|
end
|
506
105
|
|
507
|
-
it '
|
508
|
-
|
509
|
-
|
510
|
-
.should_receive(:sd_journal_test_cursor)
|
511
|
-
.with(anything, '1234')
|
512
|
-
.and_return(0)
|
106
|
+
it 'throws a JournalError on invalid return code' do
|
107
|
+
expect(Systemd::Journal::Native).to receive(:sd_journal_seek_head)
|
108
|
+
.and_return(-1)
|
513
109
|
|
514
|
-
j.
|
110
|
+
expect { j.each }.to raise_error(Systemd::JournalError)
|
515
111
|
end
|
516
112
|
|
517
|
-
it '
|
518
|
-
|
519
|
-
Systemd::Journal::Native
|
520
|
-
.should_receive(:sd_journal_test_cursor)
|
521
|
-
.and_return(-3)
|
113
|
+
it 'properly enumerates all the entries' do
|
114
|
+
entries = j.each.map(&:message)
|
522
115
|
|
523
|
-
expect
|
116
|
+
expect(entries.first).to start_with('Allowing runtime journal')
|
117
|
+
expect(entries.last).to start_with('ROOT LOGIN ON tty1')
|
524
118
|
end
|
525
|
-
|
526
119
|
end
|
527
120
|
|
528
|
-
describe '
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
.should_receive(:sd_journal_get_cursor) do |ptr, out_ptr|
|
533
|
-
# this memory will be manually freed. not setting autorelease to
|
534
|
-
# false would cause a double free.
|
535
|
-
str = FFI::MemoryPointer.from_string('5678')
|
536
|
-
str.autorelease = false
|
121
|
+
describe 'catalog_for' do
|
122
|
+
subject(:j) { Systemd::Journal }
|
123
|
+
let(:message_id) { 'f77379a8490b408bbe5f6940505a777b' }
|
124
|
+
let(:message_text) { 'Subject: The Journal has been started' }
|
537
125
|
|
538
|
-
|
539
|
-
|
540
|
-
|
126
|
+
it 'throws a JournalError on invalid return code' do
|
127
|
+
expect(Systemd::Journal::Native)
|
128
|
+
.to receive(:sd_journal_get_catalog_for_message_id)
|
129
|
+
.and_return(-1)
|
541
130
|
|
542
|
-
j.
|
131
|
+
expect { j.catalog_for(message_id) }.to raise_error(Systemd::JournalError)
|
543
132
|
end
|
544
133
|
|
545
|
-
it '
|
546
|
-
|
547
|
-
|
548
|
-
.should_receive(:sd_journal_get_cursor)
|
549
|
-
.and_return(-3)
|
550
|
-
|
551
|
-
expect { j.cursor }.to raise_error(Systemd::JournalError)
|
134
|
+
it 'returns the correct catalog entry' do
|
135
|
+
cat = Systemd::Journal.catalog_for(message_id)
|
136
|
+
expect(cat).to start_with(message_text)
|
552
137
|
end
|
553
|
-
|
554
138
|
end
|
555
139
|
|
556
140
|
end
|