uuidtools 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +15 -0
- data/LICENSE.txt +202 -0
- data/README.md +37 -0
- data/Rakefile +10 -23
- data/lib/uuidtools.rb +363 -172
- data/lib/uuidtools/version.rb +16 -21
- data/spec/spec_helper.rb +2 -0
- data/spec/uuidtools/mac_address_spec.rb +442 -3
- data/spec/uuidtools/utility_spec.rb +5 -5
- data/spec/uuidtools/uuid_creation_spec.rb +50 -41
- data/spec/uuidtools/uuid_parsing_spec.rb +63 -43
- data/tasks/benchmark.rake +46 -27
- data/tasks/gem.rake +31 -18
- data/tasks/rspec.rake +55 -0
- data/tasks/yard.rake +22 -0
- data/uuidtools.gemspec +42 -0
- metadata +84 -68
- data/LICENSE +0 -20
- data/README +0 -13
- data/tasks/clobber.rake +0 -2
- data/tasks/rdoc.rake +0 -29
- data/tasks/rubyforge.rake +0 -89
- data/tasks/spec.rake +0 -64
data/lib/uuidtools/version.rb
CHANGED
@@ -1,33 +1,28 @@
|
|
1
|
+
# encoding:utf-8
|
1
2
|
#--
|
2
|
-
#
|
3
|
+
# Copyright (C) 2005-2014 Bob Aman
|
3
4
|
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
11
8
|
#
|
12
|
-
#
|
13
|
-
# included in all copies or substantial portions of the Software.
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
10
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
22
16
|
#++
|
23
17
|
|
18
|
+
|
24
19
|
# Used to prevent the class/module from being loaded more than once
|
25
|
-
unless defined?
|
26
|
-
|
20
|
+
unless defined? UUIDTools::VERSION
|
21
|
+
module UUIDTools
|
27
22
|
module VERSION #:nodoc:
|
28
23
|
MAJOR = 2
|
29
|
-
MINOR =
|
30
|
-
TINY =
|
24
|
+
MINOR = 2
|
25
|
+
TINY = 0
|
31
26
|
|
32
27
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
33
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,237 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path("../../spec_helper.rb", __FILE__)
|
2
|
+
|
3
|
+
def pending_if_root_required
|
4
|
+
if @mac_address == nil
|
5
|
+
output = `ifconfig -a 2>&1`
|
6
|
+
if output =~ /inet/ &&
|
7
|
+
output =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ &&
|
8
|
+
output =~ /Warning: cannot open/
|
9
|
+
pending("Cannot get MAC address without root?")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# ===========================================================================
|
15
|
+
#
|
16
|
+
# Samples of ifconfig -a output
|
17
|
+
#
|
18
|
+
# ===========================================================================
|
19
|
+
|
20
|
+
#
|
21
|
+
# solaris
|
22
|
+
#
|
23
|
+
solaris_sample = <<EOF
|
24
|
+
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
|
25
|
+
inet 127.0.0.1 netmask ff000000
|
26
|
+
igb1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
|
27
|
+
inet 10.51.0.18 netmask ffffff00 broadcast 10.51.0.255
|
28
|
+
ether 0:21:28:fa:c6:65
|
29
|
+
igb2: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
|
30
|
+
inet 10.99.0.12 netmask ffffff00 broadcast 10.99.0.255
|
31
|
+
ether 0:21:28:fa:c6:66
|
32
|
+
EOF
|
33
|
+
|
34
|
+
solaris_mac = "00:21:28:fa:c6:65"
|
35
|
+
|
36
|
+
#
|
37
|
+
# windows
|
38
|
+
#
|
39
|
+
windows_sample = <<EOF
|
40
|
+
Windows IP Configuration
|
41
|
+
|
42
|
+
Host Name . . . . . . . . . . . . : OFFICE
|
43
|
+
Primary Dns Suffix . . . . . . . :
|
44
|
+
Node Type . . . . . . . . . . . . : Unknown
|
45
|
+
IP Routing Enabled. . . . . . . . : No
|
46
|
+
WINS Proxy Enabled. . . . . . . . : No
|
47
|
+
|
48
|
+
Ethernet adapter Local Area Connection:
|
49
|
+
|
50
|
+
Connection-specific DNS Suffix . :
|
51
|
+
Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller
|
52
|
+
Physical Address. . . . . . . . . : E0-CB-4E-5D-BC-E9
|
53
|
+
Dhcp Enabled. . . . . . . . . . . : No
|
54
|
+
IP Address. . . . . . . . . . . . : 192.168.1.10
|
55
|
+
Subnet Mask . . . . . . . . . . . : 255.255.255.0
|
56
|
+
Default Gateway . . . . . . . . . : 192.168.1.1
|
57
|
+
DNS Servers . . . . . . . . . . . : 192.168.1.1
|
58
|
+
4.2.2.1
|
59
|
+
EOF
|
60
|
+
|
61
|
+
windows_mac = "e0:cb:4e:5d:bc:e9"
|
62
|
+
|
63
|
+
#
|
64
|
+
# linux
|
65
|
+
#
|
66
|
+
linux_sample = <<EOF
|
67
|
+
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
|
68
|
+
inet 10.16.187.71 netmask 255.255.252.0 broadcast 10.16.187.255
|
69
|
+
inet6 fe80::226:2dff:fef6:b94 prefixlen 64 scopeid 0x20<link>
|
70
|
+
ether 00:26:2d:f6:0b:94 txqueuelen 1000 (Ethernet)
|
71
|
+
RX packets 172074 bytes 82784684 (78.9 MiB)
|
72
|
+
RX errors 0 dropped 0 overruns 0 frame 0
|
73
|
+
TX packets 99075 bytes 23551085 (22.4 MiB)
|
74
|
+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
75
|
+
device interrupt 20 memory 0xf2600000-f2620000
|
76
|
+
|
77
|
+
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
|
78
|
+
inet 127.0.0.1 netmask 255.0.0.0
|
79
|
+
inet6 ::1 prefixlen 128 scopeid 0x10<host>
|
80
|
+
loop txqueuelen 0 (Local Loopback)
|
81
|
+
RX packets 20 bytes 2148 (2.0 KiB)
|
82
|
+
RX errors 0 dropped 0 overruns 0 frame 0
|
83
|
+
TX packets 20 bytes 2148 (2.0 KiB)
|
84
|
+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
85
|
+
EOF
|
86
|
+
|
87
|
+
linux_mac = "00:26:2d:f6:0b:94"
|
88
|
+
|
89
|
+
#
|
90
|
+
# alternate linux
|
91
|
+
#
|
92
|
+
linux_sample_2 = <<EOF
|
93
|
+
eth0 Link encap:Ethernet HWaddr 00:80:C8:F8:4A:51
|
94
|
+
inet addr:192.168.99.35 Bcast:192.168.99.255 Mask:255.255.255.0
|
95
|
+
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
96
|
+
RX packets:190312 errors:0 dropped:0 overruns:0 frame:0
|
97
|
+
TX packets:86955 errors:0 dropped:0 overruns:0 carrier:0
|
98
|
+
collisions:0 txqueuelen:100
|
99
|
+
RX bytes:30701229 (29.2 Mb) TX bytes:7878951 (7.5 Mb)
|
100
|
+
Interrupt:9 Base address:0x5000
|
101
|
+
|
102
|
+
lo Link encap:Local Loopback
|
103
|
+
inet addr:127.0.0.1 Mask:255.0.0.0
|
104
|
+
UP LOOPBACK RUNNING MTU:16436 Metric:1
|
105
|
+
RX packets:306 errors:0 dropped:0 overruns:0 frame:0
|
106
|
+
TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
|
107
|
+
collisions:0 txqueuelen:0
|
108
|
+
RX bytes:29504 (28.8 Kb) TX bytes:29504 (28.8 Kb)
|
109
|
+
EOF
|
110
|
+
|
111
|
+
linux_mac_2 = "00:80:c8:f8:4a:51"
|
112
|
+
|
113
|
+
linux_ip_sample = <<EOF
|
114
|
+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
|
115
|
+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
116
|
+
inet 127.0.0.1/8 scope host lo
|
117
|
+
inet6 ::1/128 scope host
|
118
|
+
valid_lft forever preferred_lft forever
|
119
|
+
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
|
120
|
+
link/ether 00:26:2d:f6:0b:94 brd ff:ff:ff:ff:ff:ff
|
121
|
+
inet 10.16.187.125/22 brd 10.16.187.255 scope global eth0
|
122
|
+
inet6 fe80::226:2dff:fef6:b94/64 scope link
|
123
|
+
valid_lft forever preferred_lft forever
|
124
|
+
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000
|
125
|
+
link/ether 00:26:c6:c6:1a:b4 brd ff:ff:ff:ff:ff:ff
|
126
|
+
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
|
127
|
+
link/ether 52:54:00:e3:cf:d3 brd ff:ff:ff:ff:ff:ff
|
128
|
+
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
|
129
|
+
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
|
130
|
+
link/ether 52:54:00:e3:cf:d3 brd ff:ff:ff:ff:ff:ff
|
131
|
+
EOF
|
132
|
+
|
133
|
+
linux_ip_mac = "00:26:2d:f6:0b:94"
|
134
|
+
|
135
|
+
#
|
136
|
+
# freebsd
|
137
|
+
#
|
138
|
+
freebsd_sample = <<EOF
|
139
|
+
igb0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
|
140
|
+
options=401bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,VLAN_HWTSO>
|
141
|
+
ether 00:25:90:2b:81:32
|
142
|
+
inet6 fe80::225:90ff:fe2b:8132%igb0 prefixlen 64 scopeid 0x1
|
143
|
+
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
|
144
|
+
media: Ethernet autoselect (1000baseT <full-duplex>)
|
145
|
+
status: active
|
146
|
+
igb1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
|
147
|
+
options=401bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,VLAN_HWTSO>
|
148
|
+
ether 00:25:90:2b:81:32
|
149
|
+
inet6 fe80::225:90ff:fe2b:8133%igb1 prefixlen 64 scopeid 0x2
|
150
|
+
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
|
151
|
+
media: Ethernet autoselect (1000baseT <full-duplex>)
|
152
|
+
EOF
|
153
|
+
|
154
|
+
freebsd_mac = "00:25:90:2b:81:32"
|
155
|
+
|
156
|
+
#
|
157
|
+
# openbsd
|
158
|
+
#
|
159
|
+
openbsd_sample = <<EOF
|
160
|
+
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33200
|
161
|
+
priority: 0
|
162
|
+
groups: lo
|
163
|
+
inet 127.0.0.1 netmask 0xff000000
|
164
|
+
inet6 ::1 prefixlen 128
|
165
|
+
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5
|
166
|
+
vr0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
|
167
|
+
lladdr 00:0d:b9:28:ab:44
|
168
|
+
priority: 0
|
169
|
+
media: Ethernet autoselect (100baseTX full-duplex)
|
170
|
+
status: active
|
171
|
+
inet 192.168.7.2 netmask 0xffffff00 broadcast 192.168.7.255
|
172
|
+
inet6 fe80::20d:b9ff:fe28:ab44%vr0 prefixlen 64 scopeid 0x1
|
173
|
+
EOF
|
174
|
+
|
175
|
+
openbsd_mac = "00:0d:b9:28:ab:44"
|
176
|
+
|
177
|
+
#
|
178
|
+
# MacOS 10
|
179
|
+
#
|
180
|
+
macos_sample = <<EOF
|
181
|
+
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
|
182
|
+
options=3<RXCSUM,TXCSUM>
|
183
|
+
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
|
184
|
+
inet 127.0.0.1 netmask 0xff000000
|
185
|
+
inet6 ::1 prefixlen 128
|
186
|
+
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
|
187
|
+
stf0: flags=0<> mtu 1280
|
188
|
+
en0: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
|
189
|
+
options=27<RXCSUM,TXCSUM,VLAN_MTU,TSO4>
|
190
|
+
ether 58:b0:35:a4:cd:0c
|
191
|
+
inet6 fe80::5ab0:35ff:fea4:cd0c%en0 prefixlen 64 scopeid 0x4
|
192
|
+
inet 192.168.142.136 netmask 0xfffffff0 broadcast 192.168.142.143
|
193
|
+
media: autoselect (1000baseT <full-duplex,flow-control>)
|
194
|
+
status: active
|
195
|
+
en1: flags=8823<UP,BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500
|
196
|
+
ether d8:30:62:51:dd:3d
|
197
|
+
media: autoselect (<unknown type>)
|
198
|
+
status: inactive
|
199
|
+
p2p0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 2304
|
200
|
+
ether 0a:30:62:51:dd:3d
|
201
|
+
media: autoselect
|
202
|
+
status: inactive
|
203
|
+
EOF
|
204
|
+
|
205
|
+
macos_mac = "58:b0:35:a4:cd:0c"
|
206
|
+
|
207
|
+
# Gather the samples and MAC addresses for simple access
|
208
|
+
samples = {
|
209
|
+
:macos => macos_sample,
|
210
|
+
:windows => windows_sample,
|
211
|
+
:solaris => solaris_sample,
|
212
|
+
:freebsd => freebsd_sample,
|
213
|
+
:openbsd => openbsd_sample,
|
214
|
+
:linux => linux_sample,
|
215
|
+
:linux2 => linux_sample_2,
|
216
|
+
:linuxip => linux_ip_sample
|
217
|
+
}
|
218
|
+
|
219
|
+
macs = {
|
220
|
+
:macos => macos_mac,
|
221
|
+
:windows => windows_mac,
|
222
|
+
:solaris => solaris_mac,
|
223
|
+
:freebsd => freebsd_mac,
|
224
|
+
:openbsd => openbsd_mac,
|
225
|
+
:linux => linux_mac,
|
226
|
+
:linux2 => linux_mac_2,
|
227
|
+
:linuxip => linux_ip_mac
|
228
|
+
}
|
229
|
+
|
230
|
+
# --------------------------------------------------------------------------
|
231
|
+
#
|
232
|
+
# TESTS
|
233
|
+
#
|
234
|
+
# --------------------------------------------------------------------------
|
2
235
|
|
3
236
|
describe UUIDTools::UUID, "when obtaining a MAC address" do
|
4
237
|
before do
|
@@ -6,10 +239,216 @@ describe UUIDTools::UUID, "when obtaining a MAC address" do
|
|
6
239
|
end
|
7
240
|
|
8
241
|
it "should obtain a MAC address" do
|
9
|
-
|
242
|
+
pending_if_root_required()
|
243
|
+
expect(@mac_address).not_to be_nil
|
10
244
|
end
|
11
245
|
|
12
246
|
it "should cache the MAC address" do
|
13
|
-
|
247
|
+
pending_if_root_required()
|
248
|
+
expect(@mac_address.object_id).to eql(UUIDTools::UUID.mac_address.object_id)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe UUIDTools::UUID, "before obtaining a MAC address" do
|
253
|
+
|
254
|
+
before do
|
255
|
+
module UUIDTools
|
256
|
+
class UUID
|
257
|
+
remove_class_variable(:@@mac_address) if defined?(@@mac_address)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should parse windows MAC addresses" do
|
263
|
+
# mock ifconfig() to return the windows sample
|
264
|
+
allow(UUIDTools::UUID).to receive(:ifconfig) { samples[:windows] }
|
265
|
+
mac = UUIDTools::UUID.mac_address
|
266
|
+
expect(mac).to eql(macs[:windows])
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should parse solaris MAC addresses" do
|
270
|
+
allow(UUIDTools::UUID).to receive(:ifconfig) { samples[:solaris] }
|
271
|
+
mac = UUIDTools::UUID.mac_address
|
272
|
+
expect(mac).to eql(macs[:solaris])
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should parse freebsd MAC addresses" do
|
276
|
+
allow(UUIDTools::UUID).to receive(:ifconfig) { samples[:freebsd] }
|
277
|
+
mac = UUIDTools::UUID.mac_address
|
278
|
+
expect(mac).to eql(macs[:freebsd])
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should parse openbsd MAC addresses" do
|
282
|
+
allow(UUIDTools::UUID).to receive(:ifconfig) { samples[:openbsd] }
|
283
|
+
mac = UUIDTools::UUID.mac_address
|
284
|
+
expect(mac).to eql(macs[:openbsd])
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should parse linux MAC addresses with ifconfig" do
|
288
|
+
allow(UUIDTools::UUID).to receive(:ifconfig) { samples[:linux] }
|
289
|
+
mac = UUIDTools::UUID.mac_address
|
290
|
+
expect(mac).to eql(macs[:linux])
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should parse a linux HWaddr address with ifconfig" do
|
294
|
+
allow(UUIDTools::UUID).to receive(:ifconfig) { samples[:linux2] }
|
295
|
+
mac = UUIDTools::UUID.mac_address
|
296
|
+
expect(mac).to eql(macs[:linux2])
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should parse macos MAC addresses with ifconfig" do
|
300
|
+
allow(UUIDTools::UUID).to receive(:ifconfig) { samples[:macos] }
|
301
|
+
mac = UUIDTools::UUID.mac_address
|
302
|
+
expect(mac).to eql(macs[:macos])
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should parse linux MAC addresses with ip" do
|
306
|
+
allow(UUIDTools::UUID).to receive(:ifconfig) { samples[:linuxip] }
|
307
|
+
mac = UUIDTools::UUID.mac_address
|
308
|
+
expect(mac).to eql(macs[:linuxip])
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should identify the default os classes" do
|
312
|
+
module RbConfig
|
313
|
+
CONFIG['target_os'] = nil
|
314
|
+
end
|
315
|
+
|
316
|
+
os_class = UUIDTools::UUID.os_class
|
317
|
+
expect(os_class).to be_nil
|
318
|
+
|
319
|
+
RbConfig::CONFIG['target_os'] = 'linux'
|
320
|
+
os_class = UUIDTools::UUID.os_class
|
321
|
+
expect(os_class).to be_nil
|
322
|
+
|
323
|
+
RbConfig::CONFIG['target_os'] = 'darwin'
|
324
|
+
os_class = UUIDTools::UUID.os_class
|
325
|
+
expect(os_class).to be_nil
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should identify the solaris os classes" do
|
329
|
+
module RbConfig
|
330
|
+
CONFIG['target_os'] = "solaris"
|
331
|
+
end
|
332
|
+
|
333
|
+
os_class = UUIDTools::UUID.os_class
|
334
|
+
expect(os_class).to eql(:solaris)
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should identify the BSD os classes" do
|
338
|
+
module RbConfig
|
339
|
+
CONFIG['target_os'] = "netbsd"
|
340
|
+
end
|
341
|
+
|
342
|
+
os_class = UUIDTools::UUID.os_class
|
343
|
+
expect(os_class).to eql(:netbsd)
|
344
|
+
|
345
|
+
RbConfig::CONFIG['target_os'] = "openbsd"
|
346
|
+
os_class = UUIDTools::UUID.os_class
|
347
|
+
expect(os_class).to eql(:openbsd)
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should identify the Windows os classes" do
|
352
|
+
module RbConfig
|
353
|
+
CONFIG['target_os'] = "win"
|
354
|
+
end
|
355
|
+
os_class = UUIDTools::UUID.os_class
|
356
|
+
expect(os_class).to eql(:windows)
|
357
|
+
|
358
|
+
RbConfig::CONFIG['target_os'] = "w32"
|
359
|
+
os_class = UUIDTools::UUID.os_class
|
360
|
+
expect(os_class).to eql(:windows)
|
361
|
+
|
362
|
+
RbConfig::CONFIG['target_os'] = "darwin"
|
363
|
+
os_class = UUIDTools::UUID.os_class
|
364
|
+
expect(os_class).to be_nil
|
365
|
+
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should find the ifconfig program" do
|
369
|
+
save_ifconfig_command = UUIDTools::UUID.ifconfig_command
|
370
|
+
save_ifconfig_path = UUIDTools::UUID.ifconfig_path_default
|
371
|
+
|
372
|
+
# this should always exist
|
373
|
+
UUIDTools::UUID.ifconfig_command="sh"
|
374
|
+
UUIDTools::UUID.ifconfig_path_default="notfound"
|
375
|
+
ifconfig_path = UUIDTools::UUID.ifconfig_path
|
376
|
+
# expect(ifconfig_path).to eql("/usr/bin/sh")
|
377
|
+
|
378
|
+
# Test what happens if it does not
|
379
|
+
UUIDTools::UUID.ifconfig_command="nosuchthing"
|
380
|
+
UUIDTools::UUID.ifconfig_path_default="default"
|
381
|
+
|
382
|
+
# ifconfig_path checks if the IFCONFIG_PATH command file exists
|
383
|
+
allow(File).to receive(:exist?) { true }
|
384
|
+
|
385
|
+
ifconfig_path = UUIDTools::UUID.ifconfig_path
|
386
|
+
# expect(ifconfig_path).to eql("default")
|
387
|
+
|
388
|
+
UUIDTools::UUID.ifconfig_command=save_ifconfig_command
|
389
|
+
UUIDTools::UUID.ifconfig_path_default=save_ifconfig_path
|
390
|
+
|
391
|
+
end
|
392
|
+
|
393
|
+
it "should find the ip program" do
|
394
|
+
save_ip_command = UUIDTools::UUID.ip_command
|
395
|
+
save_ip_path = UUIDTools::UUID.ip_path_default
|
396
|
+
|
397
|
+
# this should always exist
|
398
|
+
UUIDTools::UUID.ip_command="sh"
|
399
|
+
UUIDTools::UUID.ip_path_default="notfound"
|
400
|
+
ip_path = UUIDTools::UUID.ip_path
|
401
|
+
# expect(ip_path).to eql("/usr/bin/sh")
|
402
|
+
|
403
|
+
# Test what happens if it does not
|
404
|
+
UUIDTools::UUID.ip_command="nosuchthing"
|
405
|
+
UUIDTools::UUID.ip_path_default="default"
|
406
|
+
|
407
|
+
# ifconfig_path checks if the IP_PATH command file exists
|
408
|
+
allow(File).to receive(:exist?) { true }
|
409
|
+
|
410
|
+
ifconfig_path = UUIDTools::UUID.ip_path
|
411
|
+
# expect(ifconfig_path).to eql("default")
|
412
|
+
|
413
|
+
UUIDTools::UUID.ip_command=save_ip_command
|
414
|
+
UUIDTools::UUID.ip_path_default=save_ip_path
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should be able to parse windows ipconfig output" do
|
418
|
+
mac = UUIDTools::UUID.first_mac samples[:windows]
|
419
|
+
expect(mac).to eql(macs[:windows])
|
420
|
+
end
|
421
|
+
|
422
|
+
it "should be able to parse solaris ifconfig output" do
|
423
|
+
mac = UUIDTools::UUID.first_mac samples[:solaris]
|
424
|
+
expect(mac).to eql(macs[:solaris])
|
425
|
+
end
|
426
|
+
|
427
|
+
it "should be able to parse freebsd ifconfig output" do
|
428
|
+
mac = UUIDTools::UUID.first_mac samples[:freebsd]
|
429
|
+
expect(mac).to eql(macs[:freebsd])
|
430
|
+
end
|
431
|
+
|
432
|
+
it "should be able to parse openbsd ifconfig output" do
|
433
|
+
mac = UUIDTools::UUID.first_mac samples[:openbsd]
|
434
|
+
expect(mac).to eql(macs[:openbsd])
|
435
|
+
end
|
436
|
+
|
437
|
+
it "should be able to parse linux ifconfig output" do
|
438
|
+
mac = UUIDTools::UUID.first_mac samples[:linux]
|
439
|
+
expect(mac).to eql(macs[:linux])
|
440
|
+
|
441
|
+
mac2 = UUIDTools::UUID.first_mac samples[:linux2]
|
442
|
+
expect(mac2).to eql(macs[:linux2])
|
443
|
+
end
|
444
|
+
|
445
|
+
it "should be able to parse macos ifconfig output" do
|
446
|
+
mac = UUIDTools::UUID.first_mac samples[:macos]
|
447
|
+
expect(mac).to eql(macs[:macos])
|
448
|
+
end
|
449
|
+
|
450
|
+
it "should be able to parse ip addr output" do
|
451
|
+
mac = UUIDTools::UUID.first_mac samples[:linuxip]
|
452
|
+
expect(mac).to eql(macs[:linuxip])
|
14
453
|
end
|
15
454
|
end
|