systemd-journal 2.1.0 → 2.1.1
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +17 -5
- data/Gemfile +2 -2
- data/Rakefile +9 -17
- data/examples/journal_directory.rb +1 -1
- data/examples/ssh_watcher.rb +6 -6
- data/lib/systemd/ffi_size_t.rb +5 -5
- data/lib/systemd/id128.rb +12 -14
- data/lib/systemd/journal/fields.rb +9 -9
- data/lib/systemd/journal/filterable.rb +29 -0
- data/lib/systemd/journal/flags.rb +3 -3
- data/lib/systemd/journal/native.rb +30 -30
- data/lib/systemd/journal/navigable.rb +29 -20
- data/lib/systemd/journal/version.rb +1 -1
- data/lib/systemd/journal/waitable.rb +4 -4
- data/lib/systemd/journal/writable.rb +11 -11
- data/lib/systemd/journal.rb +39 -36
- data/lib/systemd/journal_entry.rb +10 -5
- data/lib/systemd/journal_error.rb +1 -1
- data/lib/systemd-journal.rb +1 -1
- data/lib/systemd.rb +1 -1
- data/spec/spec_helper.rb +8 -8
- data/spec/systemd/id128_spec.rb +19 -17
- data/spec/systemd/journal_entry_spec.rb +32 -32
- data/spec/systemd/journal_spec.rb +148 -133
- data/spec/systemd_spec.rb +5 -5
- data/systemd-journal.gemspec +23 -25
- metadata +18 -28
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
RSpec.describe Systemd::Journal do
|
4
4
|
subject(:j) do
|
@@ -8,8 +8,8 @@ RSpec.describe Systemd::Journal do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
12
|
-
it
|
11
|
+
describe "open" do
|
12
|
+
it "creates and closes" do
|
13
13
|
expect(Systemd::Journal::Native).to receive(:sd_journal_close)
|
14
14
|
.and_call_original
|
15
15
|
|
@@ -17,7 +17,7 @@ RSpec.describe Systemd::Journal do
|
|
17
17
|
expect(result).to eq 1
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it "raises original exception when creating journal fails" do
|
21
21
|
expect(Systemd::Journal::Native).to_not receive(:sd_journal_close)
|
22
22
|
|
23
23
|
expect do
|
@@ -26,45 +26,53 @@ RSpec.describe Systemd::Journal do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
29
|
+
describe "initialize" do
|
30
30
|
subject(:j) { Systemd::Journal }
|
31
31
|
|
32
|
-
it
|
33
|
-
expect { j.new(path:
|
34
|
-
expect { j.new(container:
|
35
|
-
expect { j.new(container:
|
32
|
+
it "detects invalid argument combinations" do
|
33
|
+
expect { j.new(path: "/", files: []) }.to raise_error(ArgumentError)
|
34
|
+
expect { j.new(container: "", files: []) }.to raise_error(ArgumentError)
|
35
|
+
expect { j.new(container: "", path: "/") }.to raise_error(ArgumentError)
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it "raises ArgumentError on attempt to open a container without support" do
|
39
39
|
allow(Systemd::Journal::Native).to receive(:open_container?)
|
40
40
|
.and_return(false)
|
41
41
|
|
42
|
-
expect { j.new(container:
|
42
|
+
expect { j.new(container: "test") }.to raise_error(ArgumentError)
|
43
43
|
end
|
44
44
|
|
45
|
-
context
|
46
|
-
it
|
47
|
-
journal = Systemd::Journal.new
|
45
|
+
context "auto_reopen" do
|
46
|
+
it "returns nil as default behavior" do
|
47
|
+
journal = Systemd::Journal.new
|
48
48
|
expect(journal.auto_reopen).to be_falsy
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it "returns default iterations with true" do
|
52
52
|
journal = Systemd::Journal.new(auto_reopen: true)
|
53
53
|
expect(journal.auto_reopen).to be_truthy
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
56
|
+
it "returns nil with false" do
|
57
57
|
journal = Systemd::Journal.new(auto_reopen: false)
|
58
58
|
expect(journal.auto_reopen).to be_falsy
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it "returns iterations with custom value" do
|
62
62
|
journal = Systemd::Journal.new(auto_reopen: 12345)
|
63
63
|
expect(journal.auto_reopen).to be 12345
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
journal = Systemd::Journal.new(auto_reopen: 2)
|
66
|
+
it "should re-open internal journal pointer at specified iterations" do
|
67
|
+
journal = Systemd::Journal.new(file: journal_file, auto_reopen: 2)
|
68
|
+
journal.seek(:head)
|
69
|
+
|
70
|
+
journal.add_filters({syslog_identifier: "kernel"})
|
71
|
+
journal.add_conjunction
|
72
|
+
journal.add_filters({priority: "6"})
|
73
|
+
journal.add_disjunction
|
74
|
+
journal.add_filters({_transport: "kernel"})
|
75
|
+
|
68
76
|
internal_journal = journal.instance_variable_get(:@ptr)
|
69
77
|
|
70
78
|
journal.move_next
|
@@ -72,19 +80,26 @@ RSpec.describe Systemd::Journal do
|
|
72
80
|
|
73
81
|
journal.move_next
|
74
82
|
expect(journal.instance_variable_get(:@ptr)).to_not be internal_journal
|
83
|
+
expect(journal.instance_variable_get(:@reopen_filter_conditions)).to eq [
|
84
|
+
{syslog_identifier: "kernel"},
|
85
|
+
:conjunction,
|
86
|
+
{priority: "6"},
|
87
|
+
:disjunction,
|
88
|
+
{_transport: "kernel"}
|
89
|
+
]
|
75
90
|
end
|
76
91
|
end
|
77
92
|
end
|
78
93
|
|
79
|
-
describe
|
80
|
-
it
|
94
|
+
describe "close" do
|
95
|
+
it "closes the underlying file" do
|
81
96
|
expect(Systemd::Journal::Native).to receive(:sd_journal_close)
|
82
97
|
.and_call_original
|
83
98
|
|
84
99
|
j.close
|
85
100
|
end
|
86
101
|
|
87
|
-
it
|
102
|
+
it "unregisters the finalizer" do
|
88
103
|
expect(ObjectSpace).to receive(:undefine_finalizer)
|
89
104
|
.with(j)
|
90
105
|
.and_call_original
|
@@ -92,53 +107,53 @@ RSpec.describe Systemd::Journal do
|
|
92
107
|
j.close
|
93
108
|
end
|
94
109
|
|
95
|
-
it
|
110
|
+
it "does not fail if called more than once" do
|
96
111
|
j.close
|
97
112
|
expect { j.close }.to_not raise_error
|
98
113
|
end
|
99
114
|
|
100
|
-
it
|
115
|
+
it "marks the journal as closed" do
|
101
116
|
expect(j).to_not be_closed
|
102
117
|
j.close
|
103
118
|
expect(j).to be_closed
|
104
119
|
end
|
105
120
|
end
|
106
121
|
|
107
|
-
describe
|
108
|
-
it
|
122
|
+
describe "query_unique" do
|
123
|
+
it "throws a JournalError on invalid return code" do
|
109
124
|
expect(Systemd::Journal::Native).to receive(:sd_journal_enumerate_unique)
|
110
125
|
.and_return(-1)
|
111
126
|
|
112
127
|
expect { j.query_unique(:_pid) }.to raise_error(Systemd::JournalError)
|
113
128
|
end
|
114
129
|
|
115
|
-
it
|
116
|
-
values
|
117
|
-
transports = %w
|
130
|
+
it "lists all the unique values for the given field" do
|
131
|
+
values = j.query_unique(:_transport)
|
132
|
+
transports = %w[syslog journal stdout kernel driver]
|
118
133
|
|
119
134
|
expect(values.length).to eq(5)
|
120
135
|
expect(values).to include(*transports)
|
121
136
|
end
|
122
137
|
end
|
123
138
|
|
124
|
-
describe
|
125
|
-
it
|
139
|
+
describe "disk_usage" do
|
140
|
+
it "throws a JournalError on invalid return code" do
|
126
141
|
expect(Systemd::Journal::Native).to receive(:sd_journal_get_usage)
|
127
142
|
.and_return(-1)
|
128
143
|
|
129
144
|
expect { j.disk_usage }.to raise_error(Systemd::JournalError)
|
130
145
|
end
|
131
146
|
|
132
|
-
it
|
133
|
-
pending
|
147
|
+
it "returns the disk usage of the example journal file" do
|
148
|
+
pending "blocks? bytes?"
|
134
149
|
expect(j.disk_usage).to eq(4_005_888)
|
135
150
|
# force failure to make travis-ci happy
|
136
151
|
expect(true).to be false
|
137
152
|
end
|
138
153
|
end
|
139
154
|
|
140
|
-
describe
|
141
|
-
it
|
155
|
+
describe "data_threshold" do
|
156
|
+
it "throws a JournalError on invalid return code" do
|
142
157
|
expect(Systemd::Journal::Native)
|
143
158
|
.to receive(:sd_journal_get_data_threshold)
|
144
159
|
.and_return(-1)
|
@@ -146,13 +161,13 @@ RSpec.describe Systemd::Journal do
|
|
146
161
|
expect { j.data_threshold }.to raise_error(Systemd::JournalError)
|
147
162
|
end
|
148
163
|
|
149
|
-
it
|
164
|
+
it "returns the default 64K" do
|
150
165
|
expect(j.data_threshold).to eq(0x0010000)
|
151
166
|
end
|
152
167
|
end
|
153
168
|
|
154
|
-
describe
|
155
|
-
it
|
169
|
+
describe "data_threshold=" do
|
170
|
+
it "throws a JournalError on invalid return code" do
|
156
171
|
expect(Systemd::Journal::Native)
|
157
172
|
.to receive(:sd_journal_set_data_threshold)
|
158
173
|
.and_return(-1)
|
@@ -161,62 +176,62 @@ RSpec.describe Systemd::Journal do
|
|
161
176
|
end
|
162
177
|
end
|
163
178
|
|
164
|
-
describe
|
165
|
-
it
|
179
|
+
describe "read_field" do
|
180
|
+
it "throws a JournalError on invalid return code" do
|
166
181
|
expect(Systemd::Journal::Native).to receive(:sd_journal_get_data)
|
167
182
|
.and_return(-1)
|
168
183
|
|
169
184
|
expect { j.read_field(:message) }.to raise_error(Systemd::JournalError)
|
170
185
|
end
|
171
186
|
|
172
|
-
it
|
173
|
-
expect(j.read_field(:_hostname)).to eq(
|
187
|
+
it "returns the correct value" do
|
188
|
+
expect(j.read_field(:_hostname)).to eq("arch")
|
174
189
|
end
|
175
190
|
end
|
176
191
|
|
177
|
-
describe
|
178
|
-
it
|
192
|
+
describe "current_entry" do
|
193
|
+
it "throws a JournalError on invalid return code" do
|
179
194
|
expect(Systemd::Journal::Native).to receive(:sd_journal_enumerate_data)
|
180
195
|
.and_return(-1)
|
181
196
|
|
182
197
|
expect { j.current_entry }.to raise_error(Systemd::JournalError)
|
183
198
|
end
|
184
199
|
|
185
|
-
it
|
200
|
+
it "returns a JournalEntry with the correct values" do
|
186
201
|
entry = j.current_entry
|
187
|
-
expect(entry._hostname).to eq(
|
188
|
-
expect(entry.message).to start_with(
|
202
|
+
expect(entry._hostname).to eq("arch")
|
203
|
+
expect(entry.message).to start_with("Allowing runtime journal")
|
189
204
|
end
|
190
205
|
end
|
191
206
|
|
192
|
-
describe
|
193
|
-
it
|
207
|
+
describe "each" do
|
208
|
+
it "returns an enumerator" do
|
194
209
|
expect(j.each.class).to be Enumerator
|
195
210
|
end
|
196
211
|
|
197
|
-
it
|
212
|
+
it "throws a JournalError on invalid return code" do
|
198
213
|
expect(Systemd::Journal::Native).to receive(:sd_journal_seek_head)
|
199
214
|
.and_return(-1)
|
200
215
|
|
201
216
|
expect { j.each }.to raise_error(Systemd::JournalError)
|
202
217
|
end
|
203
218
|
|
204
|
-
it
|
219
|
+
it "properly enumerates all the entries" do
|
205
220
|
entries = j.each.map(&:message)
|
206
221
|
|
207
|
-
expect(entries.first).to start_with(
|
208
|
-
expect(entries.last).to start_with(
|
222
|
+
expect(entries.first).to start_with("Allowing runtime journal")
|
223
|
+
expect(entries.last).to start_with("ROOT LOGIN ON tty1")
|
209
224
|
end
|
210
225
|
end
|
211
226
|
|
212
|
-
context
|
213
|
-
let(:msg_id)
|
214
|
-
let(:msg_text) {
|
227
|
+
context "with catalog messages" do
|
228
|
+
let(:msg_id) { "f77379a8490b408bbe5f6940505a777b" }
|
229
|
+
let(:msg_text) { "Subject: The Journal has been started" }
|
215
230
|
|
216
|
-
describe
|
231
|
+
describe "catalog_for" do
|
217
232
|
subject(:j) { Systemd::Journal }
|
218
233
|
|
219
|
-
it
|
234
|
+
it "throws a JournalError on invalid return code" do
|
220
235
|
expect(Systemd::Journal::Native)
|
221
236
|
.to receive(:sd_journal_get_catalog_for_message_id)
|
222
237
|
.and_return(-1)
|
@@ -224,14 +239,14 @@ RSpec.describe Systemd::Journal do
|
|
224
239
|
expect { j.catalog_for(msg_id) }.to raise_error(Systemd::JournalError)
|
225
240
|
end
|
226
241
|
|
227
|
-
it
|
242
|
+
it "returns the correct catalog entry" do
|
228
243
|
cat = Systemd::Journal.catalog_for(msg_id)
|
229
244
|
expect(cat.downcase).to start_with(msg_text.downcase)
|
230
245
|
end
|
231
246
|
end
|
232
247
|
|
233
|
-
describe
|
234
|
-
it
|
248
|
+
describe "current_catalog" do
|
249
|
+
it "throws a JournalError on invalid return code" do
|
235
250
|
expect(Systemd::Journal::Native)
|
236
251
|
.to receive(:sd_journal_get_catalog)
|
237
252
|
.and_return(-1)
|
@@ -239,7 +254,7 @@ RSpec.describe Systemd::Journal do
|
|
239
254
|
expect { j.current_catalog }.to raise_error(Systemd::JournalError)
|
240
255
|
end
|
241
256
|
|
242
|
-
it
|
257
|
+
it "returns the correct catalog entry" do
|
243
258
|
# find first entry with a catalog
|
244
259
|
j.move_next until j.current_entry.catalog?
|
245
260
|
|
@@ -248,64 +263,64 @@ RSpec.describe Systemd::Journal do
|
|
248
263
|
end
|
249
264
|
end
|
250
265
|
|
251
|
-
describe
|
252
|
-
it
|
253
|
-
j.filter(_transport:
|
266
|
+
describe "filter" do
|
267
|
+
it "does basic filtering as expected" do
|
268
|
+
j.filter(_transport: "kernel")
|
254
269
|
j.each do |entry|
|
255
|
-
expect(entry._transport).to eq(
|
270
|
+
expect(entry._transport).to eq("kernel")
|
256
271
|
end
|
257
272
|
expect(j.count).to eq(435)
|
258
273
|
end
|
259
274
|
|
260
|
-
it
|
261
|
-
j.filter(_transport:
|
275
|
+
it "does filtering with AND conditions" do
|
276
|
+
j.filter(_transport: "kernel", priority: 3)
|
262
277
|
expect(j.count).to eq(2)
|
263
278
|
j.each do |e|
|
264
|
-
expect(e._transport).to eq(
|
265
|
-
expect(e.priority).to eq(
|
279
|
+
expect(e._transport).to eq("kernel")
|
280
|
+
expect(e.priority).to eq("3")
|
266
281
|
end
|
267
282
|
end
|
268
283
|
|
269
|
-
it
|
270
|
-
j.filter(_transport: %w
|
284
|
+
it "does basic filtering with multiple options for the same key" do
|
285
|
+
j.filter(_transport: %w[kernel driver])
|
271
286
|
j.each do |entry|
|
272
|
-
expect(%w
|
287
|
+
expect(%w[kernel driver]).to include(entry._transport)
|
273
288
|
end
|
274
289
|
expect(j.count).to eq(438)
|
275
290
|
end
|
276
291
|
|
277
|
-
it
|
292
|
+
it "does basic filtering with multiple keys" do
|
278
293
|
j.filter(
|
279
|
-
{
|
280
|
-
{
|
294
|
+
{_transport: "kernel"},
|
295
|
+
{_systemd_unit: "systemd-journald.service"}
|
281
296
|
)
|
282
297
|
|
283
298
|
c = j.each_with_object(Hash.new(0)) do |e, h|
|
284
|
-
h[:transport] += 1 if e._transport ==
|
285
|
-
h[:unit]
|
299
|
+
h[:transport] += 1 if e._transport == "kernel"
|
300
|
+
h[:unit] += 1 if e._systemd_unit == "systemd-journald.service"
|
286
301
|
end
|
287
302
|
|
288
303
|
expect(c[:transport]).to eq(435)
|
289
304
|
expect(c[:unit]).to eq(3)
|
290
305
|
end
|
291
306
|
|
292
|
-
it
|
307
|
+
it "does crazy stupid filtering" do
|
293
308
|
filter = [
|
294
|
-
{
|
295
|
-
{
|
296
|
-
{
|
297
|
-
{
|
309
|
+
{_transport: "kernel", priority: 4},
|
310
|
+
{_systemd_unit: "getty@tty1.service"},
|
311
|
+
{_systemd_unit: "systemd-logind.service", seat_id: "seat0"},
|
312
|
+
{priority: [3, 5]}
|
298
313
|
]
|
299
314
|
|
300
315
|
j.filter(*filter)
|
301
316
|
|
302
317
|
c = j.each_with_object(Hash.new(0)) do |e, h|
|
303
|
-
h[:a] += 1 if e._transport ==
|
304
|
-
h[:b] += 1 if e._systemd_unit ==
|
305
|
-
if e._systemd_unit ==
|
318
|
+
h[:a] += 1 if e._transport == "kernel" && e.priority == "4"
|
319
|
+
h[:b] += 1 if e._systemd_unit == "getty@tty1.service"
|
320
|
+
if e._systemd_unit == "systemd-logind.service" && e[:seat_id] == "seat0"
|
306
321
|
h[:c] += 1
|
307
322
|
end
|
308
|
-
h[:d] += 1 if %w
|
323
|
+
h[:d] += 1 if %w[3 5].include?(e.priority)
|
309
324
|
end
|
310
325
|
|
311
326
|
# from journalctl --file <fixture> <filter> --output json | wc -l
|
@@ -316,12 +331,12 @@ RSpec.describe Systemd::Journal do
|
|
316
331
|
end
|
317
332
|
end
|
318
333
|
|
319
|
-
describe
|
320
|
-
it
|
334
|
+
describe "cursor" do
|
335
|
+
it "returns some opaque string" do
|
321
336
|
expect(j.cursor).to be_kind_of(String)
|
322
337
|
end
|
323
338
|
|
324
|
-
it
|
339
|
+
it "throws an error on failure" do
|
325
340
|
expect(Systemd::Journal::Native).to receive(:sd_journal_get_cursor)
|
326
341
|
.and_return(-1)
|
327
342
|
|
@@ -329,13 +344,13 @@ RSpec.describe Systemd::Journal do
|
|
329
344
|
end
|
330
345
|
end
|
331
346
|
|
332
|
-
describe
|
347
|
+
describe "cursor?" do
|
333
348
|
let!(:cursor) { j.cursor }
|
334
|
-
it
|
349
|
+
it "returns true if the cursor matches" do
|
335
350
|
expect(j.cursor?(cursor)).to be true
|
336
351
|
end
|
337
352
|
|
338
|
-
it
|
353
|
+
it "throws an error on failure" do
|
339
354
|
expect(Systemd::Journal::Native).to receive(:sd_journal_test_cursor)
|
340
355
|
.and_return(-1)
|
341
356
|
|
@@ -343,41 +358,41 @@ RSpec.describe Systemd::Journal do
|
|
343
358
|
end
|
344
359
|
end
|
345
360
|
|
346
|
-
describe
|
347
|
-
it
|
361
|
+
describe "move" do
|
362
|
+
it "moves by the specified number of entries" do
|
348
363
|
j.move(1)
|
349
|
-
expect(j.read_field(:message)).to eq(journal_json[1][
|
364
|
+
expect(j.read_field(:message)).to eq(journal_json[1]["MESSAGE"])
|
350
365
|
end
|
351
366
|
|
352
|
-
it
|
367
|
+
it "does not move with 0" do
|
353
368
|
j.move(1)
|
354
369
|
j.move(0)
|
355
|
-
expect(j.read_field(:message)).to eq(journal_json[1][
|
370
|
+
expect(j.read_field(:message)).to eq(journal_json[1]["MESSAGE"])
|
356
371
|
end
|
357
372
|
|
358
|
-
it
|
373
|
+
it "moves backwards" do
|
359
374
|
j.move(3)
|
360
375
|
j.move(-1)
|
361
|
-
expect(j.read_field(:message)).to eq(journal_json[2][
|
376
|
+
expect(j.read_field(:message)).to eq(journal_json[2]["MESSAGE"])
|
362
377
|
end
|
363
378
|
|
364
|
-
it
|
379
|
+
it "returns the number of entries moved" do
|
365
380
|
expect(j.move(3)).to eq(3)
|
366
381
|
end
|
367
382
|
|
368
|
-
it
|
383
|
+
it "returns the number of entries moved even if if less" do
|
369
384
|
j.move(2)
|
370
|
-
expect(j.read_field(:message)).to eq(journal_json[2][
|
385
|
+
expect(j.read_field(:message)).to eq(journal_json[2]["MESSAGE"])
|
371
386
|
expect(j.move(-5)).to eq(2)
|
372
387
|
end
|
373
388
|
|
374
|
-
it
|
389
|
+
it "returns 0 if it did not move" do
|
375
390
|
expect(j.move(-1)).to eq(0)
|
376
391
|
end
|
377
392
|
end
|
378
393
|
|
379
|
-
describe
|
380
|
-
it
|
394
|
+
describe "seek" do
|
395
|
+
it "treats a string parameter as the cursor" do
|
381
396
|
cursor = j.cursor
|
382
397
|
j.move(3)
|
383
398
|
expect(j.cursor?(cursor)).to be false
|
@@ -386,36 +401,36 @@ RSpec.describe Systemd::Journal do
|
|
386
401
|
expect(j.cursor?(cursor)).to be true
|
387
402
|
end
|
388
403
|
|
389
|
-
it
|
404
|
+
it "can seek to the end" do
|
390
405
|
j.seek(:tail)
|
391
406
|
j.move_previous
|
392
407
|
expect(j.move_next).to be false
|
393
408
|
end
|
394
409
|
|
395
|
-
it
|
410
|
+
it "can seek to the start" do
|
396
411
|
j.seek(:start)
|
397
412
|
j.move_next
|
398
413
|
expect(j.move_previous).to be false
|
399
414
|
end
|
400
415
|
|
401
|
-
it
|
402
|
-
j.seek(Time.parse(
|
416
|
+
it "can seek based on timestamp" do
|
417
|
+
j.seek(Time.parse("2013-03-28T21:07:21-04:00"))
|
403
418
|
j.move_next
|
404
419
|
|
405
420
|
entry = j.current_entry
|
406
|
-
ts
|
421
|
+
ts = entry.realtime_timestamp
|
407
422
|
|
408
|
-
expect(entry.message).to start_with(
|
409
|
-
expect(ts.utc.iso8601).to eq(
|
423
|
+
expect(entry.message).to start_with("input: ImExPS/2")
|
424
|
+
expect(ts.utc.iso8601).to eq("2013-03-29T01:07:21Z")
|
410
425
|
end
|
411
426
|
|
412
|
-
it
|
427
|
+
it "throws an ArgumentError for other types" do
|
413
428
|
expect { j.seek(5) }.to raise_error(ArgumentError)
|
414
429
|
end
|
415
430
|
end
|
416
431
|
|
417
|
-
describe
|
418
|
-
it
|
432
|
+
describe "wait" do
|
433
|
+
it "returns nil if nothing happens" do
|
419
434
|
expect(Systemd::Journal::Native)
|
420
435
|
.to receive(:sd_journal_wait)
|
421
436
|
.and_return(:nop)
|
@@ -423,7 +438,7 @@ RSpec.describe Systemd::Journal do
|
|
423
438
|
expect(j.wait(1)).to be nil
|
424
439
|
end
|
425
440
|
|
426
|
-
it
|
441
|
+
it "returns :append if new entries are found" do
|
427
442
|
expect(Systemd::Journal::Native)
|
428
443
|
.to receive(:sd_journal_wait)
|
429
444
|
.and_return(:append)
|
@@ -431,7 +446,7 @@ RSpec.describe Systemd::Journal do
|
|
431
446
|
expect(j.wait(1)).to be :append
|
432
447
|
end
|
433
448
|
|
434
|
-
it
|
449
|
+
it "raise a JournalError on error" do
|
435
450
|
expect(Systemd::Journal::Native)
|
436
451
|
.to receive(:sd_journal_wait)
|
437
452
|
.and_return(-1)
|
@@ -439,46 +454,46 @@ RSpec.describe Systemd::Journal do
|
|
439
454
|
expect { j.wait(1) }.to raise_error(Systemd::JournalError)
|
440
455
|
end
|
441
456
|
|
442
|
-
it
|
443
|
-
pending
|
457
|
+
it "can use select" do
|
458
|
+
pending "not available on JRUBY" if Systemd::Journal::IS_JRUBY
|
444
459
|
expect(Systemd::Journal::Native).to_not receive(:sd_journal_wait)
|
445
460
|
j.wait(1, select: true)
|
446
461
|
end
|
447
462
|
|
448
|
-
it
|
449
|
-
pending
|
463
|
+
it "ignores request to use select on JRuby" do
|
464
|
+
pending "not necessary on MRI" unless Systemd::Journal::IS_JRUBY
|
450
465
|
expect(Systemd::Journal::Native).to receive(:sd_journal_wait)
|
451
466
|
j.wait(1, select: true)
|
452
467
|
end
|
453
468
|
end
|
454
469
|
|
455
|
-
describe
|
456
|
-
it
|
470
|
+
describe "wait_select_reliable?" do
|
471
|
+
it "should not throw an error" do
|
457
472
|
expect { j.wait_select_reliable? }.to_not raise_error
|
458
473
|
end
|
459
474
|
|
460
|
-
it
|
475
|
+
it "should return a boolean" do
|
461
476
|
expect([true, false]).to include(j.wait_select_reliable?)
|
462
477
|
end
|
463
478
|
end
|
464
479
|
|
465
|
-
describe
|
466
|
-
it
|
480
|
+
describe "message" do
|
481
|
+
it "escapes percent signs in messages" do
|
467
482
|
expect(Systemd::Journal::Native).to receive(:sd_journal_send)
|
468
|
-
.with(:string,
|
483
|
+
.with(:string, "MESSAGE=hello %% world %%", :string, nil)
|
469
484
|
.and_return(0)
|
470
485
|
|
471
|
-
Systemd::Journal.message(message:
|
486
|
+
Systemd::Journal.message(message: "hello % world %")
|
472
487
|
end
|
473
488
|
end
|
474
489
|
|
475
|
-
describe
|
476
|
-
it
|
490
|
+
describe "print" do
|
491
|
+
it "escapes percent signs" do
|
477
492
|
expect(Systemd::Journal::Native).to receive(:sd_journal_print)
|
478
|
-
.with(Systemd::Journal::LOG_DEBUG,
|
493
|
+
.with(Systemd::Journal::LOG_DEBUG, "hello %% world %%")
|
479
494
|
.and_return(0)
|
480
495
|
|
481
|
-
Systemd::Journal.print(Systemd::Journal::LOG_DEBUG,
|
496
|
+
Systemd::Journal.print(Systemd::Journal::LOG_DEBUG, "hello % world %")
|
482
497
|
end
|
483
498
|
end
|
484
499
|
end
|
data/spec/systemd_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
RSpec.describe Systemd do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe "machine_id" do
|
5
|
+
it "is an alias for Systemd::Id128.machine_id" do
|
6
6
|
expect(Systemd::Id128).to receive(:machine_id)
|
7
7
|
Systemd.machine_id
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
12
|
-
it
|
11
|
+
describe "boot_id" do
|
12
|
+
it "is an alias for Systemd::Id128.boot_id" do
|
13
13
|
expect(Systemd::Id128).to receive(:boot_id)
|
14
14
|
Systemd.boot_id
|
15
15
|
end
|