serverspec 0.4.0 → 0.4.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.
Files changed (40) hide show
  1. data/lib/serverspec/helper/type.rb +8 -2
  2. data/lib/serverspec/matchers/be_directory.rb +5 -1
  3. data/lib/serverspec/matchers/be_executable.rb +7 -3
  4. data/lib/serverspec/matchers/be_file.rb +5 -1
  5. data/lib/serverspec/matchers/be_grouped_into.rb +5 -1
  6. data/lib/serverspec/matchers/be_installed.rb +11 -7
  7. data/lib/serverspec/matchers/be_linked_to.rb +5 -1
  8. data/lib/serverspec/matchers/be_listening.rb +6 -2
  9. data/lib/serverspec/matchers/be_mode.rb +5 -1
  10. data/lib/serverspec/matchers/be_mounted.rb +5 -1
  11. data/lib/serverspec/matchers/be_owned_by.rb +5 -1
  12. data/lib/serverspec/matchers/be_readable.rb +7 -3
  13. data/lib/serverspec/matchers/be_writable.rb +7 -3
  14. data/lib/serverspec/matchers/contain.rb +9 -5
  15. data/lib/serverspec/matchers/match_md5checksum.rb +5 -1
  16. data/lib/serverspec/type/base.rb +14 -0
  17. data/lib/serverspec/type/file.rb +70 -0
  18. data/lib/serverspec/type/package.rb +19 -0
  19. data/lib/serverspec/type/port.rb +9 -0
  20. data/lib/serverspec/type/service.rb +1 -9
  21. data/lib/serverspec/version.rb +1 -1
  22. data/spec/darwin/file_spec.rb +40 -0
  23. data/spec/darwin/package_spec.rb +8 -0
  24. data/spec/darwin/port_spec.rb +7 -0
  25. data/spec/debian/file_spec.rb +39 -0
  26. data/spec/debian/package_spec.rb +9 -0
  27. data/spec/debian/port_spec.rb +7 -0
  28. data/spec/gentoo/file_spec.rb +40 -0
  29. data/spec/gentoo/package_spec.rb +9 -0
  30. data/spec/gentoo/port_spec.rb +7 -0
  31. data/spec/redhat/file_spec.rb +40 -0
  32. data/spec/redhat/package_spec.rb +9 -0
  33. data/spec/redhat/port_spec.rb +7 -0
  34. data/spec/solaris/file_spec.rb +40 -0
  35. data/spec/solaris/package_spec.rb +9 -0
  36. data/spec/solaris/port_spec.rb +7 -0
  37. data/spec/support/shared_file_examples.rb +557 -0
  38. data/spec/support/shared_package_examples.rb +41 -0
  39. data/spec/support/shared_port_examples.rb +11 -0
  40. metadata +42 -2
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Solaris
4
+
5
+ describe 'Serverspec service matchers of Solaris family' do
6
+ it_behaves_like 'support file be_file matcher', '/etc/ssh/sshd_config'
7
+ it_behaves_like 'support file be_directory matcher', '/etc/ssh'
8
+ it_behaves_like 'support file contain matcher', '/etc/ssh/sshd_config', 'This is the sshd server system-wide configuration file'
9
+ it_behaves_like 'support file contain from to matcher', 'Gemfile', 'rspec', /^group :test do/, /^end/
10
+ it_behaves_like 'support file contain after matcher', 'Gemfile', 'rspec', /^group :test do/
11
+ it_behaves_like 'support file contain before matcher', 'Gemfile', 'rspec', /^end/
12
+ it_behaves_like 'support file be_mode matcher', '/etc/passwd', 644
13
+ it_behaves_like 'support file be_owned_by matcher', '/etc/passwd', 'root'
14
+ it_behaves_like 'support file be_grouped_into matcher', '/etc/passwd', 'root'
15
+ it_behaves_like 'support file be_linked_to matcher', '/etc/pam.d/system-auth', '/etc/pam.d/system-auth-ac'
16
+
17
+ it_behaves_like 'support file be_readable matcher', '/dev'
18
+ it_behaves_like 'support file be_readable by owner matcher', '/dev'
19
+ it_behaves_like 'support file be_readable by group matcher', '/dev'
20
+ it_behaves_like 'support file be_readable by others matcher', '/dev'
21
+ it_behaves_like 'support file be_readable by specific user matcher', '/tmp', 'mail'
22
+
23
+ it_behaves_like 'support file be_writable matcher', '/dev'
24
+ it_behaves_like 'support file be_writable by owner matcher', '/dev'
25
+ it_behaves_like 'support file be_writable by group matcher', '/dev'
26
+ it_behaves_like 'support file be_writable by others matcher', '/dev'
27
+ it_behaves_like 'support file be_writable by specific user matcher', '/tmp', 'mail'
28
+
29
+ it_behaves_like 'support file be_executable matcher', '/dev'
30
+ it_behaves_like 'support file be_executable by owner matcher', '/dev'
31
+ it_behaves_like 'support file be_executable by group matcher', '/dev'
32
+ it_behaves_like 'support file be_executable by others matcher', '/dev'
33
+ it_behaves_like 'support file be_executable by specific user matcher', '/tmp', 'mail'
34
+
35
+ it_behaves_like 'support file be_mounted matcher', '/'
36
+ it_behaves_like 'support file be_mounted with matcher', '/'
37
+ it_behaves_like 'support file be_mounted only with matcher', '/'
38
+
39
+ it_behaves_like 'support file match_md5checksum matcher', '/etc/services', '35435ea447c19f0ea5ef971837ab9ced'
40
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Solaris
4
+
5
+ describe 'Serverspec package matchers of Solaris family' do
6
+ it_behaves_like 'support package installed matcher', 'httpd'
7
+ it_behaves_like 'support package installed by gem matcher', 'jekyll'
8
+ it_behaves_like 'support package installed by gem with version matcher', 'jekyll', '1.1.1'
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Solaris
4
+
5
+ describe 'Serverspec package matchers of Solaris family' do
6
+ it_behaves_like 'support port listening matcher', 80
7
+ end
@@ -0,0 +1,557 @@
1
+ shared_examples_for 'support file be_file matcher' do |name|
2
+ describe 'be_file' do
3
+ describe file(name) do
4
+ it { should be_file }
5
+ end
6
+
7
+ describe file('/etc/invalid_file') do
8
+ it { should_not be_file }
9
+ end
10
+ end
11
+ end
12
+
13
+ shared_examples_for 'support file be_directory matcher' do |name|
14
+ describe 'be_directory' do
15
+ describe file(name) do
16
+ it { should be_directory }
17
+ end
18
+
19
+ describe file('/etc/invalid_directory') do
20
+ it { should_not be_directory }
21
+ end
22
+ end
23
+ end
24
+
25
+ shared_examples_for 'support file contain matcher' do |name, pattern|
26
+ describe 'contain' do
27
+ describe file(name) do
28
+ it { should contain pattern }
29
+ end
30
+
31
+ describe file('/etc/ssh/sshd_config') do
32
+ it { should_not contain 'This is invalid text!!' }
33
+ end
34
+ end
35
+ end
36
+
37
+ shared_examples_for 'support file contain from to matcher' do |name, pattern, from, to|
38
+ describe 'contain' do
39
+ describe file(name) do
40
+ it { should contain(pattern).from(from).to(to) }
41
+ end
42
+
43
+ describe file('/etc/ssh/sshd_config') do
44
+ it { should_not contain('This is invalid text!!').from(from).to(to) }
45
+ end
46
+ end
47
+ end
48
+
49
+ shared_examples_for 'support file contain after matcher' do |name, pattern, after|
50
+ describe 'contain' do
51
+ describe file(name) do
52
+ it { should contain(pattern).after(after) }
53
+ end
54
+
55
+ describe file('/etc/ssh/sshd_config') do
56
+ it { should_not contain('This is invalid text!!').after(after) }
57
+ end
58
+ end
59
+ end
60
+
61
+ shared_examples_for 'support file contain before matcher' do |name, pattern, before|
62
+ describe 'contain' do
63
+ describe file(name) do
64
+ it { should contain(pattern).before(before) }
65
+ end
66
+
67
+ describe file('/etc/ssh/sshd_config') do
68
+ it { should_not contain('This is invalid text!!').before(before) }
69
+ end
70
+ end
71
+ end
72
+
73
+ shared_examples_for 'support file be_mode matcher' do |name, mode|
74
+ describe 'be_mode' do
75
+ describe file(name) do
76
+ it { should be_mode mode }
77
+ end
78
+
79
+ describe file('/etc/passwd') do
80
+ it { should_not be_mode 'invalid' }
81
+ end
82
+ end
83
+ end
84
+
85
+ shared_examples_for 'support file be_owned_by matcher' do |name, owner|
86
+ describe 'be_owned_by' do
87
+ describe file(name) do
88
+ it { should be_owned_by owner }
89
+ end
90
+
91
+ describe file('/etc/passwd') do
92
+ it { should_not be_owned_by 'invalid-owner' }
93
+ end
94
+ end
95
+ end
96
+
97
+ shared_examples_for 'support file be_grouped_into matcher' do |name, group|
98
+ describe 'be_grouped_into' do
99
+ describe file(name) do
100
+ it { should be_grouped_into group }
101
+ end
102
+
103
+ describe file('/etc/passwd') do
104
+ it { should_not be_grouped_into 'invalid-group' }
105
+ end
106
+ end
107
+ end
108
+
109
+ shared_examples_for 'support file be_linked_to matcher' do |name, target|
110
+ describe 'be_linked_to' do
111
+ describe file(name) do
112
+ it { should be_linked_to target }
113
+ end
114
+
115
+ describe file('dummy-link') do
116
+ it { should_not be_linked_to '/invalid/target' }
117
+ end
118
+ end
119
+ end
120
+
121
+ shared_examples_for 'support file be_readable matcher' do |name|
122
+ describe 'be_readable' do
123
+ describe file(name) do
124
+ before :all do
125
+ RSpec.configure do |c|
126
+ c.stdout = "755\r\n"
127
+ end
128
+ end
129
+ it { should be_readable }
130
+ end
131
+
132
+ describe file(name) do
133
+ before :all do
134
+ RSpec.configure do |c|
135
+ c.stdout = "333\r\n"
136
+ end
137
+ end
138
+ it { should_not be_readable }
139
+ end
140
+ end
141
+ end
142
+
143
+ shared_examples_for 'support file be_readable by owner matcher' do |name|
144
+ describe 'be_readable by owner' do
145
+ describe file(name) do
146
+ before :all do
147
+ RSpec.configure do |c|
148
+ c.stdout = "400\r\n"
149
+ end
150
+ end
151
+ it { should be_readable.by('owner') }
152
+ end
153
+
154
+ describe file(name) do
155
+ before :all do
156
+ RSpec.configure do |c|
157
+ c.stdout = "044\r\n"
158
+ end
159
+ end
160
+ it { should_not be_readable.by('owner') }
161
+ end
162
+ end
163
+ end
164
+
165
+ shared_examples_for 'support file be_readable by group matcher' do |name|
166
+ describe 'be_readable by group' do
167
+ describe file(name) do
168
+ before :all do
169
+ RSpec.configure do |c|
170
+ c.stdout = "040\r\n"
171
+ end
172
+ end
173
+ it { should be_readable.by('group') }
174
+ end
175
+
176
+ describe file(name) do
177
+ before :all do
178
+ RSpec.configure do |c|
179
+ c.stdout = "404\r\n"
180
+ end
181
+ end
182
+ it { should_not be_readable.by('group') }
183
+ end
184
+ end
185
+ end
186
+
187
+ shared_examples_for 'support file be_readable by others matcher' do |name|
188
+ describe 'be_readable by others' do
189
+ describe file(name) do
190
+ before :all do
191
+ RSpec.configure do |c|
192
+ c.stdout = "044\r\n"
193
+ end
194
+ end
195
+ it { should be_readable.by('others') }
196
+ end
197
+
198
+ describe file(name) do
199
+ before :all do
200
+ RSpec.configure do |c|
201
+ c.stdout = "443\r\n"
202
+ end
203
+ end
204
+ it { should_not be_readable.by('others') }
205
+ end
206
+ end
207
+ end
208
+
209
+ shared_examples_for 'support file be_readable by specific user matcher' do |name, user|
210
+ describe 'be_readable by specific user' do
211
+ describe file(name) do
212
+ it { should be_readable.by_user(user) }
213
+ end
214
+ describe file(name) do
215
+ it { should_not be_readable.by_user('invalid-user') }
216
+ end
217
+ end
218
+ end
219
+
220
+ shared_examples_for 'support file be_writable matcher' do |name|
221
+ describe 'be_writable' do
222
+ describe file(name) do
223
+ before :all do
224
+ RSpec.configure do |c|
225
+ c.stdout = "755\r\n"
226
+ end
227
+ end
228
+ it { should be_writable }
229
+ end
230
+
231
+ describe file(name) do
232
+ before :all do
233
+ RSpec.configure do |c|
234
+ c.stdout = "555\r\n"
235
+ end
236
+ end
237
+ it { should_not be_writable }
238
+ end
239
+ end
240
+ end
241
+
242
+ shared_examples_for 'support file be_writable by owner matcher' do |name|
243
+ describe 'be_writable_by_owner' do
244
+ describe file(name) do
245
+ before :all do
246
+ RSpec.configure do |c|
247
+ c.stdout = "200\r\n"
248
+ end
249
+ end
250
+ it { should be_writable.by('owner') }
251
+ end
252
+
253
+ describe file(name) do
254
+ before :all do
255
+ RSpec.configure do |c|
256
+ c.stdout = "555\r\n"
257
+ end
258
+ end
259
+ it { should_not be_writable.by('owner') }
260
+ end
261
+ end
262
+ end
263
+
264
+ shared_examples_for 'support file be_writable by group matcher' do |name|
265
+ describe 'be_writable_by_group' do
266
+ describe file(name) do
267
+ before :all do
268
+ RSpec.configure do |c|
269
+ c.stdout = "030\r\n"
270
+ end
271
+ end
272
+ it { should be_writable.by('group') }
273
+ end
274
+
275
+ describe file(name) do
276
+ before :all do
277
+ RSpec.configure do |c|
278
+ c.stdout = "555\r\n"
279
+ end
280
+ end
281
+ it { should_not be_writable.by('group') }
282
+ end
283
+ end
284
+ end
285
+
286
+ shared_examples_for 'support file be_writable by others matcher' do |name|
287
+ describe 'be_writable_by_others' do
288
+ describe file(name) do
289
+ before :all do
290
+ RSpec.configure do |c|
291
+ c.stdout = "666\r\n"
292
+ end
293
+ end
294
+ it { should be_writable.by('others') }
295
+ end
296
+
297
+ describe file(name) do
298
+ before :all do
299
+ RSpec.configure do |c|
300
+ c.stdout = "555\r\n"
301
+ end
302
+ end
303
+ it { should_not be_writable.by('others') }
304
+ end
305
+ end
306
+ end
307
+
308
+ shared_examples_for 'support file be_writable by specific user matcher' do |name, user|
309
+ describe 'be_writable by specific user' do
310
+ describe file(name) do
311
+ it { should be_writable.by_user(user) }
312
+ end
313
+ describe file(name) do
314
+ it { should_not be_writable.by_user('invalid-user') }
315
+ end
316
+ end
317
+ end
318
+
319
+ shared_examples_for 'support file be_executable matcher' do |name|
320
+ describe 'be_executable' do
321
+ describe file(name) do
322
+ before :all do
323
+ RSpec.configure do |c|
324
+ c.stdout = "755\r\n"
325
+ end
326
+ end
327
+ it { should be_executable }
328
+ end
329
+
330
+ describe file(name) do
331
+ before :all do
332
+ RSpec.configure do |c|
333
+ c.stdout = "666\r\n"
334
+ end
335
+ end
336
+ it { should_not be_executable }
337
+ end
338
+ end
339
+ end
340
+
341
+ shared_examples_for 'support file be_executable by owner matcher' do |name|
342
+ describe 'be_executable by owner' do
343
+ describe file(name) do
344
+ before :all do
345
+ RSpec.configure do |c|
346
+ c.stdout = "100\r\n"
347
+ end
348
+ end
349
+ it { should be_executable.by('owner') }
350
+ end
351
+
352
+ describe file(name) do
353
+ before :all do
354
+ RSpec.configure do |c|
355
+ c.stdout = "666\r\n"
356
+ end
357
+ end
358
+ it { should_not be_executable.by('owner') }
359
+ end
360
+ end
361
+ end
362
+
363
+ shared_examples_for 'support file be_executable by group matcher' do |name|
364
+ describe 'be_executable by group' do
365
+ describe file(name) do
366
+ before :all do
367
+ RSpec.configure do |c|
368
+ c.stdout = "070\r\n"
369
+ end
370
+ end
371
+ it { should be_executable.by('group') }
372
+ end
373
+
374
+ describe file(name) do
375
+ before :all do
376
+ RSpec.configure do |c|
377
+ c.stdout = "666\r\n"
378
+ end
379
+ end
380
+ it { should_not be_executable.by('group') }
381
+ end
382
+ end
383
+ end
384
+
385
+ shared_examples_for 'support file be_executable by others matcher' do |name|
386
+ describe 'be_executable by others' do
387
+ describe file(name) do
388
+ before :all do
389
+ RSpec.configure do |c|
390
+ c.stdout = "001\r\n"
391
+ end
392
+ end
393
+ it { should be_executable.by('others') }
394
+ end
395
+
396
+ describe file(name) do
397
+ before :all do
398
+ RSpec.configure do |c|
399
+ c.stdout = "666\r\n"
400
+ end
401
+ end
402
+ it { should_not be_executable.by('others') }
403
+ end
404
+ end
405
+ end
406
+
407
+ shared_examples_for 'support file be_executable by specific user matcher' do |name, user|
408
+ describe 'be_writable by specific user' do
409
+ describe file(name) do
410
+ it { should be_executable.by_user(user) }
411
+ end
412
+ describe file(name) do
413
+ it { should_not be_executable.by_user('invalid-user') }
414
+ end
415
+ end
416
+ end
417
+
418
+ shared_examples_for 'support file be_mounted matcher' do |name|
419
+ describe 'be_mounted' do
420
+ describe file(name) do
421
+ it { should be_mounted }
422
+ end
423
+
424
+ describe file('/etc/invalid-mount') do
425
+ it { should_not be_mounted }
426
+ end
427
+ end
428
+ end
429
+
430
+ shared_examples_for 'support file be_mounted with matcher' do |name|
431
+ describe 'be_mounted.with' do
432
+ before :all do
433
+ RSpec.configure do |c|
434
+ c.stdout = "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n"
435
+ end
436
+ end
437
+
438
+ describe file(name) do
439
+ it { should be_mounted.with( :type => 'ext4' ) }
440
+ end
441
+
442
+ describe file(name) do
443
+ it { should be_mounted.with( :type => 'ext4', :options => { :rw => true } ) }
444
+ end
445
+
446
+ describe file(name) do
447
+ it { should be_mounted.with( :type => 'ext4', :options => { :mode => 620 } ) }
448
+ end
449
+
450
+ describe file(name) do
451
+ it { should be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_root' ) }
452
+ end
453
+
454
+ describe file(name) do
455
+ it { should_not be_mounted.with( :type => 'xfs' ) }
456
+ end
457
+
458
+ describe file(name) do
459
+ it { should_not be_mounted.with( :type => 'ext4', :options => { :rw => false } ) }
460
+ end
461
+
462
+ describe file(name) do
463
+ it { should_not be_mounted.with( :type => 'ext4', :options => { :mode => 600 } ) }
464
+ end
465
+
466
+ describe file(name) do
467
+ it { should_not be_mounted.with( :type => 'xfs', :device => '/dev/mapper/VolGroup-lv_root' ) }
468
+ end
469
+
470
+ describe file(name) do
471
+ it { should_not be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_r00t' ) }
472
+ end
473
+
474
+ describe file('/etc/invalid-mount') do
475
+ it { should_not be_mounted.with( :type => 'ext4' ) }
476
+ end
477
+ end
478
+ end
479
+
480
+
481
+ shared_examples_for 'support file be_mounted only with matcher' do |name|
482
+ describe 'be_mounted.with' do
483
+ before :all do
484
+ RSpec.configure do |c|
485
+ c.stdout = "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n"
486
+ end
487
+ end
488
+
489
+ describe file(name) do
490
+ it do
491
+ should be_mounted.only_with(
492
+ :device => '/dev/mapper/VolGroup-lv_root',
493
+ :type => 'ext4',
494
+ :options => {
495
+ :rw => true,
496
+ :mode => 620,
497
+ }
498
+ )
499
+ end
500
+ end
501
+
502
+ describe file(name) do
503
+ it do
504
+ should_not be_mounted.only_with(
505
+ :device => '/dev/mapper/VolGroup-lv_root',
506
+ :type => 'ext4',
507
+ :options => {
508
+ :rw => true,
509
+ :mode => 620,
510
+ :bind => true,
511
+ }
512
+ )
513
+ end
514
+ end
515
+
516
+ describe file(name) do
517
+ it do
518
+ should_not be_mounted.only_with(
519
+ :device => '/dev/mapper/VolGroup-lv_root',
520
+ :type => 'ext4',
521
+ :options => {
522
+ :rw => true,
523
+ }
524
+ )
525
+ end
526
+ end
527
+
528
+ describe file(name) do
529
+ it do
530
+ should_not be_mounted.only_with(
531
+ :device => '/dev/mapper/VolGroup-lv_roooooooooot',
532
+ :type => 'ext4',
533
+ :options => {
534
+ :rw => true,
535
+ :mode => 620,
536
+ }
537
+ )
538
+ end
539
+ end
540
+
541
+ describe file('/etc/invalid-mount') do
542
+ it { should_not be_mounted.only_with( :type => 'ext4' ) }
543
+ end
544
+ end
545
+ end
546
+
547
+ shared_examples_for 'support file match_md5checksum matcher' do |name, pattern|
548
+ describe 'match_md5checksum' do
549
+ describe file(name) do
550
+ it { should match_md5checksum pattern }
551
+ end
552
+
553
+ describe file('invalid-file') do
554
+ it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' }
555
+ end
556
+ end
557
+ end
@@ -0,0 +1,41 @@
1
+ shared_examples_for 'support package installed matcher' do |name|
2
+ describe 'be_installed' do
3
+ describe package(name) do
4
+ it { should be_installed }
5
+ end
6
+
7
+ describe 'invalid-package' do
8
+ it { should_not be_installed }
9
+ end
10
+ end
11
+ end
12
+
13
+ shared_examples_for 'support package installed by gem matcher' do |name|
14
+ describe 'installed by gem' do
15
+ describe package(name) do
16
+ it { should be_installed.by('gem') }
17
+ end
18
+
19
+ describe 'invalid-gem' do
20
+ it { should_not be_installed.by('gem') }
21
+ end
22
+ end
23
+ end
24
+
25
+ shared_examples_for 'support package installed by gem with version matcher' do |name, version|
26
+ describe 'installed by gem with version' do
27
+ before :all do
28
+ RSpec.configure do |c|
29
+ c.stdout = "#{name} (#{version})"
30
+ end
31
+ end
32
+
33
+ describe package(name) do
34
+ it { should be_installed.by('gem').with_version(version) }
35
+ end
36
+
37
+ describe package(name) do
38
+ it { should_not be_installed.by('gem').with_version('invalid-version') }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ shared_examples_for 'support port listening matcher' do |num|
2
+ describe 'listening' do
3
+ describe port(num) do
4
+ it { should be_listening }
5
+ end
6
+
7
+ describe port('invalid') do
8
+ it { should_not be_listening }
9
+ end
10
+ end
11
+ end