pio 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/pio/version.rb +1 -1
- data/pio.gemspec +30 -0
- data/spec/pio/dhcp_spec.rb +848 -144
- data/spec/pio/ipv4_address_spec.rb +258 -53
- data/spec/pio/mac_spec.rb +106 -29
- data/spec/spec_helper.rb +0 -1
- metadata +340 -32
@@ -9,91 +9,296 @@ describe Pio::IPv4Address do
|
|
9
9
|
context 'with 10.1.1.1' do
|
10
10
|
let(:ip_address) { '10.1.1.1' }
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
describe '#to_s' do
|
13
|
+
subject { super().to_s }
|
14
|
+
it { is_expected.to eq '10.1.1.1' }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#to_i' do
|
18
|
+
subject { super().to_i }
|
19
|
+
it { is_expected.to eq(((10 * 256 + 1) * 256 + 1) * 256 + 1) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#prefixlen' do
|
23
|
+
subject { super().prefixlen }
|
24
|
+
it { is_expected.to eq 32 }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#to_ary' do
|
28
|
+
subject { super().to_ary }
|
29
|
+
it { is_expected.to eq [0x0a, 0x01, 0x01, 0x01] }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#class_a?' do
|
33
|
+
subject { super().class_a? }
|
34
|
+
it { is_expected.to be_truthy }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#class_b?' do
|
38
|
+
subject { super().class_b? }
|
39
|
+
it { is_expected.to be_falsey }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#class_c?' do
|
43
|
+
subject { super().class_c? }
|
44
|
+
it { is_expected.to be_falsey }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#class_d?' do
|
48
|
+
subject { super().class_d? }
|
49
|
+
it { is_expected.to be_falsey }
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#class_e?' do
|
53
|
+
subject { super().class_e? }
|
54
|
+
it { is_expected.to be_falsey }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#unicast?' do
|
58
|
+
subject { super().unicast? }
|
59
|
+
it { is_expected.to be_truthy }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#multicast?' do
|
63
|
+
subject { super().multicast? }
|
64
|
+
it { is_expected.to be_falsey }
|
65
|
+
end
|
23
66
|
|
24
67
|
context '.mask!' do
|
25
68
|
subject { ipv4.mask!(mask) }
|
26
69
|
|
27
70
|
let(:mask) { 8 }
|
28
71
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
72
|
+
describe '#to_s' do
|
73
|
+
subject { super().to_s }
|
74
|
+
it { is_expected.to eq '10.0.0.0' }
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#to_i' do
|
78
|
+
subject { super().to_i }
|
79
|
+
it { is_expected.to eq 10 * 256 * 256 * 256 }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#to_ary' do
|
83
|
+
subject { super().to_ary }
|
84
|
+
it { is_expected.to eq [0x0a, 0x00, 0x00, 0x00] }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#class_a?' do
|
88
|
+
subject { super().class_a? }
|
89
|
+
it { is_expected.to be_truthy }
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#class_b?' do
|
93
|
+
subject { super().class_b? }
|
94
|
+
it { is_expected.to be_falsey }
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#class_c?' do
|
98
|
+
subject { super().class_c? }
|
99
|
+
it { is_expected.to be_falsey }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#class_d?' do
|
103
|
+
subject { super().class_d? }
|
104
|
+
it { is_expected.to be_falsey }
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#class_e?' do
|
108
|
+
subject { super().class_e? }
|
109
|
+
it { is_expected.to be_falsey }
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#unicast?' do
|
113
|
+
subject { super().unicast? }
|
114
|
+
it { is_expected.to be_truthy }
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#multicast?' do
|
118
|
+
subject { super().multicast? }
|
119
|
+
it { is_expected.to be_falsey }
|
120
|
+
end
|
39
121
|
end
|
40
122
|
end
|
41
123
|
|
42
124
|
context 'with 172.20.1.1' do
|
43
125
|
let(:ip_address) { '172.20.1.1' }
|
44
126
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
127
|
+
describe '#to_s' do
|
128
|
+
subject { super().to_s }
|
129
|
+
it { is_expected.to eq '172.20.1.1' }
|
130
|
+
end
|
131
|
+
|
132
|
+
describe '#to_i' do
|
133
|
+
subject { super().to_i }
|
134
|
+
it { is_expected.to eq(((172 * 256 + 20) * 256 + 1) * 256 + 1) }
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#to_ary' do
|
138
|
+
subject { super().to_ary }
|
139
|
+
it { is_expected.to eq [0xac, 0x14, 0x01, 0x01] }
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#class_a?' do
|
143
|
+
subject { super().class_a? }
|
144
|
+
it { is_expected.to be_falsey }
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#class_b?' do
|
148
|
+
subject { super().class_b? }
|
149
|
+
it { is_expected.to be_truthy }
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#class_c?' do
|
153
|
+
subject { super().class_c? }
|
154
|
+
it { is_expected.to be_falsey }
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#class_d?' do
|
158
|
+
subject { super().class_d? }
|
159
|
+
it { is_expected.to be_falsey }
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#class_e?' do
|
163
|
+
subject { super().class_e? }
|
164
|
+
it { is_expected.to be_falsey }
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '#unicast?' do
|
168
|
+
subject { super().unicast? }
|
169
|
+
it { is_expected.to be_truthy }
|
170
|
+
end
|
171
|
+
|
172
|
+
describe '#multicast?' do
|
173
|
+
subject { super().multicast? }
|
174
|
+
it { is_expected.to be_falsey }
|
175
|
+
end
|
55
176
|
end
|
56
177
|
|
57
178
|
context 'with 192.168.1.1' do
|
58
179
|
let(:ip_address) { '192.168.1.1' }
|
59
180
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
181
|
+
describe '#to_s' do
|
182
|
+
subject { super().to_s }
|
183
|
+
it { is_expected.to eq '192.168.1.1' }
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#to_i' do
|
187
|
+
subject { super().to_i }
|
188
|
+
it { is_expected.to eq 3_232_235_777 }
|
189
|
+
end
|
190
|
+
|
191
|
+
describe '#to_ary' do
|
192
|
+
subject { super().to_ary }
|
193
|
+
it { is_expected.to eq [0xc0, 0xa8, 0x01, 0x01] }
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#class_a?' do
|
197
|
+
subject { super().class_a? }
|
198
|
+
it { is_expected.to be_falsey }
|
199
|
+
end
|
200
|
+
|
201
|
+
describe '#class_b?' do
|
202
|
+
subject { super().class_b? }
|
203
|
+
it { is_expected.to be_falsey }
|
204
|
+
end
|
205
|
+
|
206
|
+
describe '#class_c?' do
|
207
|
+
subject { super().class_c? }
|
208
|
+
it { is_expected.to be_truthy }
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '#class_d?' do
|
212
|
+
subject { super().class_d? }
|
213
|
+
it { is_expected.to be_falsey }
|
214
|
+
end
|
215
|
+
|
216
|
+
describe '#class_e?' do
|
217
|
+
subject { super().class_e? }
|
218
|
+
it { is_expected.to be_falsey }
|
219
|
+
end
|
220
|
+
|
221
|
+
describe '#unicast?' do
|
222
|
+
subject { super().unicast? }
|
223
|
+
it { is_expected.to be_truthy }
|
224
|
+
end
|
225
|
+
|
226
|
+
describe '#multicast?' do
|
227
|
+
subject { super().multicast? }
|
228
|
+
it { is_expected.to be_falsey }
|
229
|
+
end
|
70
230
|
end
|
71
231
|
|
72
232
|
context 'with 234.1.1.1' do
|
73
233
|
let(:ip_address) { '234.1.1.1' }
|
74
234
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
235
|
+
describe '#to_s' do
|
236
|
+
subject { super().to_s }
|
237
|
+
it { is_expected.to eq '234.1.1.1' }
|
238
|
+
end
|
239
|
+
|
240
|
+
describe '#to_i' do
|
241
|
+
subject { super().to_i }
|
242
|
+
it { is_expected.to eq(((234 * 256 + 1) * 256 + 1) * 256 + 1) }
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#to_ary' do
|
246
|
+
subject { super().to_ary }
|
247
|
+
it { is_expected.to eq [0xea, 0x01, 0x01, 0x01] }
|
248
|
+
end
|
249
|
+
|
250
|
+
describe '#class_a?' do
|
251
|
+
subject { super().class_a? }
|
252
|
+
it { is_expected.to be_falsey }
|
253
|
+
end
|
254
|
+
|
255
|
+
describe '#class_b?' do
|
256
|
+
subject { super().class_b? }
|
257
|
+
it { is_expected.to be_falsey }
|
258
|
+
end
|
259
|
+
|
260
|
+
describe '#class_c?' do
|
261
|
+
subject { super().class_c? }
|
262
|
+
it { is_expected.to be_falsey }
|
263
|
+
end
|
264
|
+
|
265
|
+
describe '#class_d?' do
|
266
|
+
subject { super().class_d? }
|
267
|
+
it { is_expected.to be_truthy }
|
268
|
+
end
|
269
|
+
|
270
|
+
describe '#class_e?' do
|
271
|
+
subject { super().class_e? }
|
272
|
+
it { is_expected.to be_falsey }
|
273
|
+
end
|
274
|
+
|
275
|
+
describe '#unicast?' do
|
276
|
+
subject { super().unicast? }
|
277
|
+
it { is_expected.to be_falsey }
|
278
|
+
end
|
279
|
+
|
280
|
+
describe '#multicast?' do
|
281
|
+
subject { super().multicast? }
|
282
|
+
it { is_expected.to be_truthy }
|
283
|
+
end
|
85
284
|
end
|
86
285
|
|
87
286
|
context 'with 192.168.0.1/16' do
|
88
287
|
let(:ip_address) { '192.168.0.1/16' }
|
89
288
|
|
90
|
-
|
289
|
+
describe '#prefixlen' do
|
290
|
+
subject { super().prefixlen }
|
291
|
+
it { is_expected.to eq 16 }
|
292
|
+
end
|
91
293
|
end
|
92
294
|
|
93
295
|
context 'with 192.168.0.1/255.255.255.0' do
|
94
296
|
let(:ip_address) { '192.168.0.1/255.255.255.0' }
|
95
297
|
|
96
|
-
|
298
|
+
describe '#prefixlen' do
|
299
|
+
subject { super().prefixlen }
|
300
|
+
it { is_expected.to eq 24 }
|
301
|
+
end
|
97
302
|
end
|
98
303
|
end
|
99
304
|
end
|
data/spec/pio/mac_spec.rb
CHANGED
@@ -9,13 +9,13 @@ describe Pio::Mac do
|
|
9
9
|
let(:value) { '11:22:33:44:55:66' }
|
10
10
|
|
11
11
|
describe '#==' do
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
12
|
+
it { is_expected.to eq Pio::Mac.new('11:22:33:44:55:66') }
|
13
|
+
it { is_expected.to eq '11:22:33:44:55:66' }
|
14
|
+
it { is_expected.not_to eq Pio::Mac.new('66:55:44:33:22:11') }
|
15
|
+
it { is_expected.not_to eq '66:55:44:33:22:11' }
|
16
|
+
it { is_expected.to eq 0x112233445566 }
|
17
|
+
it { is_expected.not_to eq 42 }
|
18
|
+
it { is_expected.not_to eq 'INVALID_MAC_ADDRESS' }
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#eql?' do
|
@@ -28,20 +28,45 @@ describe Pio::Mac do
|
|
28
28
|
it { expect(subject).not_to eql 'INVALID_MAC_ADDRESS' }
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
describe '#hash' do
|
32
|
+
subject { super().hash }
|
33
|
+
it { is_expected.to eq Pio::Mac.new('11:22:33:44:55:66').hash }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#to_i' do
|
37
|
+
subject { super().to_i }
|
38
|
+
it { is_expected.to eq 0x112233445566 }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#to_a' do
|
42
|
+
subject { super().to_a }
|
43
|
+
it { is_expected.to eq [0x11, 0x22, 0x33, 0x44, 0x55, 0x66] }
|
44
|
+
end
|
32
45
|
|
33
|
-
|
34
|
-
|
35
|
-
|
46
|
+
describe '#to_s' do
|
47
|
+
subject { super().to_s }
|
48
|
+
it { is_expected.to eq '11:22:33:44:55:66' }
|
49
|
+
end
|
36
50
|
describe '#to_str' do
|
37
51
|
context 'when "MAC = " + subject' do
|
38
52
|
it { expect('MAC = ' + subject).to eq 'MAC = 11:22:33:44:55:66' }
|
39
53
|
end
|
40
54
|
end
|
41
55
|
|
42
|
-
|
43
|
-
|
44
|
-
|
56
|
+
describe '#multicast?' do
|
57
|
+
subject { super().multicast? }
|
58
|
+
it { is_expected.to be_truthy }
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#broadcast?' do
|
62
|
+
subject { super().broadcast? }
|
63
|
+
it { is_expected.to be_falsey }
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#reserved?' do
|
67
|
+
subject { super().reserved? }
|
68
|
+
it { is_expected.to be_falsey }
|
69
|
+
end
|
45
70
|
end
|
46
71
|
|
47
72
|
context 'with reserved address' do
|
@@ -51,7 +76,11 @@ describe Pio::Mac do
|
|
51
76
|
|
52
77
|
context "when #{ reserved_address }" do
|
53
78
|
let(:value) { reserved_address }
|
54
|
-
|
79
|
+
|
80
|
+
describe '#reserved?' do
|
81
|
+
subject { super().reserved? }
|
82
|
+
it { is_expected.to be_truthy }
|
83
|
+
end
|
55
84
|
end
|
56
85
|
end
|
57
86
|
end
|
@@ -59,25 +88,73 @@ describe Pio::Mac do
|
|
59
88
|
context 'with 0' do
|
60
89
|
let(:value) { 0 }
|
61
90
|
|
62
|
-
it {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
91
|
+
it { is_expected.to eq Pio::Mac.new(0) }
|
92
|
+
|
93
|
+
describe '#to_i' do
|
94
|
+
subject { super().to_i }
|
95
|
+
it { is_expected.to eq 0 }
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#to_a' do
|
99
|
+
subject { super().to_a }
|
100
|
+
it { is_expected.to eq [0x00, 0x00, 0x00, 0x00, 0x00, 0x00] }
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#to_s' do
|
104
|
+
subject { super().to_s }
|
105
|
+
it { is_expected.to eq '00:00:00:00:00:00' }
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#multicast?' do
|
109
|
+
subject { super().multicast? }
|
110
|
+
it { is_expected.to be_falsey }
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#broadcast?' do
|
114
|
+
subject { super().broadcast? }
|
115
|
+
it { is_expected.to be_falsey }
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#reserved?' do
|
119
|
+
subject { super().reserved? }
|
120
|
+
it { is_expected.to be_falsey }
|
121
|
+
end
|
69
122
|
end
|
70
123
|
|
71
124
|
context 'with 0xffffffffffff' do
|
72
125
|
let(:value) { 0xffffffffffff }
|
73
126
|
|
74
|
-
it {
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
127
|
+
it { is_expected.to eq Pio::Mac.new(0xffffffffffff) }
|
128
|
+
|
129
|
+
describe '#to_i' do
|
130
|
+
subject { super().to_i }
|
131
|
+
it { is_expected.to eq 0xffffffffffff }
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#to_a' do
|
135
|
+
subject { super().to_a }
|
136
|
+
it { is_expected.to eq [0xff, 0xff, 0xff, 0xff, 0xff, 0xff] }
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#to_s' do
|
140
|
+
subject { super().to_s }
|
141
|
+
it { is_expected.to eq 'ff:ff:ff:ff:ff:ff' }
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#multicast?' do
|
145
|
+
subject { super().multicast? }
|
146
|
+
it { is_expected.to be_truthy }
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#broadcast?' do
|
150
|
+
subject { super().broadcast? }
|
151
|
+
it { is_expected.to be_truthy }
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#reserved?' do
|
155
|
+
subject { super().reserved? }
|
156
|
+
it { is_expected.to be_falsey }
|
157
|
+
end
|
81
158
|
end
|
82
159
|
|
83
160
|
context 'with "INVALID MAC ADDRESS"' do
|