vnstat-ruby 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +6 -2
- data/VERSION +1 -1
- data/lib/vnstat/interface.rb +2 -2
- data/lib/vnstat/traffic/base.rb +0 -5
- data/spec/lib/vnstat/interface_collection_spec.rb +68 -0
- data/spec/lib/vnstat/interface_spec.rb +123 -38
- data/vnstat-ruby.gemspec +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b11dd1355f5618e134a3d186a1957b15790d237
|
4
|
+
data.tar.gz: 244a68723714c5ea3d432fd4dd65ba86f43a2d65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 993ad13bda555602b454e5a713bf18fe661b66d27227dcc2a19c79e310309ca2b9d2c9c31bee4da335954e997f097452aa85ba9ce0e711f8007c2faf783b429e
|
7
|
+
data.tar.gz: 626885c81f31451e8699f8d985669de2dfb9feaa1e28314efc397d63c7bb6202089feb6338eba73f908555a5115250ada9e174bb0a97730d76d1677baf64e686
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -3,8 +3,12 @@
|
|
3
3
|
[![Code Climate](https://codeclimate.com/github/tlux/vnstat-ruby/badges/gpa.svg)](https://codeclimate.com/github/tlux/vnstat-ruby) [![Test Coverage](https://codeclimate.com/github/tlux/vnstat-ruby/badges/coverage.svg)](https://codeclimate.com/github/tlux/vnstat-ruby/coverage) [![Build Status](https://travis-ci.org/tlux/vnstat-ruby.svg?branch=master)](https://travis-ci.org/tlux/vnstat-ruby)
|
4
4
|
|
5
5
|
Vnstat is a tool that tracks the traffic on your network interfaces.
|
6
|
-
This tiny library
|
7
|
-
|
6
|
+
This tiny library is intended to provide network traffic information
|
7
|
+
through an easy-to-use API.
|
8
|
+
|
9
|
+
It depends on the
|
10
|
+
[vnstat command line utility](http://humdi.net/vnstat/) which is
|
11
|
+
maintained by Teemu Toivola.
|
8
12
|
|
9
13
|
|
10
14
|
### Prerequisites
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.5
|
data/lib/vnstat/interface.rb
CHANGED
data/lib/vnstat/traffic/base.rb
CHANGED
@@ -28,6 +28,21 @@ describe Vnstat::InterfaceCollection do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
describe '.load_data' do
|
32
|
+
it 'calls Vnstat::Utils.call_executable' do
|
33
|
+
expect(Vnstat::Utils).to receive(:call_executable).with('--xml')
|
34
|
+
|
35
|
+
described_class.load_data
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns result of Vnstat::Utils.call_executable' do
|
39
|
+
allow(Vnstat::Utils).to receive(:call_executable).with(any_args)
|
40
|
+
.and_return('test')
|
41
|
+
|
42
|
+
expect(described_class.load_data).to eq 'test'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
31
46
|
describe '#ids' do
|
32
47
|
it 'returns interface names from the data' do
|
33
48
|
expect(subject.ids).to eq %w(eth0 wlan0)
|
@@ -64,6 +79,59 @@ describe Vnstat::InterfaceCollection do
|
|
64
79
|
end
|
65
80
|
end
|
66
81
|
|
82
|
+
describe '#create' do
|
83
|
+
it 'calls Vnstat::Utils.call_executable_returning_status' do
|
84
|
+
expect(Vnstat::Utils).to receive(:call_executable_returning_status)
|
85
|
+
.with('--create', '-i', 'test').and_return(false)
|
86
|
+
|
87
|
+
subject.create('test')
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when Vnstat::Utils.call_executable_returning_status ' \
|
91
|
+
'returns true' do
|
92
|
+
before :each do
|
93
|
+
allow(Vnstat::Utils).to receive(:call_executable_returning_status)
|
94
|
+
.and_return(true)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'calls #[] with first arg' do
|
98
|
+
allow(subject).to receive(:reload)
|
99
|
+
|
100
|
+
expect(subject).to receive(:[]).with('test')
|
101
|
+
|
102
|
+
subject.create('test')
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns result of #[] with first arg' do
|
106
|
+
allow(subject).to receive(:reload)
|
107
|
+
|
108
|
+
allow(subject).to receive(:[]).and_return('test')
|
109
|
+
|
110
|
+
expect(subject.create('eth1')).to eq 'test'
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'calls #reload' do
|
114
|
+
allow(subject).to receive(:[]).with('test')
|
115
|
+
|
116
|
+
expect(subject).to receive(:reload)
|
117
|
+
|
118
|
+
subject.create('test')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'when Vnstat::Utils.call_executable_returning_status ' \
|
123
|
+
'returns false' do
|
124
|
+
before :each do
|
125
|
+
allow(Vnstat::Utils).to receive(:call_executable_returning_status)
|
126
|
+
.and_return(false)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'returns nil' do
|
130
|
+
expect(subject.create('test')).to be nil
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
67
135
|
describe '#reload' do
|
68
136
|
before :each do
|
69
137
|
allow(described_class).to receive(:load_data).and_return('<test />')
|
@@ -84,48 +84,19 @@ describe Vnstat::Interface do
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
describe '
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
<interface id="eth0">
|
92
|
-
<id>eth0</id>
|
93
|
-
<nick>New Ethernet</nick>
|
94
|
-
</interface>
|
95
|
-
</vnstat>
|
96
|
-
XML
|
97
|
-
end
|
98
|
-
|
99
|
-
before :each do
|
100
|
-
allow(described_class).to receive(:load_data).and_return('<test />')
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'returns self' do
|
104
|
-
expect(subject.reload).to eq subject
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'calls .load_data with #id as argument' do
|
108
|
-
expect(described_class).to receive(:load_data).with('eth0')
|
109
|
-
.and_return(reloaded_data)
|
110
|
-
|
111
|
-
subject.reload
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'calls #data= with the result from .load_data' do
|
115
|
-
allow(described_class).to receive(:load_data).and_return('<vnstat />')
|
116
|
-
|
117
|
-
expect(subject).to receive(:data=).with('<vnstat />')
|
87
|
+
describe '.load_data' do
|
88
|
+
it 'calls Vnstat::Utils.call_executable' do
|
89
|
+
expect(Vnstat::Utils).to receive(:call_executable)
|
90
|
+
.with('-i', 'test', '--xml')
|
118
91
|
|
119
|
-
|
92
|
+
described_class.load_data('test')
|
120
93
|
end
|
121
94
|
|
122
|
-
it '
|
123
|
-
allow(
|
124
|
-
.and_return(
|
95
|
+
it 'returns result of Vnstat::Utils.call_executable' do
|
96
|
+
allow(Vnstat::Utils).to receive(:call_executable).with(any_args)
|
97
|
+
.and_return('test')
|
125
98
|
|
126
|
-
expect
|
127
|
-
.to change { subject.nick }
|
128
|
-
.from('Ethernet').to('New Ethernet')
|
99
|
+
expect(described_class.load_data('eth0')).to eq 'test'
|
129
100
|
end
|
130
101
|
end
|
131
102
|
|
@@ -239,4 +210,118 @@ describe Vnstat::Interface do
|
|
239
210
|
expect(subject.tops.interface).to eq subject
|
240
211
|
end
|
241
212
|
end
|
213
|
+
|
214
|
+
describe '#reload' do
|
215
|
+
let :reloaded_data do
|
216
|
+
<<-XML
|
217
|
+
<vnstat version="1.12" xmlversion="1">
|
218
|
+
<interface id="eth0">
|
219
|
+
<id>eth0</id>
|
220
|
+
<nick>New Ethernet</nick>
|
221
|
+
</interface>
|
222
|
+
</vnstat>
|
223
|
+
XML
|
224
|
+
end
|
225
|
+
|
226
|
+
before :each do
|
227
|
+
allow(described_class).to receive(:load_data).and_return('<test />')
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'returns self' do
|
231
|
+
expect(subject.reload).to eq subject
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'calls .load_data with #id as argument' do
|
235
|
+
expect(described_class).to receive(:load_data).with('eth0')
|
236
|
+
.and_return(reloaded_data)
|
237
|
+
|
238
|
+
subject.reload
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'calls #data= with the result from .load_data' do
|
242
|
+
allow(described_class).to receive(:load_data).and_return('<vnstat />')
|
243
|
+
|
244
|
+
expect(subject).to receive(:data=).with('<vnstat />')
|
245
|
+
|
246
|
+
subject.reload
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'resets #nick from reloaded data' do
|
250
|
+
allow(described_class).to receive(:load_data).with('eth0')
|
251
|
+
.and_return(reloaded_data)
|
252
|
+
|
253
|
+
expect { subject.reload }
|
254
|
+
.to change { subject.nick }.from('Ethernet').to('New Ethernet')
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe '#delete' do
|
259
|
+
it 'calls Vnstat::Utils.call_executable_returning_status' do
|
260
|
+
expect(Vnstat::Utils).to receive(:call_executable_returning_status)
|
261
|
+
.with('--delete', '-i', subject.id)
|
262
|
+
|
263
|
+
subject.delete
|
264
|
+
end
|
265
|
+
|
266
|
+
[true, false].each do |expected|
|
267
|
+
context "when Vnstat::Utils.call_executable_returning_status " \
|
268
|
+
"returns #{expected}" do
|
269
|
+
before :each do
|
270
|
+
allow(Vnstat::Utils).to receive(:call_executable_returning_status)
|
271
|
+
.with(any_args).and_return(expected)
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'returns true' do
|
275
|
+
expect(subject.delete).to be expected
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe '#reset' do
|
282
|
+
it 'calls Vnstat::Utils.call_executable_returning_status' do
|
283
|
+
expect(Vnstat::Utils).to receive(:call_executable_returning_status)
|
284
|
+
.with('--reset', '-i', subject.id)
|
285
|
+
|
286
|
+
subject.reset
|
287
|
+
end
|
288
|
+
|
289
|
+
context 'when Vnstat::Utils.call_executable_returning_status ' \
|
290
|
+
'returns true' do
|
291
|
+
before :each do
|
292
|
+
allow(Vnstat::Utils).to receive(:call_executable_returning_status)
|
293
|
+
.with(any_args).and_return(true)
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'returns self' do
|
297
|
+
allow(subject).to receive(:reload)
|
298
|
+
|
299
|
+
expect(subject.reset).to eq subject
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'calls #reload' do
|
303
|
+
expect(subject).to receive(:reload)
|
304
|
+
|
305
|
+
subject.reset
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context 'when Vnstat::Utils.call_executable_returning_status ' \
|
310
|
+
'returns false' do
|
311
|
+
before :each do
|
312
|
+
allow(Vnstat::Utils).to receive(:call_executable_returning_status)
|
313
|
+
.with(any_args).and_return(false)
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'returns self' do
|
317
|
+
expect(subject.reset).to eq subject
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'does not call #reload' do
|
321
|
+
expect(subject).not_to receive(:reload)
|
322
|
+
|
323
|
+
subject.reset
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
242
327
|
end
|
data/vnstat-ruby.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: vnstat-ruby 1.0.
|
5
|
+
# stub: vnstat-ruby 1.0.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "vnstat-ruby"
|
9
|
-
s.version = "1.0.
|
9
|
+
s.version = "1.0.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Tobias Casper"]
|
14
|
-
s.date = "2015-11-
|
14
|
+
s.date = "2015-11-28"
|
15
15
|
s.description = "Uses the the vnstat CLI to track your network traffic."
|
16
16
|
s.email = "tobias.casper@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vnstat-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Casper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|