vnstat-ruby 1.1.0 → 2.0.0
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 +5 -5
- data/.gitignore +49 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -5
- data/Gemfile +4 -10
- data/Gemfile.lock +29 -75
- data/LICENSE.txt +18 -17
- data/README.md +1 -3
- data/Rakefile +4 -25
- data/lib/vnstat-ruby.rb +2 -0
- data/lib/vnstat.rb +17 -2
- data/lib/vnstat/configuration.rb +4 -2
- data/lib/vnstat/document.rb +6 -1
- data/lib/vnstat/error.rb +2 -0
- data/lib/vnstat/errors/executable_not_found.rb +2 -0
- data/lib/vnstat/errors/unknown_interface.rb +2 -0
- data/lib/vnstat/interface.rb +4 -1
- data/lib/vnstat/interface_collection.rb +2 -0
- data/lib/vnstat/parser.rb +4 -2
- data/lib/vnstat/result.rb +8 -5
- data/lib/vnstat/result/date_delegation.rb +2 -0
- data/lib/vnstat/result/day.rb +4 -1
- data/lib/vnstat/result/hour.rb +6 -2
- data/lib/vnstat/result/minute.rb +5 -2
- data/lib/vnstat/result/month.rb +6 -2
- data/lib/vnstat/result/time_comparable.rb +2 -0
- data/lib/vnstat/system_call.rb +10 -7
- data/lib/vnstat/traffic.rb +2 -0
- data/lib/vnstat/traffic/base.rb +2 -0
- data/lib/vnstat/traffic/daily.rb +2 -0
- data/lib/vnstat/traffic/hourly.rb +2 -0
- data/lib/vnstat/traffic/monthly.rb +2 -0
- data/lib/vnstat/traffic/tops.rb +2 -0
- data/lib/vnstat/utils.rb +2 -0
- data/lib/vnstat/version.rb +5 -0
- data/vnstat-ruby.gemspec +36 -109
- metadata +27 -65
- data/.codeclimate.yml +0 -14
- data/spec/lib/vnstat/configuration_spec.rb +0 -72
- data/spec/lib/vnstat/document_spec.rb +0 -54
- data/spec/lib/vnstat/errors/executable_not_found_spec.rb +0 -5
- data/spec/lib/vnstat/errors/unknown_interface_spec.rb +0 -5
- data/spec/lib/vnstat/interface_collection_spec.rb +0 -194
- data/spec/lib/vnstat/interface_spec.rb +0 -327
- data/spec/lib/vnstat/result/day_spec.rb +0 -39
- data/spec/lib/vnstat/result/hour_spec.rb +0 -43
- data/spec/lib/vnstat/result/minute_spec.rb +0 -54
- data/spec/lib/vnstat/result/month_spec.rb +0 -39
- data/spec/lib/vnstat/result_spec.rb +0 -86
- data/spec/lib/vnstat/system_call_spec.rb +0 -209
- data/spec/lib/vnstat/traffic/daily_spec.rb +0 -109
- data/spec/lib/vnstat/traffic/hourly_spec.rb +0 -153
- data/spec/lib/vnstat/traffic/monthly_spec.rb +0 -46
- data/spec/lib/vnstat/traffic/tops_spec.rb +0 -48
- data/spec/lib/vnstat/utils_spec.rb +0 -130
- data/spec/lib/vnstat_spec.rb +0 -61
- data/spec/spec_helper.rb +0 -98
- data/spec/support/shared_examples/shared_examples_for_date_delegation.rb +0 -19
- data/spec/support/shared_examples/shared_examples_for_traffic_collection.rb +0 -19
data/.codeclimate.yml
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
describe Vnstat::Configuration do
|
2
|
-
describe '#reset' do
|
3
|
-
before :each do
|
4
|
-
subject.executable_path = '/test/path/vnstat'
|
5
|
-
end
|
6
|
-
|
7
|
-
it 'returns self' do
|
8
|
-
expect(subject.reset).to eq subject
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'sets #executable_path to nil' do
|
12
|
-
expect { subject.reset }
|
13
|
-
.to change { subject.instance_variable_get(:@executable_path) }
|
14
|
-
.from('/test/path/vnstat').to(nil)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#executable_path' do
|
19
|
-
context 'when configured' do
|
20
|
-
before :each do
|
21
|
-
subject.executable_path = '/test/path/vnstat'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns configured path' do
|
25
|
-
expect(subject.executable_path).to eq '/test/path/vnstat'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'when not configured' do
|
30
|
-
it 'calls Utils.system_call to invoke `which vnstat`' do
|
31
|
-
expect(Vnstat::Utils).to receive(:system_call)
|
32
|
-
.with('which', 'vnstat')
|
33
|
-
.and_return('/test/other_path/vnstat')
|
34
|
-
|
35
|
-
subject.executable_path
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'with path detected by `which vnstat`' do
|
39
|
-
before :each do
|
40
|
-
allow(Vnstat::Utils).to receive(:system_call)
|
41
|
-
.with('which', 'vnstat')
|
42
|
-
.and_return('/test/other_path/vnstat')
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns detected path' do
|
46
|
-
expect(subject.executable_path).to eq '/test/other_path/vnstat'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'with path not detectable by `which vnstat`' do
|
51
|
-
before :each do
|
52
|
-
allow(Vnstat::Utils).to receive(:system_call)
|
53
|
-
.with('which', 'vnstat').and_yield
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'raises Vnstat::ExecutableNotFound' do
|
57
|
-
expect { subject.executable_path }
|
58
|
-
.to raise_error(Vnstat::ExecutableNotFound,
|
59
|
-
'Unable to locate vnstat executable')
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#executable_path=' do
|
66
|
-
it 'sets instance variable @executable_path' do
|
67
|
-
expect { subject.executable_path = '/test/path/vnstat' }
|
68
|
-
.to change { subject.instance_variable_get(:@executable_path) }
|
69
|
-
.from(nil).to('/test/path/vnstat')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
describe Vnstat::Document do
|
2
|
-
subject do
|
3
|
-
described_class.new('<vnstat version="1.23" xmlversion="1"></vnstat>')
|
4
|
-
end
|
5
|
-
|
6
|
-
describe '#initialize' do
|
7
|
-
it 'invokes #data= forwarding the first argument' do
|
8
|
-
expect_any_instance_of(described_class)
|
9
|
-
.to receive(:data=).with('test')
|
10
|
-
|
11
|
-
described_class.new('test')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#data=' do
|
16
|
-
context 'when setting nil' do
|
17
|
-
subject { described_class.new('<vnstat />') }
|
18
|
-
|
19
|
-
it 'raises ArgumentError' do
|
20
|
-
expect { subject.data = nil }
|
21
|
-
.to raise_error(ArgumentError, 'No document data specified')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when setting a String' do
|
26
|
-
subject { described_class.new('<old />') }
|
27
|
-
|
28
|
-
before :each do
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'changes #data' do
|
32
|
-
expect { subject.data = '<vnstat />' }.to(change { subject.data })
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'stores the XML fragment in #data' do
|
36
|
-
subject.data = '<vnstat />'
|
37
|
-
|
38
|
-
expect(subject.data).to be_a Nokogiri::XML::Document
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#version' do
|
44
|
-
it 'returns the version attribute value from the vnstat element' do
|
45
|
-
expect(subject.version).to eq '1.23'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#xml_version' do
|
50
|
-
it 'returns the xmlversion attribute value from the vnstat element' do
|
51
|
-
expect(subject.xml_version).to eq '1'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,194 +0,0 @@
|
|
1
|
-
describe Vnstat::InterfaceCollection do
|
2
|
-
let :data do
|
3
|
-
<<-XML
|
4
|
-
<vnstat version="0.00" xmlversion="1">
|
5
|
-
<interface id="eth0"></interface>
|
6
|
-
<interface id="wlan0"></interface>
|
7
|
-
</vnstat>
|
8
|
-
XML
|
9
|
-
end
|
10
|
-
|
11
|
-
subject { described_class.new(data) }
|
12
|
-
|
13
|
-
it { is_expected.to be_a Vnstat::Document }
|
14
|
-
|
15
|
-
describe '.open' do
|
16
|
-
it 'calls .new' do
|
17
|
-
allow(described_class).to receive(:load_data).and_return('test data')
|
18
|
-
|
19
|
-
expect(described_class).to receive(:new).with('test data')
|
20
|
-
|
21
|
-
described_class.open
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'calls .load_data' do
|
25
|
-
expect(described_class).to receive(:load_data).and_return('<vnstat />')
|
26
|
-
|
27
|
-
described_class.open
|
28
|
-
end
|
29
|
-
end
|
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
|
-
|
46
|
-
describe '#ids' do
|
47
|
-
it 'returns interface names from the data' do
|
48
|
-
expect(subject.ids).to eq %w[eth0 wlan0]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#[]' do
|
53
|
-
context 'when existing interface given' do
|
54
|
-
context 'with String argument' do
|
55
|
-
it 'returns Vnstat::Interface' do
|
56
|
-
expect(subject['eth0']).to be_a Vnstat::Interface
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'returns object with id matching the given argument' do
|
60
|
-
expect(subject['eth0'].id).to eq 'eth0'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'with symbolic argument' do
|
65
|
-
it 'returns Vnstat::Interface' do
|
66
|
-
expect(subject[:eth0]).to be_a Vnstat::Interface
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns object with id matching the given argument' do
|
70
|
-
expect(subject[:eth0].id).to eq 'eth0'
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'when non-existing interface given' do
|
76
|
-
it 'raises Vnstat::UnknownInterface' do
|
77
|
-
expect { subject['eth1'] }.to raise_error(Vnstat::UnknownInterface)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
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
|
-
|
135
|
-
describe '#reload' do
|
136
|
-
before :each do
|
137
|
-
allow(described_class).to receive(:load_data).and_return('<test />')
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'sets #data using .load_data' do
|
141
|
-
expect(subject).to receive(:data=).with('<test />')
|
142
|
-
|
143
|
-
subject.reload
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'returns self' do
|
147
|
-
expect(subject.reload).to eq subject
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe '#rebuild' do
|
152
|
-
before :each do
|
153
|
-
allow(described_class).to receive(:load_data).and_return('<test />')
|
154
|
-
end
|
155
|
-
|
156
|
-
context 'when Vnstat::Utils.call_executable_returning_status ' \
|
157
|
-
'returns true' do
|
158
|
-
before :each do
|
159
|
-
allow(Vnstat::Utils)
|
160
|
-
.to receive(:call_executable_returning_status)
|
161
|
-
.with('--rebuildtotal').and_return(true)
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'returns self' do
|
165
|
-
expect(subject.rebuild).to eq subject
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'calls #reload' do
|
169
|
-
expect(subject).to receive(:reload)
|
170
|
-
|
171
|
-
subject.rebuild
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context 'when Vnstat::Utils.call_executable_returning_status ' \
|
176
|
-
'returns false' do
|
177
|
-
before :each do
|
178
|
-
allow(Vnstat::Utils)
|
179
|
-
.to receive(:call_executable_returning_status)
|
180
|
-
.with('--rebuildtotal').and_return(false)
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'returns self' do
|
184
|
-
expect(subject.rebuild).to eq subject
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'does not call #reload' do
|
188
|
-
expect(subject).not_to receive(:reload)
|
189
|
-
|
190
|
-
subject.rebuild
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
@@ -1,327 +0,0 @@
|
|
1
|
-
describe Vnstat::Interface do
|
2
|
-
let :data do
|
3
|
-
<<-XML
|
4
|
-
<vnstat version="1.12" xmlversion="1">
|
5
|
-
<interface id="eth0">
|
6
|
-
<id>eth0-test</id>
|
7
|
-
<nick>Ethernet</nick>
|
8
|
-
<created>
|
9
|
-
<date><year>2015</year><month>10</month><day>21</day></date>
|
10
|
-
</created>
|
11
|
-
<updated>
|
12
|
-
<date><year>2015</year><month>10</month><day>21</day></date>
|
13
|
-
<time><hour>22</hour><minute>58</minute></time>
|
14
|
-
</updated>
|
15
|
-
<traffic>
|
16
|
-
<total><rx>1000</rx><tx>2000</tx></total>
|
17
|
-
<days>
|
18
|
-
<day id="0">
|
19
|
-
<date><year>2015</year><month>1</month><day>1</day></date>
|
20
|
-
<rx>1000</rx><tx>2000</tx>
|
21
|
-
</day>
|
22
|
-
<day id="1">
|
23
|
-
<date><year>2015</year><month>1</month><day>2</day></date>
|
24
|
-
<rx>3000</rx><tx>4000</tx>
|
25
|
-
</day>
|
26
|
-
</days>
|
27
|
-
<months>
|
28
|
-
<month id="0">
|
29
|
-
<date><year>2015</year><month>1</month></date>
|
30
|
-
<rx>1000</rx><tx>2000</tx>
|
31
|
-
</month>
|
32
|
-
<month id="1">
|
33
|
-
<date><year>2015</year><month>2</month></date>
|
34
|
-
<rx>3000</rx><tx>4000</tx>
|
35
|
-
</month>
|
36
|
-
</months>
|
37
|
-
<tops>
|
38
|
-
<top id="0">
|
39
|
-
<date><year>2015</year><month>10</month><day>22</day></date>
|
40
|
-
<time><hour>00</hour><minute>00</minute></time>
|
41
|
-
<rx>1000</rx><tx>2000</tx>
|
42
|
-
</top>
|
43
|
-
<top id="1">
|
44
|
-
<date><year>2015</year><month>10</month><day>21</day></date>
|
45
|
-
<time><hour>19</hour><minute>53</minute></time>
|
46
|
-
<rx>3000</rx><tx>4000</tx>
|
47
|
-
</top>
|
48
|
-
</tops>
|
49
|
-
<hours>
|
50
|
-
<hour id="19">
|
51
|
-
<date><year>2015</year><month>10</month><day>21</day></date>
|
52
|
-
<rx>1000</rx><tx>2000</tx>
|
53
|
-
</hour>
|
54
|
-
<hour id="20">
|
55
|
-
<date><year>2015</year><month>10</month><day>21</day></date>
|
56
|
-
<rx>3000</rx><tx>4000</tx>
|
57
|
-
</hour>
|
58
|
-
</hours>
|
59
|
-
</traffic>
|
60
|
-
</interface>
|
61
|
-
</vnstat>
|
62
|
-
XML
|
63
|
-
end
|
64
|
-
|
65
|
-
subject { described_class.new('eth0', data) }
|
66
|
-
|
67
|
-
it { is_expected.to be_a Vnstat::Document }
|
68
|
-
|
69
|
-
describe '.open' do
|
70
|
-
it 'calls .new forwarding the first argument' do
|
71
|
-
allow(described_class).to receive(:load_data).with('test')
|
72
|
-
.and_return('test data')
|
73
|
-
|
74
|
-
expect(described_class).to receive(:new).with('test', 'test data')
|
75
|
-
|
76
|
-
described_class.open('test')
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'calls .load_data forwarding the argument' do
|
80
|
-
expect(described_class).to receive(:load_data).with('test')
|
81
|
-
.and_return('<vnstat />')
|
82
|
-
|
83
|
-
described_class.open('test')
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
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')
|
91
|
-
|
92
|
-
described_class.load_data('test')
|
93
|
-
end
|
94
|
-
|
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')
|
98
|
-
|
99
|
-
expect(described_class.load_data('eth0')).to eq 'test'
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe '#id' do
|
104
|
-
it 'returns id from the interface node' do
|
105
|
-
expect(subject.id).to eq 'eth0'
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
%w[nick name].each do |method_name|
|
110
|
-
describe "##{method_name}" do
|
111
|
-
it 'returns value from the nick node' do
|
112
|
-
expect(subject.public_send(method_name)).to eq 'Ethernet'
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "##{method_name}=" do
|
117
|
-
context 'when nickname can be set by vnstat' do
|
118
|
-
before :each do
|
119
|
-
allow(Vnstat::Utils).to receive(:call_executable_returning_status)
|
120
|
-
.and_return(true)
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'sets #nick to argument' do
|
124
|
-
expect { subject.nick = 'test' }.to change { subject.nick }.to('test')
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context 'when nickname cannot be set by vnstat' do
|
129
|
-
before :each do
|
130
|
-
allow(Vnstat::Utils).to receive(:call_executable_returning_status)
|
131
|
-
.and_return(false)
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'raises Vnstat::Error' do
|
135
|
-
expect { subject.nick = 'test' }.to raise_error(
|
136
|
-
Vnstat::Error, 'Unable to set nickname for interface (eth0). ' \
|
137
|
-
'Please make sure the vnstat daemon is not ' \
|
138
|
-
'running while performing this operation.'
|
139
|
-
)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe '#created_on' do
|
146
|
-
it 'returns the Date from the created node' do
|
147
|
-
date = Date.new(2015, 10, 21)
|
148
|
-
expect(subject.created_on).to eq date
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe '#updated_at' do
|
153
|
-
it 'returns the DateTime from the updated node in the correct time zone' do
|
154
|
-
time = DateTime.new(2015, 10, 21, 22, 58, 0o0, DateTime.now.offset)
|
155
|
-
|
156
|
-
expect(subject.updated_at).to eq time
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe '#total' do
|
161
|
-
it 'returns a Vnstat::Result' do
|
162
|
-
expect(subject.total).to be_a Vnstat::Result
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'returns a result with the correct bytes received' do
|
166
|
-
expect(subject.total.bytes_received).to eq(1000 * 1024)
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'returns a result with the correct bytes sent' do
|
170
|
-
expect(subject.total.bytes_sent).to eq(2000 * 1024)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe '#hours' do
|
175
|
-
it 'returns a Vnstat::Traffic::Hourly' do
|
176
|
-
expect(subject.hours).to be_a Vnstat::Traffic::Hourly
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'stores subject in Vnstat::Traffic::Hourly#interface' do
|
180
|
-
expect(subject.hours.interface).to eq subject
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe '#days' do
|
185
|
-
it 'returns a Vnstat::Traffic::Daily' do
|
186
|
-
expect(subject.days).to be_a Vnstat::Traffic::Daily
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'stores subject in Vnstat::Traffic::Daily#interface' do
|
190
|
-
expect(subject.days.interface).to eq subject
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe '#months' do
|
195
|
-
it 'returns a Vnstat::Traffic::Monthly' do
|
196
|
-
expect(subject.months).to be_a Vnstat::Traffic::Monthly
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'stores subject in Vnstat::Traffic::Monthly#interface' do
|
200
|
-
expect(subject.months.interface).to eq subject
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe '#tops' do
|
205
|
-
it 'returns a Vnstat::Traffic::Tops' do
|
206
|
-
expect(subject.tops).to be_a Vnstat::Traffic::Tops
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'stores subject in Vnstat::Traffic::Tops#interface' do
|
210
|
-
expect(subject.tops.interface).to eq subject
|
211
|
-
end
|
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
|
327
|
-
end
|