systemd-journal 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62fda8140f386ef899a2e599ebd0b28dcc4d371e
4
- data.tar.gz: 20856e68190c5cb1b62c79baeeeb90a1db5ac009
3
+ metadata.gz: 41bf055a81da81e7351fbfafdd5a16177cbea081
4
+ data.tar.gz: 235ba1a4be3f02c1b8ba7b23d68bfed2b549f933
5
5
  SHA512:
6
- metadata.gz: 1501c0de4be3f35d44ed101e2c9f068beb66b14b9554eb61c382430bc1c946d5039ff55a71388ba7acca5a16eed898a25ed1d1164fcd95be1a3dbb24b6971c84
7
- data.tar.gz: 8fbb64089d686aeabc530dbd207da49d47ac170fcac504d31291e277cec527f9a2ca957d78c4a68cbe72c253fc645ea8162b19b756e3934d34b9e92d24dfd2e3
6
+ metadata.gz: 6e45b203f15cf57d61e9a0392bc299dda4c64dc7cf383b41561a95f4e8b14f5add2b55af0ec98a16ddcb5b6c0d034d718f8697f55975649c74d7ce59f8237447
7
+ data.tar.gz: 18c6726c5c693748bc37e6b09972c47efff27c5fbea3fe55b8f07219c58c9ca2fce1404a00abf2fce1cde26f25fb49726deb6507091e86677fe63bd1fce97922
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Ruby bindings for reading from the systemd journal.
4
4
 
