omnijack 0.2.0 → 1.0.0.rc.1
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +16 -15
- data/Rakefile +1 -1
- data/features/step_definitions/project.rb +5 -6
- data/lib/omnijack/config.rb +10 -10
- data/lib/omnijack/endpoint/list.rb +29 -0
- data/lib/omnijack/endpoint/metadata.rb +189 -0
- data/lib/omnijack/endpoint/platforms.rb +29 -0
- data/lib/omnijack/{platforms.rb → endpoint.rb} +34 -12
- data/lib/omnijack/project.rb +4 -6
- data/lib/omnijack/version.rb +1 -1
- data/lib/omnijack.rb +2 -24
- data/omnijack.gemspec +1 -2
- data/spec/omnijack/config_spec.rb +1 -1
- data/spec/omnijack/endpoint/list_spec.rb +33 -0
- data/spec/omnijack/{metadata_spec.rb → endpoint/metadata_spec.rb} +62 -208
- data/spec/omnijack/endpoint/platforms_spec.rb +33 -0
- data/spec/omnijack/{list_spec.rb → endpoint_spec.rb} +88 -9
- data/spec/omnijack/project_spec.rb +9 -5
- data/spec/omnijack_spec.rb +8 -44
- data/spec/support/real_test_data.json +12 -12
- data/vendor/chef/lib/chef/exceptions.rb +19 -13
- metadata +17 -28
- data/lib/omnijack/list.rb +0 -94
- data/lib/omnijack/metadata.rb +0 -238
- data/spec/omnijack/platforms_spec.rb +0 -132
@@ -16,13 +16,15 @@
|
|
16
16
|
# See the License for the specific language governing permissions and
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
|
-
require '
|
20
|
-
require_relative '
|
21
|
-
require_relative '
|
19
|
+
require 'multi_json'
|
20
|
+
require_relative '../../spec_helper'
|
21
|
+
require_relative '../../../lib/omnijack/endpoint/metadata'
|
22
22
|
|
23
|
-
describe Omnijack::Metadata do
|
23
|
+
describe Omnijack::Endpoint::Metadata do
|
24
24
|
let(:name) { :chef_dk }
|
25
|
-
let(:args)
|
25
|
+
let(:args) do
|
26
|
+
{ platform: 'linspire', platform_version: '3.3.3', machine_arch: 'risc' }
|
27
|
+
end
|
26
28
|
let(:obj) { described_class.new(name, args) }
|
27
29
|
|
28
30
|
before(:each) do
|
@@ -30,28 +32,35 @@ describe Omnijack::Metadata do
|
|
30
32
|
end
|
31
33
|
|
32
34
|
describe '#initialize' do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
{
|
39
|
-
platform: 'linspire',
|
40
|
-
platform_version: '3.3.3',
|
41
|
-
machine_arch: 'risc'
|
42
|
-
}.each do |k, v|
|
43
|
-
context "a #{k} arg provided" do
|
44
|
-
let(:args) { { k => v } }
|
45
|
-
|
46
|
-
it 'sets the given arg' do
|
35
|
+
context 'the required args provided' do
|
36
|
+
{
|
37
|
+
platform: 'linspire', platform_version: '3.3.3', machine_arch: 'risc'
|
38
|
+
}.each do |k, v|
|
39
|
+
it "sets the given #{k}" do
|
47
40
|
expect(obj.send(k)).to eq(v)
|
48
41
|
expect(obj.instance_variable_get(:"@#{k}")).to eq(v)
|
49
42
|
end
|
50
43
|
end
|
51
44
|
end
|
52
45
|
|
46
|
+
[:platform, :platform_version, :machine_arch].each do |i|
|
47
|
+
context "missing #{i} arg" do
|
48
|
+
let(:args) do
|
49
|
+
a = super()
|
50
|
+
a.delete(i) && a
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'raises an error' do
|
54
|
+
expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
53
59
|
context 'an invalid arg provided' do
|
54
|
-
let(:args)
|
60
|
+
let(:args) do
|
61
|
+
a = super()
|
62
|
+
a.merge!(potatoes: 'peeled') && a
|
63
|
+
end
|
55
64
|
|
56
65
|
it 'raises an exception' do
|
57
66
|
expect { obj }.to raise_error(NoMethodError)
|
@@ -72,26 +81,6 @@ describe Omnijack::Metadata do
|
|
72
81
|
end
|
73
82
|
end
|
74
83
|
|
75
|
-
describe '#[]' do
|
76
|
-
let(:attributes) do
|
77
|
-
[:url, :md5, :sha256, :yolo, :filename, :version, :build]
|
78
|
-
end
|
79
|
-
|
80
|
-
before(:each) do
|
81
|
-
allow_any_instance_of(described_class).to receive(:to_h)
|
82
|
-
.and_return(attributes.each_with_object({}) do |a, hsh|
|
83
|
-
hsh[a] = "#{a} things"
|
84
|
-
hsh
|
85
|
-
end)
|
86
|
-
end
|
87
|
-
|
88
|
-
[:url, :md5, :sha256, :yolo, :filename, :version, :build].each do |a|
|
89
|
-
it "returns the correct #{a}" do
|
90
|
-
expect(obj[a]).to eq("#{a} things")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
84
|
describe '#to_h' do
|
96
85
|
before(:each) do
|
97
86
|
allow_any_instance_of(described_class).to receive(:to_h)
|
@@ -108,13 +97,13 @@ describe Omnijack::Metadata do
|
|
108
97
|
'afd487ab6f0cd0286a0a3d2808a041c784c064eddb6193d688edfb6741065b56'
|
109
98
|
end
|
110
99
|
let(:yolo) { true }
|
111
|
-
let(:
|
100
|
+
let(:raw_data) do
|
112
101
|
"url\t#{url}\nmd5\t#{md5}\nsha256\t#{sha256}\nyolo\t#{yolo}"
|
113
102
|
end
|
114
103
|
|
115
104
|
before(:each) do
|
116
|
-
allow_any_instance_of(described_class).to receive(:
|
117
|
-
.and_return(
|
105
|
+
allow_any_instance_of(described_class).to receive(:raw_data)
|
106
|
+
.and_return(raw_data)
|
118
107
|
end
|
119
108
|
|
120
109
|
it 'returns the correct result hash' do
|
@@ -150,13 +139,13 @@ describe Omnijack::Metadata do
|
|
150
139
|
'b9ecab8f2ebb258c3bdc341ab82310dfbfc8b8a5b27802481f27daf607ba7f99'
|
151
140
|
end
|
152
141
|
let(:yolo) { true }
|
153
|
-
let(:
|
142
|
+
let(:raw_data) do
|
154
143
|
"url\t#{url}\nmd5\t#{md5}\nsha256\t#{sha256}\nyolo\t#{yolo}"
|
155
144
|
end
|
156
145
|
|
157
146
|
before(:each) do
|
158
|
-
allow_any_instance_of(described_class).to receive(:
|
159
|
-
.and_return(
|
147
|
+
allow_any_instance_of(described_class).to receive(:raw_data)
|
148
|
+
.and_return(raw_data)
|
160
149
|
end
|
161
150
|
|
162
151
|
it 'decodes the encoded URL' do
|
@@ -169,9 +158,9 @@ describe Omnijack::Metadata do
|
|
169
158
|
end
|
170
159
|
end
|
171
160
|
|
172
|
-
json = ::File.open(File.expand_path('
|
161
|
+
json = ::File.open(File.expand_path('../../../support/real_test_data.json',
|
173
162
|
__FILE__)).read
|
174
|
-
|
163
|
+
MultiJson.load(json, symbolize_names: true).each do |data|
|
175
164
|
context "#{data[:platform]} Chef-DK" do
|
176
165
|
let(:obj) do
|
177
166
|
described_class.new(:chef_dk,
|
@@ -194,18 +183,6 @@ describe Omnijack::Metadata do
|
|
194
183
|
end
|
195
184
|
end
|
196
185
|
|
197
|
-
describe '#to_s' do
|
198
|
-
let(:raw_metadata) { 'SOME METADATA' }
|
199
|
-
before(:each) do
|
200
|
-
allow_any_instance_of(described_class).to receive(:raw_metadata)
|
201
|
-
.and_return(raw_metadata)
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'returns the raw metadata string' do
|
205
|
-
expect(obj.to_s).to eq(raw_metadata)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
186
|
describe '#version' do
|
210
187
|
context 'no argument provided' do
|
211
188
|
it 'returns latest' do
|
@@ -306,29 +283,23 @@ describe Omnijack::Metadata do
|
|
306
283
|
end
|
307
284
|
|
308
285
|
describe '#platform' do
|
309
|
-
let(:node) { { platform: 'ms_dos' } }
|
310
|
-
|
311
|
-
before(:each) do
|
312
|
-
allow_any_instance_of(described_class).to receive(:node).and_return(node)
|
313
|
-
end
|
314
|
-
|
315
286
|
context 'no argument provided' do
|
316
|
-
it '
|
317
|
-
|
318
|
-
expect(
|
319
|
-
expect(
|
287
|
+
it 'returns the initialized arg' do
|
288
|
+
expected = args[:platform]
|
289
|
+
expect(obj.platform).to eq(expected)
|
290
|
+
expect(obj.instance_variable_get(:@platform)).to eq(expected)
|
320
291
|
end
|
321
292
|
end
|
322
293
|
|
323
294
|
context 'a valid argument provided' do
|
324
295
|
let(:obj) do
|
325
296
|
o = super()
|
326
|
-
o.platform('
|
297
|
+
o.platform('ms_dos') && o
|
327
298
|
end
|
328
299
|
|
329
300
|
it 'uses the provided arg' do
|
330
|
-
expect(obj.platform).to eq('
|
331
|
-
expect(obj.instance_variable_get(:@platform)).to eq('
|
301
|
+
expect(obj.platform).to eq('ms_dos')
|
302
|
+
expect(obj.instance_variable_get(:@platform)).to eq('ms_dos')
|
332
303
|
end
|
333
304
|
end
|
334
305
|
|
@@ -345,16 +316,11 @@ describe Omnijack::Metadata do
|
|
345
316
|
end
|
346
317
|
|
347
318
|
describe '#platform_version' do
|
348
|
-
let(:node) { { platform_version: '1.2.3' } }
|
349
|
-
|
350
|
-
before(:each) do
|
351
|
-
allow_any_instance_of(described_class).to receive(:node).and_return(node)
|
352
|
-
end
|
353
|
-
|
354
319
|
context 'no argument provided' do
|
355
|
-
it '
|
356
|
-
|
357
|
-
expect(obj.
|
320
|
+
it 'returns the initialized arg' do
|
321
|
+
expected = args[:platform_version]
|
322
|
+
expect(obj.platform_version).to eq(expected)
|
323
|
+
expect(obj.instance_variable_get(:@platform_version)).to eq(expected)
|
358
324
|
end
|
359
325
|
end
|
360
326
|
|
@@ -383,17 +349,11 @@ describe Omnijack::Metadata do
|
|
383
349
|
end
|
384
350
|
|
385
351
|
describe '#machine_arch' do
|
386
|
-
let(:node) { { kernel: { machine: 'x86_64' } } }
|
387
|
-
|
388
|
-
before(:each) do
|
389
|
-
allow_any_instance_of(described_class).to receive(:node).and_return(node)
|
390
|
-
end
|
391
|
-
|
392
352
|
context 'no argument provided' do
|
393
|
-
it '
|
394
|
-
|
395
|
-
expect(
|
396
|
-
expect(
|
353
|
+
it 'returns the initialized arg' do
|
354
|
+
expected = args[:machine_arch]
|
355
|
+
expect(obj.machine_arch).to eq(expected)
|
356
|
+
expect(obj.instance_variable_get(:@machine_arch)).to eq(expected)
|
397
357
|
end
|
398
358
|
end
|
399
359
|
|
@@ -421,33 +381,17 @@ describe Omnijack::Metadata do
|
|
421
381
|
end
|
422
382
|
end
|
423
383
|
|
424
|
-
describe '#raw_metadata' do
|
425
|
-
let(:open) { double(read: 'SOME STUFF') }
|
426
|
-
|
427
|
-
before(:each) do
|
428
|
-
allow_any_instance_of(URI::HTTP).to receive(:open).and_return(open)
|
429
|
-
end
|
430
|
-
|
431
|
-
it 'returns a GET of the API URL' do
|
432
|
-
expect(obj.send(:raw_metadata)).to eq('SOME STUFF')
|
433
|
-
expect(obj.instance_variable_get(:@raw_metadata)).to eq('SOME STUFF')
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
384
|
describe '#api_url' do
|
438
|
-
let(:
|
439
|
-
let(:endpoint) { '/metadata-example' }
|
440
|
-
let(:query_params) { { v: '1.2.3', p: 'ubuntu' } }
|
385
|
+
let(:query_params) { { v: '1.2.3', p: 'ubuntu', pv: '12.04' } }
|
441
386
|
|
442
387
|
before(:each) do
|
443
|
-
|
444
|
-
|
445
|
-
end
|
388
|
+
allow_any_instance_of(described_class).to receive(:query_params)
|
389
|
+
.and_return(query_params)
|
446
390
|
end
|
447
391
|
|
448
|
-
it '
|
449
|
-
expected = URI.parse('
|
450
|
-
'v=1.2.3&p=ubuntu')
|
392
|
+
it 'returns the appropriate metadata endpoint' do
|
393
|
+
expected = URI.parse('https://www.getchef.com/chef/metadata-chefdk?' \
|
394
|
+
'v=1.2.3&p=ubuntu&pv=12.04')
|
451
395
|
expect(obj.send(:api_url)).to eq(expected)
|
452
396
|
end
|
453
397
|
end
|
@@ -479,101 +423,15 @@ describe Omnijack::Metadata do
|
|
479
423
|
end
|
480
424
|
end
|
481
425
|
|
482
|
-
describe '#endpoint' do
|
483
|
-
let(:name) { 'chef_container' }
|
484
|
-
|
485
|
-
it 'returns the appropriate metadata endpoint' do
|
486
|
-
expect(obj.send(:endpoint)).to eq('/metadata-container')
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
describe '#node' do
|
491
|
-
let(:platform) { nil }
|
492
|
-
let(:platform_version) { nil }
|
493
|
-
let(:system) do
|
494
|
-
double(all_plugins: [
|
495
|
-
double(data: { platform: platform, platform_version: platform_version })
|
496
|
-
])
|
497
|
-
end
|
498
|
-
|
499
|
-
before(:each) do
|
500
|
-
unless platform.nil? || platform_version.nil?
|
501
|
-
allow(Ohai::System).to receive(:new).and_return(system)
|
502
|
-
end
|
503
|
-
end
|
504
|
-
|
505
|
-
it 'loads and returns Ohai platform data' do
|
506
|
-
node = obj.send(:node)
|
507
|
-
expect(node[:platform]).to be_an_instance_of(String)
|
508
|
-
expect(node[:platform_version]).to be_an_instance_of(String)
|
509
|
-
end
|
510
|
-
|
511
|
-
context 'Mac OS X' do
|
512
|
-
let(:platform) { 'mac_os_x' }
|
513
|
-
let(:platform_version) { '10.9.2' }
|
514
|
-
|
515
|
-
it 'calls the custom Mac OS X version logic' do
|
516
|
-
o = obj
|
517
|
-
expect(o).to receive(:platform_version_mac_os_x).and_call_original
|
518
|
-
expect(o.send(:node)[:platform_version]).to eq('10.9')
|
519
|
-
end
|
520
|
-
end
|
521
|
-
|
522
|
-
context 'Windows' do
|
523
|
-
let(:platform) { 'windows' }
|
524
|
-
let(:platform_version) { '6.3' }
|
525
|
-
|
526
|
-
it 'calls the custom Windows version logic' do
|
527
|
-
o = obj
|
528
|
-
expect(o).to receive(:platform_version_windows).and_call_original
|
529
|
-
expect(o.send(:node)[:platform_version]).to eq('2012r2')
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
context 'CentOS' do
|
534
|
-
let(:platform) { 'centos' }
|
535
|
-
let(:platform_version) { '7.0' }
|
536
|
-
|
537
|
-
it 'does not modify the version' do
|
538
|
-
expect(obj.send(:node)[:platform_version]).to eq('7.0')
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
context 'Ubuntu' do
|
543
|
-
let(:platform) { 'ubuntu' }
|
544
|
-
let(:platform_version) { '14.04' }
|
545
|
-
|
546
|
-
it 'does not modify the version' do
|
547
|
-
expect(obj.send(:node)[:platform_version]).to eq('14.04')
|
548
|
-
end
|
549
|
-
end
|
550
|
-
end
|
551
|
-
|
552
426
|
describe '#platform_version_mac_os_x' do
|
553
|
-
let(:node) { { platform_version: platform_version } }
|
554
|
-
|
555
|
-
before(:each) do
|
556
|
-
allow_any_instance_of(described_class).to receive(:node).and_return(node)
|
557
|
-
end
|
558
|
-
|
559
427
|
{ '10.9' => '10.9', '10.9.4' => '10.9' }.each do |ver, expected|
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
it "returns Mac OSX #{expected}" do
|
564
|
-
expect(obj.send(:platform_version_mac_os_x)).to eq(expected)
|
565
|
-
end
|
428
|
+
it "returns #{expected} for Mac OS X #{ver}" do
|
429
|
+
expect(obj.send(:platform_version_mac_os_x, ver)).to eq(expected)
|
566
430
|
end
|
567
431
|
end
|
568
432
|
end
|
569
433
|
|
570
434
|
describe '#platform_version_windows' do
|
571
|
-
let(:node) { { platform_version: platform_version } }
|
572
|
-
|
573
|
-
before(:each) do
|
574
|
-
allow_any_instance_of(described_class).to receive(:node).and_return(node)
|
575
|
-
end
|
576
|
-
|
577
435
|
{
|
578
436
|
'6.3.123456.789' => '2012r2',
|
579
437
|
'6.2.123456.789' => '2012',
|
@@ -583,12 +441,8 @@ describe Omnijack::Metadata do
|
|
583
441
|
'5.1.123456.789' => 'xp',
|
584
442
|
'5.0.123456.789' => '2000'
|
585
443
|
}.each do |ver, expected|
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
it "returns Windows #{expected}" do
|
590
|
-
expect(obj.send(:platform_version_windows)).to eq(expected)
|
591
|
-
end
|
444
|
+
it "returns #{expected} for Windows #{ver}" do
|
445
|
+
expect(obj.send(:platform_version_windows, ver)).to eq(expected)
|
592
446
|
end
|
593
447
|
end
|
594
448
|
end
|
@@ -0,0 +1,33 @@
|
|
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/endpoint/platforms'
|
21
|
+
|
22
|
+
describe Omnijack::Endpoint::Platforms do
|
23
|
+
let(:name) { :chef_dk }
|
24
|
+
let(:obj) { described_class.new(name) }
|
25
|
+
|
26
|
+
describe '#endpoint' do
|
27
|
+
let(:name) { :chef_container }
|
28
|
+
|
29
|
+
it 'returns the appropriate metadata endpoint' do
|
30
|
+
expect(obj.send(:endpoint)).to eq('/chef_container_platform_names')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -17,11 +17,43 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
19
|
require_relative '../spec_helper'
|
20
|
-
require_relative '../../lib/omnijack/
|
20
|
+
require_relative '../../lib/omnijack/endpoint'
|
21
21
|
|
22
|
-
describe Omnijack::
|
22
|
+
describe Omnijack::Endpoint do
|
23
23
|
let(:name) { :chef_dk }
|
24
|
-
let(:
|
24
|
+
let(:args) { {} }
|
25
|
+
let(:obj) { described_class.new(name, args) }
|
26
|
+
|
27
|
+
describe '#initialize' do
|
28
|
+
shared_examples_for 'any context' do
|
29
|
+
it 'sets the project name' do
|
30
|
+
expect(obj.name).to eq(:chef_dk)
|
31
|
+
expect(obj.instance_variable_get(:@name)).to eq(:chef_dk)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'no extra args provided' do
|
36
|
+
let(:obj) { described_class.new(name) }
|
37
|
+
|
38
|
+
it_behaves_like 'any context'
|
39
|
+
|
40
|
+
it 'holds an empty hash for the args' do
|
41
|
+
expect(obj.args).to eq({})
|
42
|
+
expect(obj.instance_variable_get(:@args)).to eq({})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'a base_url arg provided' do
|
47
|
+
let(:args) { { base_url: 'https://example.com' } }
|
48
|
+
|
49
|
+
it_behaves_like 'any context'
|
50
|
+
|
51
|
+
it 'sets the given arg' do
|
52
|
+
expect(obj.send(:base_url)).to eq(args[:base_url])
|
53
|
+
expect(obj.instance_variable_get(:@base_url)).to eq(args[:base_url])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
25
57
|
|
26
58
|
describe '#method_missing' do
|
27
59
|
let(:to_h) { { thing1: 'yup', thing2: 'nope', thing3: 'maybe' } }
|
@@ -70,8 +102,14 @@ describe Omnijack::List do
|
|
70
102
|
end
|
71
103
|
|
72
104
|
context 'real data' do
|
105
|
+
let(:endpoint) { '/full_client_list' }
|
73
106
|
let(:obj) { described_class.new(:chef) }
|
74
107
|
|
108
|
+
before(:each) do
|
109
|
+
allow_any_instance_of(described_class).to receive(:endpoint)
|
110
|
+
.and_return(endpoint)
|
111
|
+
end
|
112
|
+
|
75
113
|
it 'returns the expected data' do
|
76
114
|
expected = '/el/6/i686/chef-10.12.0-1.el6.i686.rpm'
|
77
115
|
expect(obj.to_h[:suse][:'12.1'][:i686][:'10.12.0-1']).to eq(expected)
|
@@ -87,17 +125,53 @@ describe Omnijack::List do
|
|
87
125
|
.and_return(raw_data)
|
88
126
|
end
|
89
127
|
|
90
|
-
it 'returns the raw
|
91
|
-
expect(obj.to_s).to eq(
|
128
|
+
it 'returns the raw data' do
|
129
|
+
expect(obj.to_s).to eq('SOME STUFF')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#base_url' do
|
134
|
+
context 'no argument provided' do
|
135
|
+
it 'uses the default' do
|
136
|
+
res = obj
|
137
|
+
expected = 'https://www.getchef.com/chef'
|
138
|
+
expect(res.base_url).to eq(expected)
|
139
|
+
expect(res.instance_variable_get(:@base_url)).to eq(expected)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'a valid argument provided' do
|
144
|
+
let(:obj) do
|
145
|
+
o = super()
|
146
|
+
o.base_url('http://example.com') && o
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'uses the provided arg' do
|
150
|
+
expect(obj.base_url).to eq('http://example.com')
|
151
|
+
expect(obj.instance_variable_get(:@base_url))
|
152
|
+
.to eq('http://example.com')
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'an invalid argument provided' do
|
157
|
+
let(:obj) do
|
158
|
+
o = super()
|
159
|
+
o.base_url(:hello) && o
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'raises an exception' do
|
163
|
+
expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
|
164
|
+
end
|
92
165
|
end
|
93
166
|
end
|
94
167
|
|
95
168
|
describe '#raw_data' do
|
96
169
|
let(:read) { '{"thing1": "yup", "thing2": "nope"}' }
|
97
|
-
let(:
|
170
|
+
let(:api_url) { double(open: double(read: read)) }
|
98
171
|
|
99
172
|
before(:each) do
|
100
|
-
allow_any_instance_of(
|
173
|
+
allow_any_instance_of(described_class).to receive(:api_url)
|
174
|
+
.and_return(api_url)
|
101
175
|
end
|
102
176
|
|
103
177
|
it 'returns a GET of the API URL' do
|
@@ -124,10 +198,15 @@ describe Omnijack::List do
|
|
124
198
|
end
|
125
199
|
|
126
200
|
describe '#endpoint' do
|
127
|
-
let(:name) { :
|
201
|
+
let(:name) { :cook }
|
202
|
+
|
203
|
+
before(:each) do
|
204
|
+
stub_const('::Omnijack::Endpoint::OMNITRUCK_PROJECTS',
|
205
|
+
cook: { endpoints: { endpoint: '/there' } })
|
206
|
+
end
|
128
207
|
|
129
208
|
it 'returns the appropriate metadata endpoint' do
|
130
|
-
expect(obj.send(:endpoint)).to eq('/
|
209
|
+
expect(obj.send(:endpoint)).to eq('/there')
|
131
210
|
end
|
132
211
|
end
|
133
212
|
end
|
@@ -20,28 +20,32 @@ require_relative '../spec_helper'
|
|
20
20
|
require_relative '../../lib/omnijack/project'
|
21
21
|
|
22
22
|
describe Omnijack::Project do
|
23
|
-
let(:args) {
|
23
|
+
let(:args) { {} }
|
24
24
|
let(:obj) { described_class.new(:chef_dk, args) }
|
25
25
|
|
26
26
|
describe '#list' do
|
27
27
|
it 'returns a List object' do
|
28
28
|
res = obj
|
29
29
|
[res.list, res.instance_variable_get(:@list)].each do |i|
|
30
|
-
expect(i).to be_an_instance_of(Omnijack::List)
|
30
|
+
expect(i).to be_an_instance_of(Omnijack::Endpoint::List)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#metadata' do
|
36
|
+
let(:args) do
|
37
|
+
{ platform: 'ms_dos', platform_version: '1.2.3', machine_arch: 'i386' }
|
38
|
+
end
|
39
|
+
|
36
40
|
before(:each) do
|
37
|
-
allow_any_instance_of(Omnijack::Metadata).to receive(:to_h)
|
41
|
+
allow_any_instance_of(Omnijack::Endpoint::Metadata).to receive(:to_h)
|
38
42
|
.and_return(true)
|
39
43
|
end
|
40
44
|
|
41
45
|
it 'returns a Metadata object' do
|
42
46
|
res = obj
|
43
47
|
[res.metadata, res.instance_variable_get(:@metadata)].each do |i|
|
44
|
-
expect(i).to be_an_instance_of(Omnijack::Metadata)
|
48
|
+
expect(i).to be_an_instance_of(Omnijack::Endpoint::Metadata)
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
@@ -50,7 +54,7 @@ describe Omnijack::Project do
|
|
50
54
|
it 'returns a Platforms object' do
|
51
55
|
res = obj
|
52
56
|
[res.platforms, res.instance_variable_get(:@platforms)].each do |i|
|
53
|
-
expect(i).to be_an_instance_of(Omnijack::Platforms)
|
57
|
+
expect(i).to be_an_instance_of(Omnijack::Endpoint::Platforms)
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
data/spec/omnijack_spec.rb
CHANGED
@@ -53,50 +53,6 @@ describe Omnijack do
|
|
53
53
|
expect(obj.instance_variable_get(:@args)).to eq(args)
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
57
|
-
context 'a base_url arg provided' do
|
58
|
-
let(:args) { { base_url: 'https://example.com' } }
|
59
|
-
|
60
|
-
it 'sets the given arg' do
|
61
|
-
expect(obj.send(:base_url)).to eq(args[:base_url])
|
62
|
-
expect(obj.instance_variable_get(:@base_url)).to eq(args[:base_url])
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#base_url' do
|
68
|
-
context 'no argument provided' do
|
69
|
-
it 'uses the default' do
|
70
|
-
res = obj
|
71
|
-
expected = 'https://www.getchef.com/chef'
|
72
|
-
expect(res.base_url).to eq(expected)
|
73
|
-
expect(res.instance_variable_get(:@base_url)).to eq(expected)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'a valid argument provided' do
|
78
|
-
let(:obj) do
|
79
|
-
o = super()
|
80
|
-
o.base_url('http://example.com') && o
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'uses the provided arg' do
|
84
|
-
expect(obj.base_url).to eq('http://example.com')
|
85
|
-
expect(obj.instance_variable_get(:@base_url))
|
86
|
-
.to eq('http://example.com')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'an invalid argument provided' do
|
91
|
-
let(:obj) do
|
92
|
-
o = super()
|
93
|
-
o.base_url(:hello) && o
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'raises an exception' do
|
97
|
-
expect { obj }.to raise_error(Chef::Exceptions::ValidationFailed)
|
98
|
-
end
|
99
|
-
end
|
100
56
|
end
|
101
57
|
|
102
58
|
describe '#name' do
|
@@ -106,4 +62,12 @@ describe Omnijack do
|
|
106
62
|
expect(obj.name).to eq(:chef_container)
|
107
63
|
end
|
108
64
|
end
|
65
|
+
|
66
|
+
describe '#args' do
|
67
|
+
let(:args) { { platform: 'thing' } }
|
68
|
+
|
69
|
+
it 'returns the provided args' do
|
70
|
+
expect(obj.args).to eq(args)
|
71
|
+
end
|
72
|
+
end
|
109
73
|
end
|