omnijack 0.1.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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +6 -0
  4. data/CHANGELOG.md +11 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE.txt +15 -0
  7. data/NOTICE +5 -0
  8. data/README.md +119 -0
  9. data/Rakefile +23 -0
  10. data/features/list.feature +19 -0
  11. data/features/metadata.feature +43 -0
  12. data/features/platforms.feature +23 -0
  13. data/features/step_definitions/list.rb +12 -0
  14. data/features/step_definitions/metadata.rb +20 -0
  15. data/features/step_definitions/platforms.rb +8 -0
  16. data/features/step_definitions/project.rb +20 -0
  17. data/features/support/env.rb +4 -0
  18. data/lib/omnijack/config.rb +67 -0
  19. data/lib/omnijack/list.rb +94 -0
  20. data/lib/omnijack/metadata.rb +244 -0
  21. data/lib/omnijack/platforms.rb +96 -0
  22. data/lib/omnijack/project/metaprojects.rb +38 -0
  23. data/lib/omnijack/project.rb +63 -0
  24. data/lib/omnijack/version.rb +24 -0
  25. data/lib/omnijack.rb +54 -0
  26. data/omnijack.gemspec +37 -0
  27. data/spec/omnijack/config_spec.rb +55 -0
  28. data/spec/omnijack/list_spec.rb +133 -0
  29. data/spec/omnijack/metadata_spec.rb +577 -0
  30. data/spec/omnijack/platforms_spec.rb +132 -0
  31. data/spec/omnijack/project/angry_chef_spec.rb +55 -0
  32. data/spec/omnijack/project/chef_container_spec.rb +55 -0
  33. data/spec/omnijack/project/chef_dk_spec.rb +55 -0
  34. data/spec/omnijack/project/chef_server_spec.rb +55 -0
  35. data/spec/omnijack/project/chef_spec.rb +55 -0
  36. data/spec/omnijack/project_spec.rb +52 -0
  37. data/spec/omnijack_spec.rb +109 -0
  38. data/spec/spec_helper.rb +38 -0
  39. data/spec/support/real_test_data.json +131 -0
  40. data/vendor/chef/LICENSE +201 -0
  41. data/vendor/chef/NOTICE +21 -0
  42. data/vendor/chef/lib/chef/exceptions.rb +353 -0
  43. data/vendor/chef/lib/chef/mixin/params_validate.rb +242 -0
  44. metadata +276 -0
@@ -0,0 +1,133 @@
1
+ # Encoding: UTF-8
2
+ #
3
+ # Author:: Jonathan Hartman (<j@p4nt5.com>)
4
+ #
5
+ # Copyright (C) 2014, Jonathan Hartman
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative '../spec_helper'
20
+ require_relative '../../lib/omnijack/list'
21
+
22
+ describe Omnijack::List do
23
+ let(:name) { :chef_dk }
24
+ let(:obj) { described_class.new(name) }
25
+
26
+ describe '#method_missing' do
27
+ let(:to_h) { { thing1: 'yup', thing2: 'nope', thing3: 'maybe' } }
28
+
29
+ before(:each) do
30
+ allow_any_instance_of(described_class).to receive(:to_h).and_return(to_h)
31
+ end
32
+
33
+ it 'sets up methods for the platform hash keys' do
34
+ expect(obj.thing1).to eq('yup')
35
+ expect(obj.thing2).to eq('nope')
36
+ expect(obj.thing3).to eq('maybe')
37
+ end
38
+
39
+ it 'raises an exception otherwise' do
40
+ expect { obj.thing4 }.to raise_error(NoMethodError)
41
+ end
42
+ end
43
+
44
+ describe '#[]' do
45
+ let(:to_h) { { thing1: 'yup', thing2: 'nope', thing3: 'maybe' } }
46
+
47
+ before(:each) do
48
+ allow_any_instance_of(described_class).to receive(:to_h).and_return(to_h)
49
+ end
50
+
51
+ it 'returns the correct data' do
52
+ expect(obj[:thing1]).to eq('yup')
53
+ expect(obj[:thing2]).to eq('nope')
54
+ expect(obj[:thing3]).to eq('maybe')
55
+ end
56
+ end
57
+
58
+ describe '#to_h' do
59
+ context 'fake data' do
60
+ let(:raw_data) { '{"thing1": "yup", "thing2": "nope"}' }
61
+
62
+ before(:each) do
63
+ allow_any_instance_of(described_class).to receive(:raw_data)
64
+ .and_return(raw_data)
65
+ end
66
+
67
+ it 'returns the correct result hash' do
68
+ expect(obj.to_h).to eq(thing1: 'yup', thing2: 'nope')
69
+ end
70
+ end
71
+
72
+ context 'real data' do
73
+ let(:obj) { described_class.new(:chef) }
74
+
75
+ it 'returns the expected data' do
76
+ expected = '/el/6/i686/chef-10.12.0-1.el6.i686.rpm'
77
+ expect(obj.to_h[:suse][:'12.1'][:i686][:'10.12.0-1']).to eq(expected)
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#to_s' do
83
+ let(:raw_data) { 'SOME STUFF' }
84
+
85
+ before(:each) do
86
+ allow_any_instance_of(described_class).to receive(:raw_data)
87
+ .and_return(raw_data)
88
+ end
89
+
90
+ it 'returns the raw HTTP GET string' do
91
+ expect(obj.to_s).to eq(raw_data)
92
+ end
93
+ end
94
+
95
+ describe '#raw_data' do
96
+ let(:read) { '{"thing1": "yup", "thing2": "nope"}' }
97
+ let(:open) { double(read: read) }
98
+
99
+ before(:each) do
100
+ allow_any_instance_of(URI::HTTP).to receive(:open).and_return(open)
101
+ end
102
+
103
+ it 'returns a GET of the API URL' do
104
+ res = obj
105
+ expect(res.send(:raw_data)).to eq(read)
106
+ expect(res.instance_variable_get(:@raw_data)).to eq(read)
107
+ end
108
+ end
109
+
110
+ describe '#api_url' do
111
+ let(:base_url) { 'http://example.com/chef' }
112
+ let(:endpoint) { '/example_list' }
113
+
114
+ before(:each) do
115
+ [:base_url, :endpoint].each do |i|
116
+ allow_any_instance_of(described_class).to receive(i).and_return(send(i))
117
+ end
118
+ end
119
+
120
+ it 'constructs a URL based on base + endpoint' do
121
+ expected = URI.parse('http://example.com/chef/example_list')
122
+ expect(obj.send(:api_url)).to eq(expected)
123
+ end
124
+ end
125
+
126
+ describe '#endpoint' do
127
+ let(:name) { :chef_container }
128
+
129
+ it 'returns the appropriate metadata endpoint' do
130
+ expect(obj.send(:endpoint)).to eq('/full_container_list')
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,577 @@
1
+ # Encoding: UTF-8
2
+ #
3
+ # Author:: Jonathan Hartman (<j@p4nt5.com>)
4
+ #
5
+ # Copyright (C) 2014, Jonathan Hartman
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'json'
20
+ require_relative '../spec_helper'
21
+ require_relative '../../lib/omnijack/metadata'
22
+
23
+ describe Omnijack::Metadata do
24
+ let(:name) { :chef_dk }
25
+ let(:args) { nil }
26
+ let(:obj) { described_class.new(name, args) }
27
+
28
+ describe '#initialize' do
29
+ {
30
+ platform: 'linspire',
31
+ platform_version: '3.3.3',
32
+ machine_arch: 'risc'
33
+ }.each do |k, v|
34
+ context "a #{k} arg provided" do
35
+ let(:args) { { k => v } }
36
+
37
+ it 'sets the given arg' do
38
+ expect(obj.send(k)).to eq(v)
39
+ expect(obj.instance_variable_get(:"@#{k}")).to eq(v)
40
+ end
41
+ end
42
+ end
43
+
44
+ context 'an invalid arg provided' do
45
+ let(:args) { { potatoes: 'peeled' } }
46
+
47
+ it 'raises an exception' do
48
+ expect { obj }.to raise_error(NoMethodError)
49
+ end
50
+ end
51
+ end
52
+
53
+ [:url, :md5, :sha256, :yolo, :filename].each do |i|
54
+ describe "##{i}" do
55
+ before(:each) do
56
+ allow_any_instance_of(described_class).to receive(:to_h)
57
+ .and_return(i => 'a thing')
58
+ end
59
+
60
+ it "returns the #{i} attribute" do
61
+ expect(obj.send(i)).to eq('a thing')
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#[]' do
67
+ let(:attributes) { [:url, :md5, :sha256, :yolo, :filename] }
68
+
69
+ before(:each) do
70
+ allow_any_instance_of(described_class).to receive(:to_h)
71
+ .and_return(attributes.each_with_object({}) do |a, hsh|
72
+ hsh[a] = "#{a} things"
73
+ hsh
74
+ end)
75
+ end
76
+
77
+ [:url, :md5, :sha256, :yolo, :filename].each do |a|
78
+ it "returns the correct #{a}" do
79
+ expect(obj[a]).to eq("#{a} things")
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#to_h' do
85
+ context 'fake data' do
86
+ let(:url) do
87
+ 'https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/' \
88
+ 'chefdk-0.2.1-1.el6.x86_64.rpm'
89
+ end
90
+ let(:md5) { 'feb2e06fdecae3bae79f8ec8d32d6ab6' }
91
+ let(:sha256) do
92
+ 'afd487ab6f0cd0286a0a3d2808a041c784c064eddb6193d688edfb6741065b56'
93
+ end
94
+ let(:yolo) { true }
95
+ let(:raw_metadata) do
96
+ "url\t#{url}\nmd5\t#{md5}\nsha256\t#{sha256}\nyolo\t#{yolo}"
97
+ end
98
+
99
+ before(:each) do
100
+ allow_any_instance_of(described_class).to receive(:raw_metadata)
101
+ .and_return(raw_metadata)
102
+ end
103
+
104
+ it 'returns the correct result hash' do
105
+ expected = { url: url, md5: md5, sha256: sha256, yolo: yolo,
106
+ filename: 'chefdk-0.2.1-1.el6.x86_64.rpm' }
107
+ expect(obj.to_h).to eq(expected)
108
+ end
109
+
110
+ [true, false].each do |tf|
111
+ context "data with a #{tf} value in it" do
112
+ let(:yolo) { tf }
113
+
114
+ it 'converts that string into a boolean' do
115
+ expect(obj.to_h[:yolo]).to eq(tf)
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ json = ::File.open(File.expand_path('../../support/real_test_data.json',
122
+ __FILE__)).read
123
+ JSON.parse(json, symbolize_names: true).each do |data|
124
+ context "#{data[:platform]} Chef-DK" do
125
+ let(:obj) do
126
+ described_class.new(:chef_dk,
127
+ version: data[:version],
128
+ prerelease: data[:prerelease],
129
+ nightlies: data[:nightlies],
130
+ platform: data[:platform][:name],
131
+ platform_version: data[:platform][:version],
132
+ machine_arch: 'x86_64')
133
+ end
134
+ it 'returns the expected data' do
135
+ if !data[:expected]
136
+ expect { obj.to_h }.to raise_error(OpenURI::HTTPError)
137
+ else
138
+ expect(obj.to_h).to eq(data[:expected])
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ describe '#to_s' do
146
+ let(:raw_metadata) { 'SOME METADATA' }
147
+ before(:each) do
148
+ allow_any_instance_of(described_class).to receive(:raw_metadata)
149
+ .and_return(raw_metadata)
150
+ end
151
+
152
+ it 'returns the raw metadata string' do
153
+ expect(obj.to_s).to eq(raw_metadata)
154
+ end
155
+ end
156
+
157
+ describe '#version' do
158
+ context 'no argument provided' do
159
+ it 'returns latest' do
160
+ res = obj
161
+ expect(res.version).to eq('latest')
162
+ expect(res.instance_variable_get(:@version)).to eq('latest')
163
+ end
164
+ end
165
+
166
+ context 'a valid argument provided' do
167
+ let(:obj) do
168
+ o = super()
169
+ o.version('1.2.3') && o
170
+ end
171
+
172
+ it 'uses the provided arg' do
173
+ expect(obj.version).to eq('1.2.3')
174
+ expect(obj.instance_variable_get(:@version)).to eq('1.2.3')
175
+ end
176
+ end
177
+
178
+ context 'an invalid argument provided' do
179
+ let(:obj) do
180
+ o = super()
181
+ o.version(false) && o
182
+ end
183
+
184
+ it 'raises an exception' do
185
+ expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
186
+ end
187
+ end
188
+ end
189
+
190
+ describe '#prerelease' do
191
+ context 'no argument provided' do
192
+ it 'returns false' do
193
+ res = obj
194
+ expect(res.prerelease).to eq(false)
195
+ expect(res.instance_variable_get(:@prerelease)).to eq(false)
196
+ end
197
+ end
198
+
199
+ context 'a valid argument provided' do
200
+ let(:obj) do
201
+ o = super()
202
+ o.prerelease(true) && o
203
+ end
204
+
205
+ it 'uses the provided arg' do
206
+ expect(obj.prerelease).to eq(true)
207
+ expect(obj.instance_variable_get(:@prerelease)).to eq(true)
208
+ end
209
+ end
210
+
211
+ context 'an invalid argument provided' do
212
+ let(:obj) do
213
+ o = super()
214
+ o.prerelease('wigglebot') && o
215
+ end
216
+
217
+ it 'raises an exception' do
218
+ expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
219
+ end
220
+ end
221
+ end
222
+
223
+ describe '#nightlies' do
224
+ context 'no argument provided' do
225
+ it 'returns false' do
226
+ res = obj
227
+ expect(res.nightlies).to eq(false)
228
+ expect(res.instance_variable_get(:@nightlies)).to eq(false)
229
+ end
230
+ end
231
+
232
+ context 'a valid argument provided' do
233
+ let(:obj) do
234
+ o = super()
235
+ o.nightlies(true) && o
236
+ end
237
+
238
+ it 'uses the provided arg' do
239
+ expect(obj.nightlies).to eq(true)
240
+ expect(obj.instance_variable_get(:@nightlies)).to eq(true)
241
+ end
242
+ end
243
+
244
+ context 'an invalid argument provided' do
245
+ let(:obj) do
246
+ o = super()
247
+ o.nightlies('hello') && o
248
+ end
249
+
250
+ it 'raises an exception' do
251
+ expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
252
+ end
253
+ end
254
+ end
255
+
256
+ describe '#platform' do
257
+ let(:node) { { platform: 'ms_dos' } }
258
+
259
+ before(:each) do
260
+ allow_any_instance_of(described_class).to receive(:node).and_return(node)
261
+ end
262
+
263
+ context 'no argument provided' do
264
+ it 'uses the node Ohai data' do
265
+ res = obj
266
+ expect(res.platform).to eq('ms_dos')
267
+ expect(res.instance_variable_get(:@platform)).to eq('ms_dos')
268
+ end
269
+ end
270
+
271
+ context 'a valid argument provided' do
272
+ let(:obj) do
273
+ o = super()
274
+ o.platform('ms_bob') && o
275
+ end
276
+
277
+ it 'uses the provided arg' do
278
+ expect(obj.platform).to eq('ms_bob')
279
+ expect(obj.instance_variable_get(:@platform)).to eq('ms_bob')
280
+ end
281
+ end
282
+
283
+ context 'an invalid argument provided' do
284
+ let(:obj) do
285
+ o = super()
286
+ o.platform(%w(windows linux)) && o
287
+ end
288
+
289
+ it 'raises an exception' do
290
+ expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
291
+ end
292
+ end
293
+ end
294
+
295
+ describe '#platform_version' do
296
+ let(:node) { { platform_version: '1.2.3' } }
297
+
298
+ before(:each) do
299
+ allow_any_instance_of(described_class).to receive(:node).and_return(node)
300
+ end
301
+
302
+ context 'no argument provided' do
303
+ it 'uses the node Ohai data' do
304
+ expect(obj.platform_version).to eq('1.2.3')
305
+ expect(obj.instance_variable_get(:@platform_version)).to eq('1.2.3')
306
+ end
307
+ end
308
+
309
+ context 'a valid argument provided' do
310
+ let(:obj) do
311
+ o = super()
312
+ o.platform_version('6.6.6') && o
313
+ end
314
+
315
+ it 'uses the provided arg' do
316
+ expect(obj.platform_version).to eq('6.6.6')
317
+ expect(obj.instance_variable_get(:@platform_version)).to eq('6.6.6')
318
+ end
319
+ end
320
+
321
+ context 'an invalid argument provided' do
322
+ let(:obj) do
323
+ o = super()
324
+ o.platform_version(%w(1 2 3)) && o
325
+ end
326
+
327
+ it 'raises an exception' do
328
+ expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
329
+ end
330
+ end
331
+ end
332
+
333
+ describe '#machine_arch' do
334
+ let(:node) { { kernel: { machine: 'x86_64' } } }
335
+
336
+ before(:each) do
337
+ allow_any_instance_of(described_class).to receive(:node).and_return(node)
338
+ end
339
+
340
+ context 'no argument provided' do
341
+ it 'uses the node Ohai data' do
342
+ res = obj
343
+ expect(res.machine_arch).to eq('x86_64')
344
+ expect(res.instance_variable_get(:@machine_arch)).to eq('x86_64')
345
+ end
346
+ end
347
+
348
+ context 'a valid argument provided' do
349
+ let(:obj) do
350
+ o = super()
351
+ o.machine_arch('arm') && o
352
+ end
353
+
354
+ it 'uses the provided arg' do
355
+ expect(obj.machine_arch).to eq('arm')
356
+ expect(obj.instance_variable_get(:@machine_arch)).to eq('arm')
357
+ end
358
+ end
359
+
360
+ context 'an invalid argument provided' do
361
+ let(:obj) do
362
+ o = super()
363
+ o.machine_arch(%w(some things)) && o
364
+ end
365
+
366
+ it 'raises an exception' do
367
+ expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
368
+ end
369
+ end
370
+ end
371
+
372
+ describe '#raw_metadata' do
373
+ let(:open) { double(read: 'SOME STUFF') }
374
+
375
+ before(:each) do
376
+ allow_any_instance_of(URI::HTTP).to receive(:open).and_return(open)
377
+ end
378
+
379
+ it 'returns a GET of the API URL' do
380
+ expect(obj.send(:raw_metadata)).to eq('SOME STUFF')
381
+ expect(obj.instance_variable_get(:@raw_metadata)).to eq('SOME STUFF')
382
+ end
383
+ end
384
+
385
+ describe '#api_url' do
386
+ let(:base_url) { 'http://example.com/chef' }
387
+ let(:endpoint) { '/metadata-example' }
388
+ let(:query_params) { { v: '1.2.3', p: 'ubuntu' } }
389
+
390
+ before(:each) do
391
+ [:base_url, :endpoint, :query_params].each do |i|
392
+ allow_any_instance_of(described_class).to receive(i).and_return(send(i))
393
+ end
394
+ end
395
+
396
+ it 'constructs a URL based on base + endpoint + params' do
397
+ expected = URI.parse('http://example.com/chef/metadata-example?' \
398
+ 'v=1.2.3&p=ubuntu')
399
+ expect(obj.send(:api_url)).to eq(expected)
400
+ end
401
+ end
402
+
403
+ describe '#query_params' do
404
+ let(:args) do
405
+ { version: '1.2.3',
406
+ prerelease: true,
407
+ nightlies: true,
408
+ platform: 'ubuntu',
409
+ platform_version: '14.04',
410
+ machine_arch: 'x86_64' }
411
+ end
412
+
413
+ before(:each) do
414
+ args.each do |k, v|
415
+ allow_any_instance_of(described_class).to receive(k).and_return(v)
416
+ end
417
+ end
418
+
419
+ it 'returns all the data with keys Omnitruck understands' do
420
+ expected = { v: '1.2.3',
421
+ prerelease: true,
422
+ nightlies: true,
423
+ p: 'ubuntu',
424
+ pv: '14.04',
425
+ m: 'x86_64' }
426
+ expect(obj.send(:query_params)).to eq(expected)
427
+ end
428
+ end
429
+
430
+ describe '#endpoint' do
431
+ let(:name) { 'chef_container' }
432
+
433
+ it 'returns the appropriate metadata endpoint' do
434
+ expect(obj.send(:endpoint)).to eq('/metadata-container')
435
+ end
436
+ end
437
+
438
+ describe '#node' do
439
+ let(:platform) { nil }
440
+ let(:platform_version) { nil }
441
+ let(:system) do
442
+ double(all_plugins: [
443
+ double(data: { platform: platform, platform_version: platform_version })
444
+ ])
445
+ end
446
+
447
+ before(:each) do
448
+ unless platform.nil? || platform_version.nil?
449
+ allow(Ohai::System).to receive(:new).and_return(system)
450
+ end
451
+ end
452
+
453
+ it 'loads and returns Ohai platform data' do
454
+ node = obj.send(:node)
455
+ expect(node[:platform]).to be_an_instance_of(String)
456
+ expect(node[:platform_version]).to be_an_instance_of(String)
457
+ end
458
+
459
+ context 'Mac OS X' do
460
+ let(:platform) { 'mac_os_x' }
461
+ let(:platform_version) { '10.9.2' }
462
+
463
+ it 'calls the custom Mac OS X version logic' do
464
+ o = obj
465
+ expect(o).to receive(:platform_version_mac_os_x).and_call_original
466
+ expect(o.send(:node)[:platform_version]).to eq('10.9')
467
+ end
468
+ end
469
+
470
+ context 'Windows' do
471
+ let(:platform) { 'windows' }
472
+ let(:platform_version) { '6.3' }
473
+
474
+ it 'calls the custom Windows version logic' do
475
+ o = obj
476
+ expect(o).to receive(:platform_version_windows).and_call_original
477
+ expect(o.send(:node)[:platform_version]).to eq('2012r2')
478
+ end
479
+ end
480
+
481
+ context 'CentOS' do
482
+ let(:platform) { 'centos' }
483
+ let(:platform_version) { '7.0' }
484
+
485
+ it 'does not modify the version' do
486
+ expect(obj.send(:node)[:platform_version]).to eq('7.0')
487
+ end
488
+ end
489
+
490
+ context 'Ubuntu' do
491
+ let(:platform) { 'ubuntu' }
492
+ let(:platform_version) { '14.04' }
493
+
494
+ it 'does not modify the version' do
495
+ expect(obj.send(:node)[:platform_version]).to eq('14.04')
496
+ end
497
+ end
498
+ end
499
+
500
+ describe '#platform_version_mac_os_x' do
501
+ let(:node) { { platform_version: platform_version } }
502
+
503
+ before(:each) do
504
+ allow_any_instance_of(described_class).to receive(:node).and_return(node)
505
+ end
506
+
507
+ { '10.9' => '10.9', '10.9.4' => '10.9' }.each do |ver, expected|
508
+ context "Mac OS X version #{ver}" do
509
+ let(:platform_version) { ver }
510
+
511
+ it "returns Mac OSX #{expected}" do
512
+ expect(obj.send(:platform_version_mac_os_x)).to eq(expected)
513
+ end
514
+ end
515
+ end
516
+ end
517
+
518
+ describe '#platform_version_windows' do
519
+ let(:node) { { platform_version: platform_version } }
520
+
521
+ before(:each) do
522
+ allow_any_instance_of(described_class).to receive(:node).and_return(node)
523
+ end
524
+
525
+ {
526
+ '6.3.123456.789' => '2012r2',
527
+ '6.2.123456.789' => '2012',
528
+ '6.1.123456.789' => '2008r2',
529
+ '6.0.123456.789' => '2008',
530
+ '5.2.123456.789' => '2003r2',
531
+ '5.1.123456.789' => 'xp',
532
+ '5.0.123456.789' => '2000'
533
+ }.each do |ver, expected|
534
+ context "Windows version #{ver}" do
535
+ let(:platform_version) { ver }
536
+
537
+ it "returns Windows #{expected}" do
538
+ expect(obj.send(:platform_version_windows)).to eq(expected)
539
+ end
540
+ end
541
+ end
542
+ end
543
+
544
+ describe '#valid_version?' do
545
+ context 'a "latest" version' do
546
+ let(:res) { obj.send(:valid_version?, 'latest') }
547
+
548
+ it 'returns true' do
549
+ expect(res).to eq(true)
550
+ end
551
+ end
552
+
553
+ context 'a valid version' do
554
+ let(:res) { obj.send(:valid_version?, '1.2.3') }
555
+
556
+ it 'returns true' do
557
+ expect(res).to eq(true)
558
+ end
559
+ end
560
+
561
+ context 'a valid version + build' do
562
+ let(:res) { obj.send(:valid_version?, '1.2.3-12') }
563
+
564
+ it 'returns true' do
565
+ expect(res).to eq(true)
566
+ end
567
+ end
568
+
569
+ context 'an invalid version' do
570
+ let(:res) { obj.send(:valid_version?, 'x.y.z') }
571
+
572
+ it 'returns false' do
573
+ expect(res).to eq(false)
574
+ end
575
+ end
576
+ end
577
+ end