5
- * [documentation](http://rubydoc.info/github/ledbettj/systemd-journal)
5
+ * [documentation](http://rubydoc.info/github/ledbettj/systemd-journal/Systemd/Journal)
6
6
 
7
7
  ## Installation
8
8
 
@@ -45,5 +45,5 @@ Or to print all data in each entry:
45
45
  2. Create your feature branch (`git checkout -b my-new-feature`)
46
46
  3. Commit your changes (`git commit -am 'Add some feature'`)
47
47
  4. Push to the branch (`git push origin my-new-feature`)
48
- 5. Create new Pull Request
49
- 6. Wipe hands on pants
48
+ 5. Create new Pull Request, targeting the __develop__ branch.
49
+ 6. Wipe hands on pants, you're done.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "yard"
3
+ require "rspec/core/rake_task"
3
4
 
5
+ desc "open a console with systemd/journal required"
4
6
  task :console do
5
7
  exec 'pry -I./lib -r systemd/journal'
6
8
  end
@@ -9,3 +11,7 @@ YARD::Rake::YardocTask.new do |t|
9
11
  t.files = ['lib/**/*.rb']
10
12
  t.options = ['--no-private', '--markup=markdown']
11
13
  end
14
+
15
+ RSpec::Core::RakeTask.new(:spec) do |t|
16
+ t.rspec_opts = "--color"
17
+ end
@@ -51,9 +51,10 @@ module Systemd
51
51
  # that the pointer has reached the end of the journal.
52
52
  def move_next
53
53
  case (rc = Native::sd_journal_next(@ptr))
54
- when 0 then false # EOF
54
+ when 0 then false
55
55
  when 1 then true
56
- when rc < 0 then raise JournalError.new(rc)
56
+ else
57
+ raise JournalError.new(rc) if rc < 0
57
58
  end
58
59
  end
59
60
 
@@ -75,7 +76,8 @@ module Systemd
75
76
  case (rc = Native::sd_journal_previous(@ptr))
76
77
  when 0 then false # EOF
77
78
  when 1 then true
78
- when rc < 0 then raise JournalError.new(rc)
79
+ else
80
+ raise JournalError.new(rc) if rc < 0
79
81
  end
80
82
  end
81
83
 
@@ -104,11 +106,13 @@ module Systemd
104
106
  Native::sd_journal_seek_head(@ptr)
105
107
  when :tail, :end
106
108
  Native::sd_journal_seek_tail(@ptr)
107
- when whence.is_a?(Time)
108
- # TODO: is this right? who knows.
109
- Native::sd_journal_seek_realtime_usec(@ptr, whence.to_i * 1_000_000)
110
109
  else
111
- raise ArgumentError.new("Unknown seek type: #{whence}")
110
+ if whence.is_a?(Time)
111
+ # TODO: is this right? who knows.
112
+ Native::sd_journal_seek_realtime_usec(@ptr, whence.to_i * 1_000_000)
113
+ else
114
+ raise ArgumentError.new("Unknown seek type: #{whence.class}")
115
+ end
112
116
  end
113
117
 
114
118
  raise JournalErrornew(rc) if rc < 0
@@ -1,6 +1,6 @@
1
1
  module Systemd
2
2
  class Journal
3
3
  # The version of the systemd-journal gem.
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
6
6
  end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+ require 'simplecov'
3
+
4
+ SimpleCov.start
5
+ require 'systemd/journal'
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Systemd::Id128 do
4
+
5
+ describe 'boot_id' do
6
+ it 'returns a properly formatted string representing the boot id' do
7
+ Systemd::Id128::Native.should_receive(:sd_id128_get_boot) do |out|
8
+ dummy = [0xa1, 0x0c] * 8
9
+ out.write_array_of_uint8(dummy)
10
+ 0
11
+ end
12
+ Systemd::Id128.boot_id.should eq("a10c" * 8)
13
+ end
14
+ end
15
+
16
+ describe 'machine_id' do
17
+ it 'returns a properly formatted string representing the machine id' do
18
+ Systemd::Id128::Native.should_receive(:sd_id128_get_machine) do |out|
19
+ dummy = [0xa1, 0x0c] * 8
20
+ out.write_array_of_uint8(dummy)
21
+ 0
22
+ end
23
+ Systemd::Id128.machine_id.should eq("a10c" * 8)
24
+ end
25
+ end
26
+
27
+ describe 'random' do
28
+ it 'returns a random hex string' do
29
+ Systemd::Id128::Native.should_receive(:sd_id128_randomize) do |out|
30
+ dummy = [0xa1, 0x0c] * 8
31
+ out.write_array_of_uint8(dummy)
32
+ 0
33
+ end
34
+ Systemd::Id128.random.should eq("a10c" * 8)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+
3
+ describe Systemd::Journal do
4
+
5
+ before(:each) do
6
+ # don't actually make native API calls.
7
+ dummy_open = ->(ptr, flags, path=nil) do
8
+ dummy = FFI::MemoryPointer.new(:int, 1)
9
+ ptr.write_pointer(dummy)
10
+ 0
11
+ end
12
+
13
+ Systemd::Journal::Native.stub(:sd_journal_open, &dummy_open)
14
+ Systemd::Journal::Native.stub(:sd_journal_open_directory, &dummy_open)
15
+ Systemd::Journal::Native.stub(:sd_journal_close).and_return(0)
16
+ end
17
+
18
+ describe '#initialize' do
19
+ it 'opens a directory if a path is passed' do
20
+ Systemd::Journal::Native.should_receive(:sd_journal_open_directory)
21
+ Systemd::Journal::Native.should_not_receive(:sd_journal_open)
22
+ Systemd::Journal.new(path: '/path/to/journal')
23
+ end
24
+
25
+ it 'accepts flags as an argument' do
26
+ Systemd::Journal::Native.should_receive(:sd_journal_open).with(anything, 1234)
27
+ Systemd::Journal.new(flags: 1234)
28
+ end
29
+
30
+ it 'raises a Journal Error if a native call fails' do
31
+ Systemd::Journal::Native.should_receive(:sd_journal_open).and_return(-1)
32
+ expect {
33
+ Systemd::Journal.new
34
+ }.to raise_error(Systemd::JournalError)
35
+ end
36
+ end
37
+
38
+ ['next', 'previous'].each do |direction|
39
+ describe "#move_#{direction}" do
40
+ it 'returns true on a successful move' do
41
+ j = Systemd::Journal.new
42
+ Systemd::Journal::Native.should_receive(:"sd_journal_#{direction}").and_return(1)
43
+ j.send(:"move_#{direction}").should eq(true)
44
+ end
45
+
46
+ it 'returns false on EOF' do
47
+ j = Systemd::Journal.new
48
+ Systemd::Journal::Native.should_receive(:"sd_journal_#{direction}").and_return(0)
49
+ j.send(:"move_#{direction}").should eq(false)
50
+ end
51
+
52
+ it 'raises an exception on failure' do
53
+ j = Systemd::Journal.new
54
+ Systemd::Journal::Native.should_receive(:"sd_journal_#{direction}").and_return(-1)
55
+ expect {
56
+ j.send(:"move_#{direction}")
57
+ }.to raise_error(Systemd::JournalError)
58
+ end
59
+ end
60
+
61
+ describe "#move_#{direction}_skip" do
62
+ it 'returns the number of records moved by' do
63
+ Systemd::Journal::Native.should_receive(:"sd_journal_#{direction}_skip").
64
+ with(anything, 10).and_return(10)
65
+
66
+ Systemd::Journal.new.send(:"move_#{direction}_skip", 10).should eq(10)
67
+ end
68
+
69
+ it 'raises an exception on failure' do
70
+ Systemd::Journal::Native.should_receive(:"sd_journal_#{direction}_skip").
71
+ with(anything, 10).and_return(-1)
72
+
73
+ j = Systemd::Journal.new
74
+
75
+ expect { j.send(:"move_#{direction}_skip", 10) }.to raise_error(Systemd::JournalError)
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#seek' do
81
+ it 'moves to the first entry of the file' do
82
+ j = Systemd::Journal.new
83
+ Systemd::Journal::Native.should_receive(:sd_journal_seek_head).and_return(0)
84
+ j.seek(:head).should eq(true)
85
+ end
86
+
87
+ it 'moves to the last entry of the file' do
88
+ j = Systemd::Journal.new
89
+ Systemd::Journal::Native.should_receive(:sd_journal_seek_tail).and_return(0)
90
+ j.seek(:tail).should eq(true)
91
+ end
92
+
93
+ it 'seeks based on time when a time is provided' do
94
+ j = Systemd::Journal.new
95
+ Systemd::Journal::Native.should_receive(:sd_journal_seek_realtime_usec).and_return(0)
96
+ j.seek(Time.now).should eq(true)
97
+ end
98
+ end
99
+
100
+ describe '#read_field' do
101
+ pending
102
+ end
103
+
104
+ describe '#current_entry' do
105
+ pending
106
+ end
107
+
108
+ describe '#query_unique' do
109
+ pending
110
+ end
111
+
112
+ describe '#wait' do
113
+ pending
114
+ end
115
+
116
+ describe '#add_match' do
117
+ pending
118
+ end
119
+
120
+ describe '#add_conjunction' do
121
+ pending
122
+ end
123
+
124
+ describe '#add_disjunction' do
125
+ pending
126
+ end
127
+
128
+ describe '#clear_matches' do
129
+ pending
130
+ end
131
+
132
+ describe '#disk_usage' do
133
+ it 'returns the size used on disk' do
134
+ Systemd::Journal::Native.should_receive(:sd_journal_get_usage) do |ptr, size_ptr|
135
+ size_ptr.size == 8 ? size_ptr.write_uint64(12) : size_ptr.write_uint32(12)
136
+ 0
137
+ end
138
+ j = Systemd::Journal.new
139
+ j.disk_usage.should eq(12)
140
+ end
141
+
142
+ it 'raises an error if the call fails' do
143
+ Systemd::Journal::Native.should_receive(:sd_journal_get_usage).and_return(-1)
144
+ j = Systemd::Journal.new
145
+ expect { j.disk_usage }.to raise_error(Systemd::JournalError)
146
+ end
147
+ end
148
+
149
+ end
@@ -6,6 +6,7 @@ require 'systemd/journal/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "systemd-journal"
8
8
  gem.version = Systemd::Journal::VERSION
9
+ gem.license = 'MIT'
9
10
  gem.authors = ["John Ledbetter", "Daniel Mack"]
10
11
  gem.email = ["john@throttle.io"]
11
12
  gem.description = %q{Provides the ability to navigate and read entries from the systemd journal in ruby, as well as write events to the journal.}
@@ -18,4 +19,7 @@ Gem::Specification.new do |gem|
18
19
  gem.require_paths = ["lib"]
19
20
 
20
21
  gem.add_dependency 'ffi', '~>1.9.0'
22
+
23
+ gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'simplecov'
21
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: systemd-journal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ledbetter
@@ -25,6 +25,34 @@ dependencies:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: 1.9.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: simplecov
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
28
56
  description: Provides the ability to navigate and read entries from the systemd journal
29
57
  in ruby, as well as write events to the journal.
30
58
  email:
@@ -49,9 +77,13 @@ files:
49
77
  - lib/systemd/journal/native.rb
50
78
  - lib/systemd/journal/version.rb
51
79
  - lib/systemd/journal_error.rb
80
+ - spec/spec_helper.rb
81
+ - spec/systemd/id128_spec.rb
82
+ - spec/systemd/journal_spec.rb
52
83
  - systemd-journal.gemspec
53
84
  homepage: https://github.com/ledbettj/systemd-journal
54
- licenses: []
85
+ licenses:
86
+ - MIT
55
87
  metadata: {}
56
88
  post_install_message:
57
89
  rdoc_options: []
@@ -69,9 +101,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
101
  version: '0'
70
102
  requirements: []
71
103
  rubyforge_project:
72
- rubygems_version: 2.0.5
104
+ rubygems_version: 2.0.3
73
105
  signing_key:
74
106
  specification_version: 4
75
107
  summary: Ruby bindings to libsystemd-journal
76
- test_files: []
108
+ test_files:
109
+ - spec/spec_helper.rb
110
+ - spec/systemd/id128_spec.rb
111
+ - spec/systemd/journal_spec.rb
77
112
  has_rdoc: