jamie 0.1.0.beta3 → 0.1.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
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 'simplecov'
20
+ SimpleCov.adapters.define 'gem' do
21
+ command_name 'Specs'
22
+
23
+ add_filter '.gem/'
24
+ add_filter '/spec/'
25
+ add_filter '/lib/vendor/'
26
+
27
+ add_group 'Libraries', '/lib/'
28
+ end
29
+ SimpleCov.start 'gem'
30
+
31
+ require 'fakefs/spec_helpers'
32
+ require 'logger'
33
+ require 'minitest/autorun'
34
+ require 'ostruct'
35
+ require 'stringio'
36
+
37
+ require 'jamie'
38
+ require 'jamie/driver/dummy'
39
+
40
+ # Nasty hack to redefine IO.read in terms of File#read for fakefs
41
+ class IO
42
+ def self.read(*args)
43
+ File.open(args[0], "rb") { |f| f.read(args[1]) }
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jamie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta3
4
+ version: 0.1.0.beta4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: net-ssh
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -260,7 +276,12 @@ files:
260
276
  - lib/jamie/thor_tasks.rb
261
277
  - lib/jamie/version.rb
262
278
  - lib/vendor/hash_recursive_merge.rb
263
- - spec/jamie_spec.rb
279
+ - spec/jamie/config/collection_spec.rb
280
+ - spec/jamie/config_spec.rb
281
+ - spec/jamie/instance_spec.rb
282
+ - spec/jamie/platform_spec.rb
283
+ - spec/jamie/suite_spec.rb
284
+ - spec/spec_helper.rb
264
285
  - templates/plugin/driver.rb.erb
265
286
  - templates/plugin/license_apachev2.erb
266
287
  - templates/plugin/license_gplv2.erb
@@ -294,5 +315,10 @@ signing_key:
294
315
  specification_version: 3
295
316
  summary: A Chef convergence integration test harness
296
317
  test_files:
297
- - spec/jamie_spec.rb
318
+ - spec/jamie/config/collection_spec.rb
319
+ - spec/jamie/config_spec.rb
320
+ - spec/jamie/instance_spec.rb
321
+ - spec/jamie/platform_spec.rb
322
+ - spec/jamie/suite_spec.rb
323
+ - spec/spec_helper.rb
298
324
  has_rdoc:
@@ -1,512 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
- #
5
- # Copyright (C) 2012, Fletcher Nichol
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 'simplecov'
20
- SimpleCov.adapters.define 'gem' do
21
- command_name 'Specs'
22
-
23
- add_filter '/spec/'
24
- add_filter '/lib/vendor/'
25
-
26
- add_group 'Libraries', '/lib/'
27
- end
28
- SimpleCov.start 'gem'
29
-
30
- require 'fakefs/spec_helpers'
31
- require 'logger'
32
- require 'minitest/autorun'
33
- require 'ostruct'
34
- require 'stringio'
35
-
36
- require 'jamie'
37
- require 'jamie/driver/dummy'
38
-
39
- # Nasty hack to redefine IO.read in terms of File#read for fakefs
40
- class IO
41
- def self.read(*args)
42
- File.open(args[0], "rb") { |f| f.read(args[1]) }
43
- end
44
- end
45
-
46
- describe Jamie::Config do
47
- include FakeFS::SpecHelpers
48
-
49
- let(:config) { Jamie::Config.new("/tmp/.jamie.yml") }
50
-
51
- before do
52
- FileUtils.mkdir_p("/tmp")
53
- end
54
-
55
- describe "#platforms" do
56
-
57
- it "returns platforms loaded from a jamie.yml" do
58
- stub_yaml!({'platforms' => [ { 'name' => 'one' }, { 'name' => 'two' } ]})
59
- config.platforms.size.must_equal 2
60
- config.platforms[0].name.must_equal 'one'
61
- config.platforms[1].name.must_equal 'two'
62
- end
63
-
64
- it "returns an empty Array if no platforms are given" do
65
- stub_yaml!({})
66
- config.platforms.must_equal []
67
- end
68
- end
69
-
70
- describe "#suites" do
71
-
72
- it "returns suites loaded from a jamie.yml" do
73
- stub_yaml!({'suites' => [
74
- { 'name' => 'one', 'run_list' => [] },
75
- { 'name' => 'two', 'run_list' => [] },
76
- ]})
77
- config.suites.size.must_equal 2
78
- config.suites[0].name.must_equal 'one'
79
- config.suites[1].name.must_equal 'two'
80
- end
81
-
82
- it "returns an empty Array if no suites are given" do
83
- stub_yaml!({})
84
- config.suites.must_equal []
85
- end
86
-
87
- it "returns a suite with nil for data_bags_path by default" do
88
- stub_yaml!({'suites' => [ { 'name' => 'one', 'run_list' => [] } ]})
89
- config.suites.first.data_bags_path.must_be_nil
90
- end
91
-
92
- it "retuns a suite with a common data_bags_path set" do
93
- stub_yaml!({'suites' => [ { 'name' => 'one', 'run_list' => [] } ]})
94
- config.test_base_path = "/tmp/base"
95
- FileUtils.mkdir_p "/tmp/base/data_bags"
96
- config.suites.first.data_bags_path.must_equal "/tmp/base/data_bags"
97
- end
98
-
99
- it "retuns a suite with a suite-specific data_bags_path set" do
100
- stub_yaml!({'suites' => [ { 'name' => 'cool', 'run_list' => [] } ]})
101
- config.test_base_path = "/tmp/base"
102
- FileUtils.mkdir_p "/tmp/base/cool/data_bags"
103
- config.suites.first.data_bags_path.must_equal "/tmp/base/cool/data_bags"
104
- end
105
-
106
- it "returns a suite with nil for roles_path by default" do
107
- stub_yaml!({'suites' => [ { 'name' => 'one', 'run_list' => [] } ]})
108
- config.suites.first.roles_path.must_be_nil
109
- end
110
-
111
- it "returns a suite with a common roles_path set" do
112
- stub_yaml!({'suites' => [ { 'name' => 'one', 'run_list' => [] } ]})
113
- config.test_base_path = "/tmp/base"
114
- FileUtils.mkdir_p "/tmp/base/roles"
115
- config.suites.first.roles_path.must_equal "/tmp/base/roles"
116
- end
117
-
118
- it "returns a suite with a suite-specific roles_path set" do
119
- stub_yaml!({'suites' => [ { 'name' => 'mysuite', 'run_list' => [] } ]})
120
- config.test_base_path = "/tmp/base"
121
- FileUtils.mkdir_p "/tmp/base/mysuite/roles"
122
- config.suites.first.roles_path.must_equal "/tmp/base/mysuite/roles"
123
- end
124
- end
125
-
126
- describe "#instances" do
127
-
128
- it "returns instances loaded from a jamie.yml" do
129
- stub_yaml!({
130
- 'platforms' => [
131
- { 'name' => 'p1' },
132
- { 'name' => 'p2' },
133
- ],
134
- 'suites' => [
135
- { 'name' => 's1', 'run_list' => [] },
136
- { 'name' => 's2', 'run_list' => [] },
137
- ]
138
- })
139
- config.instances.size.must_equal 4
140
- config.instances.map { |i| i.name }.must_equal %w{s1-p1 s1-p2 s2-p1 s2-p2}
141
- end
142
-
143
- it "returns an instance containing a driver instance" do
144
- stub_yaml!({
145
- 'platforms' => [ { 'name' => 'platform', 'driver_plugin' => 'dummy' } ],
146
- 'suites' => [ { 'name' => 'suite', 'run_list' => [] }]
147
- })
148
- config.instances.first.driver.must_be_instance_of Jamie::Driver::Dummy
149
- end
150
-
151
- it "returns an instance with a driver initialized with jamie_root" do
152
- stub_yaml!({
153
- 'platforms' => [ { 'name' => 'platform', 'driver_plugin' => 'dummy' } ],
154
- 'suites' => [ { 'name' => 'suite', 'run_list' => [] }]
155
- })
156
- config.instances.first.driver[:jamie_root].must_equal "/tmp"
157
- end
158
-
159
- it "returns an instance with a driver initialized with passed in config" do
160
- stub_yaml!({
161
- 'platforms' => [
162
- { 'name' => 'platform', 'driver_plugin' => 'dummy',
163
- 'driver_config' => { 'foo' => 'bar' } }
164
- ],
165
- 'suites' => [ { 'name' => 'suite', 'run_list' => [] }]
166
- })
167
- config.instances.first.driver[:foo].must_equal "bar"
168
- end
169
- end
170
-
171
- describe "jamie.local.yml" do
172
-
173
- it "merges in configuration with jamie.yml" do
174
- stub_yaml!(".jamie.yml", {
175
- 'platforms' => [ { 'name' => 'p1', 'driver_plugin' => 'dummy' } ],
176
- 'suites' => [ { 'name' => 's1', 'run_list' => [] } ]
177
- })
178
- stub_yaml!(".jamie.local.yml", {
179
- 'driver_config' => { 'foo' => 'bar' }
180
- })
181
- config.instances.first.driver[:foo].must_equal 'bar'
182
- end
183
-
184
- it "merges over configuration in jamie.yml" do
185
- stub_yaml!(".jamie.yml", {
186
- 'driver_config' => { 'foo' => 'nope' },
187
- 'platforms' => [ { 'name' => 'p1', 'driver_plugin' => 'dummy' } ],
188
- 'suites' => [ { 'name' => 's1', 'run_list' => [] } ]
189
- })
190
- stub_yaml!(".jamie.local.yml", {
191
- 'driver_config' => { 'foo' => 'bar' }
192
- })
193
- config.instances.first.driver[:foo].must_equal 'bar'
194
- end
195
- end
196
-
197
- describe "erb filtering" do
198
-
199
- it "evaluates jamie.yml through erb before loading" do
200
- FileUtils.mkdir_p "/tmp"
201
- File.open("/tmp/.jamie.yml", "wb") do |f|
202
- f.write <<-YAML.gsub(/^ {10}/, '')
203
- ---
204
- driver_plugin: dummy
205
- platforms:
206
- - name: <%= "AHH".downcase + "choo" %>
207
- YAML
208
- end
209
- config.platforms.first.name.must_equal "ahhchoo"
210
- end
211
-
212
- it "evaluates jamie.local.yml through erb before loading" do
213
- stub_yaml!({
214
- 'platforms' => [ { 'name' => 'p1', 'driver_plugin' => 'dummy' } ],
215
- 'suites' => [ { 'name' => 's1', 'run_list' => [] } ]
216
- })
217
- FileUtils.mkdir_p "/tmp"
218
- File.open("/tmp/.jamie.local.yml", "wb") do |f|
219
- f.write <<-YAML.gsub(/^ {10}/, '')
220
- ---
221
- driver_config:
222
- <% %w{noodle mushroom}.each do |kind| %>
223
- <%= kind %>: soup
224
- <% end %>
225
- YAML
226
- end
227
- config.instances.first.driver[:noodle].must_equal "soup"
228
- config.instances.first.driver[:mushroom].must_equal "soup"
229
- end
230
- end
231
-
232
- describe "#log_level" do
233
-
234
- it "returns a default log_level of info" do
235
- config.log_level.must_equal :info
236
- end
237
-
238
- it "returns an overridden log_level" do
239
- config.log_level = :error
240
- config.log_level.must_equal :error
241
- end
242
- end
243
-
244
- private
245
-
246
- def stub_yaml!(name = ".jamie.yml", hash)
247
- FileUtils.mkdir_p "/tmp"
248
- File.open("/tmp/#{name}", "wb") { |f| f.write(hash.to_yaml) }
249
- end
250
- end
251
-
252
- describe Jamie::Config::Collection do
253
-
254
- let(:collection) do
255
- Jamie::Config::Collection.new([
256
- obj('one'), obj('two', 'a'), obj('two', 'b'), obj('three')
257
- ])
258
- end
259
-
260
- it "transparently wraps an Array" do
261
- collection.must_be_instance_of Array
262
- end
263
-
264
- describe "#get" do
265
-
266
- it "returns a single object by its name" do
267
- collection.get('three').must_equal obj('three')
268
- end
269
-
270
- it "returns the first occurance of an object by its name" do
271
- collection.get('two').must_equal obj('two', 'a')
272
- end
273
-
274
- it "returns nil if an object cannot be found by its name" do
275
- collection.get('nope').must_be_nil
276
- end
277
- end
278
-
279
- describe "#get_all" do
280
-
281
- it "returns a Collection of objects whose name matches the regex" do
282
- result = collection.get_all(/(one|three)/)
283
- result.size.must_equal 2
284
- result[0].must_equal obj('one')
285
- result[1].must_equal obj('three')
286
- result.get_all(/one/).size.must_equal 1
287
- end
288
-
289
- it "returns an empty Collection if on matches are found" do
290
- result = collection.get_all(/noppa/)
291
- result.must_equal []
292
- result.get("nahuh").must_be_nil
293
- end
294
- end
295
-
296
- describe "#as_name" do
297
-
298
- it "returns an Array of names as strings" do
299
- collection.as_names.must_equal %w{one two two three}
300
- end
301
- end
302
-
303
- private
304
-
305
- def obj(name, extra = nil)
306
- OpenStruct.new(:name => name, :extra => extra)
307
- end
308
- end
309
-
310
- describe Jamie::Suite do
311
-
312
- let(:opts) do ; { :name => 'suitezy', :run_list => [ 'doowah' ] } ; end
313
- let(:suite) { Jamie::Suite.new(opts) }
314
-
315
- it "raises an ArgumentError if name is missing" do
316
- opts.delete(:name)
317
- proc { Jamie::Suite.new(opts) }.must_raise Jamie::ClientError
318
- end
319
-
320
- it "raises an ArgumentError if run_list is missing" do
321
- opts.delete(:run_list)
322
- proc { Jamie::Suite.new(opts) }.must_raise Jamie::ClientError
323
- end
324
-
325
- it "returns an empty Hash given no attributes" do
326
- suite.attributes.must_equal Hash.new
327
- end
328
-
329
- it "returns nil given no data_bags_path" do
330
- suite.data_bags_path.must_be_nil
331
- end
332
-
333
- it "returns nil given no roles_path" do
334
- suite.roles_path.must_be_nil
335
- end
336
-
337
- it "returns attributes from constructor" do
338
- opts.merge!({ :attributes => { :a => 'b' }, :data_bags_path => 'crazy',
339
- :roles_path => 'town' })
340
- suite.name.must_equal 'suitezy'
341
- suite.run_list.must_equal [ 'doowah' ]
342
- suite.attributes.must_equal({ :a => 'b' })
343
- suite.data_bags_path.must_equal 'crazy'
344
- suite.roles_path.must_equal 'town'
345
- end
346
- end
347
-
348
- describe Jamie::Platform do
349
-
350
- let(:opts) do ; { :name => 'plata' } ; end
351
- let(:platform) { Jamie::Platform.new(opts) }
352
-
353
- it "raises an ArgumentError if name is missing" do
354
- opts.delete(:name)
355
- proc { Jamie::Platform.new(opts) }.must_raise Jamie::ClientError
356
- end
357
-
358
- it "returns an empty Array given no run_list" do
359
- platform.run_list.must_equal []
360
- end
361
-
362
- it "returns an empty Hash given no attributes" do
363
- platform.attributes.must_equal Hash.new
364
- end
365
-
366
- it "returns attributes from constructor" do
367
- opts.merge!({ :run_list => [ 'a', 'b' ], :attributes => { :c => 'd' }})
368
- platform.name.must_equal 'plata'
369
- platform.run_list.must_equal [ 'a', 'b' ]
370
- platform.attributes.must_equal({ :c => 'd' })
371
- end
372
- end
373
-
374
- describe Jamie::Instance do
375
-
376
- let(:suite) do
377
- Jamie::Suite.new({ :name => 'suite',
378
- :run_list => 'suite_list', :attributes => { :s => 'ss' } })
379
- end
380
-
381
- let(:platform) do
382
- Jamie::Platform.new({ :name => 'platform',
383
- :run_list => 'platform_list', :attributes => { :p => 'pp' } })
384
- end
385
-
386
- let(:driver) { Jamie::Driver::Dummy.new({}) }
387
-
388
- let(:jr) { Jamie::Jr.new(suite.name) }
389
-
390
- let(:opts) do
391
- { :suite => suite, :platform => platform, :driver => driver, :jr => jr }
392
- end
393
-
394
- let(:instance) { Jamie::Instance.new(opts) }
395
-
396
- before do
397
- Celluloid.logger = Logger.new(StringIO.new)
398
- end
399
-
400
- it "raises an ArgumentError if suite is missing" do
401
- opts.delete(:suite)
402
- proc { Jamie::Instance.new(opts) }.must_raise Jamie::ClientError
403
- end
404
-
405
- it "raises an ArgumentError if platform is missing" do
406
- opts.delete(:platform)
407
- proc { Jamie::Instance.new(opts) }.must_raise Jamie::ClientError
408
- end
409
-
410
- it "returns suite" do
411
- instance.suite.must_equal suite
412
- end
413
-
414
- it "returns platform" do
415
- instance.platform.must_equal platform
416
- end
417
-
418
- it "returns an instance of Jr" do
419
- instance.jr.must_be_instance_of Jamie::Jr
420
- end
421
-
422
- describe "#name" do
423
-
424
- def combo(suite_name, platform_name)
425
- opts[:suite] = Jamie::Suite.new(
426
- :name => suite_name, :run_list => []
427
- )
428
- opts[:platform] = Jamie::Platform.new(
429
- :name => platform_name
430
- )
431
- Jamie::Instance.new(opts)
432
- end
433
-
434
- it "combines the suite and platform names with a dash" do
435
- combo('suite', 'platform').name.must_equal "suite-platform"
436
- end
437
-
438
- it "squashes periods" do
439
- combo('suite.ness', 'platform').name.must_equal "suiteness-platform"
440
- combo('suite', 'platform.s').name.must_equal "suite-platforms"
441
- combo('s.s.', '.p.p').name.must_equal "ss-pp"
442
- end
443
-
444
- it "transforms underscores to dashes" do
445
- combo('suite_ness', 'platform').name.must_equal "suite-ness-platform"
446
- combo('suite', 'platform-s').name.must_equal "suite-platform-s"
447
- combo('_s__s_', 'pp_').name.must_equal "-s--s--pp-"
448
- end
449
- end
450
-
451
- describe "#run_list" do
452
-
453
- def combo(suite_list, platform_list)
454
- opts[:suite] = Jamie::Suite.new(
455
- :name => 'suite', :run_list => suite_list
456
- )
457
- opts[:platform] = Jamie::Platform.new(
458
- :name => 'platform', :run_list => platform_list
459
- )
460
- Jamie::Instance.new(opts)
461
- end
462
-
463
- it "combines the platform then suite run_lists" do
464
- combo(%w{s1 s2}, %w{p1 p2}).run_list.must_equal %w{p1 p2 s1 s2}
465
- end
466
-
467
- it "uses the suite run_list only when platform run_list is empty" do
468
- combo(%w{sa sb}, nil).run_list.must_equal %w{sa sb}
469
- end
470
-
471
- it "returns an emtpy Array if both run_lists are empty" do
472
- combo([], nil).run_list.must_equal []
473
- end
474
- end
475
-
476
- describe "#attributes" do
477
-
478
- def combo(suite_attrs, platform_attrs)
479
- opts[:suite] = Jamie::Suite.new(
480
- :name => 'suite', :run_list => [], :attributes => suite_attrs
481
- )
482
- opts[:platform] = Jamie::Platform.new(
483
- :name => 'platform', :attributes => platform_attrs
484
- )
485
- Jamie::Instance.new(opts)
486
- end
487
-
488
- it "merges suite and platform hashes together" do
489
- combo(
490
- { :suite => { :s1 => 'sv1' } },
491
- { :suite => { :p1 => 'pv1' }, :platform => 'pp' }
492
- ).attributes.must_equal({
493
- :suite => { :s1 => 'sv1', :p1 => 'pv1' },
494
- :platform => 'pp'
495
- })
496
- end
497
-
498
- it "merges suite values over platform values" do
499
- combo(
500
- { :common => { :c1 => 'xxx' } },
501
- { :common => { :c1 => 'cv1', :c2 => 'cv2' } },
502
- ).attributes.must_equal({
503
- :common => { :c1 => 'xxx', :c2 => 'cv2' }
504
- })
505
- end
506
- end
507
-
508
- it "#dna combines attributes with the run_list" do
509
- instance.dna.must_equal({ :s => 'ss', :p => 'pp',
510
- :run_list => [ 'platform_list', 'suite_list' ] })
511
- end
512
- end