rspec-puppet-womble 0.1.6.womble1 → 0.1.6.womble2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Gemfile +8 -0
  2. data/LICENSE +20 -0
  3. data/README.md +357 -0
  4. data/Rakefile +7 -0
  5. data/lib/rspec-puppet.rb +47 -0
  6. data/lib/rspec-puppet/errors.rb +46 -0
  7. data/lib/rspec-puppet/example.rb +27 -0
  8. data/lib/rspec-puppet/example/class_example_group.rb +10 -0
  9. data/lib/rspec-puppet/example/define_example_group.rb +10 -0
  10. data/lib/rspec-puppet/example/function_example_group.rb +46 -0
  11. data/lib/rspec-puppet/example/host_example_group.rb +10 -0
  12. data/lib/rspec-puppet/matchers.rb +6 -0
  13. data/lib/rspec-puppet/matchers/compile.rb +133 -0
  14. data/lib/rspec-puppet/matchers/count_generic.rb +73 -0
  15. data/lib/rspec-puppet/matchers/create_generic.rb +156 -0
  16. data/lib/rspec-puppet/matchers/dynamic_matchers.rb +17 -0
  17. data/lib/rspec-puppet/matchers/include_class.rb +19 -0
  18. data/lib/rspec-puppet/matchers/parameter_matcher.rb +110 -0
  19. data/lib/rspec-puppet/matchers/run.rb +94 -0
  20. data/lib/rspec-puppet/setup.rb +167 -0
  21. data/lib/rspec-puppet/support.rb +165 -0
  22. data/rspec-puppet-womble.gemspec +18 -0
  23. data/spec/classes/array_spec.rb +74 -0
  24. data/spec/classes/boolean_regexp_spec.rb +13 -0
  25. data/spec/classes/boolean_spec.rb +11 -0
  26. data/spec/classes/cycle_bad_spec.rb +5 -0
  27. data/spec/classes/cycle_good_spec.rb +5 -0
  28. data/spec/classes/escape_spec.rb +7 -0
  29. data/spec/classes/hash_spec.rb +68 -0
  30. data/spec/classes/sysctl_common_spec.rb +83 -0
  31. data/spec/defines/escape_def_spec.rb +8 -0
  32. data/spec/defines/sysctl_before_spec.rb +25 -0
  33. data/spec/defines/sysctl_spec.rb +21 -0
  34. data/spec/fixtures/manifests/site.pp +26 -0
  35. data/spec/fixtures/modules/boolean/manifests/init.pp +12 -0
  36. data/spec/fixtures/modules/cycle/manifests/bad.pp +8 -0
  37. data/spec/fixtures/modules/cycle/manifests/good.pp +7 -0
  38. data/spec/fixtures/modules/cycle/manifests/init.pp +0 -0
  39. data/spec/fixtures/modules/escape/manifests/def.pp +6 -0
  40. data/spec/fixtures/modules/escape/manifests/init.pp +6 -0
  41. data/spec/fixtures/modules/structured_data/manifests/def.pp +5 -0
  42. data/spec/fixtures/modules/structured_data/manifests/init.pp +5 -0
  43. data/spec/fixtures/modules/sysctl/manifests/init.pp +39 -0
  44. data/spec/functions/split_spec.rb +30 -0
  45. data/spec/hosts/bad_dep_host_spec.rb +5 -0
  46. data/spec/hosts/foo_spec.rb +6 -0
  47. data/spec/hosts/good_dep_host_spec.rb +5 -0
  48. data/spec/hosts/testhost_spec.rb +5 -0
  49. data/spec/spec_helper.rb +6 -0
  50. metadata +50 -1
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'rspec-puppet-womble'
3
+ s.version = '0.1.6.womble2'
4
+ s.homepage = 'https://github.com/mpalmer/rspec-puppet'
5
+ s.summary = 'RSpec tests for your Puppet manifests (updated by womble)'
6
+ s.description = "RSpec tests for your Puppet manifests. This is a forked "+
7
+ "gem, containing features merged but not yet released in the gems provided "+
8
+ "by the primary author."
9
+
10
+ s.executables = ['rspec-puppet-init']
11
+
12
+ s.files = `git ls-files|grep -v "^\\."`.split("\n")
13
+
14
+ s.add_dependency 'rspec'
15
+
16
+ s.authors = ['Tim Sharpe']
17
+ s.email = 'tim@sharpe.id.au'
18
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'structured_data' do
4
+ describe "with a single level array of strings" do
5
+ let(:params) do
6
+ {'data' => ['foo', 'bar', 'baz', 'quux']}
7
+ end
8
+
9
+ it {
10
+ should contain_structured_data__def('thing').with(
11
+ { 'data' => ['foo', 'bar', 'baz', 'quux'] }
12
+ )
13
+ }
14
+ end
15
+
16
+ describe "with integers as data values" do
17
+ let(:params) do
18
+ { 'data' => ['first', 1, 'second', 2] }
19
+ end
20
+
21
+ it {
22
+ should contain_structured_data__def('thing').with(
23
+ { 'data' => ['first', 1, 'second', 2] }
24
+ )
25
+ }
26
+ end
27
+
28
+ describe 'with nested arrays' do
29
+ let(:params) do
30
+ { 'data' => [
31
+ 'first',
32
+ 'second',
33
+ ['third', 'fourth'],
34
+ 5,
35
+ 6
36
+ ]
37
+ }
38
+ end
39
+
40
+ # Puppet 2.6 will automatically flatten nested arrays. If we're going
41
+ # to be testing recursive data structures, we might as well ensure that
42
+ # we're still handling numeric values correctly.
43
+ describe 'on Puppet 2.6', :if => Puppet.version =~ /^2\.6/ do
44
+ it {
45
+ should contain_structured_data__def('thing').with(
46
+ { 'data' => [
47
+ 'first',
48
+ 'second',
49
+ 'third',
50
+ 'fourth',
51
+ 5,
52
+ 6
53
+ ]
54
+ }
55
+ )
56
+ }
57
+ end
58
+
59
+ describe 'on Puppet 2.7 and later', :unless => Puppet.version =~ /^2\.6/ do
60
+ it {
61
+ should contain_structured_data__def('thing').with(
62
+ { 'data' => [
63
+ 'first',
64
+ 'second',
65
+ ['third', 'fourth'],
66
+ 5,
67
+ 6
68
+ ]
69
+ }
70
+ )
71
+ }
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'boolean' do
4
+ let(:title) { 'bool.testing' }
5
+ let(:params) { { :bool => false } }
6
+ let(:message_re) { /bool is false/ }
7
+
8
+ it { should create_notify("bool testing").with_message(message_re) }
9
+
10
+ # `should_not with_messsage` == `should without_message`
11
+ it { should_not create_notify("bool testing").with_message(/true/) }
12
+ it { should create_notify("bool testing").without_message(/true/) }
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ if Puppet::PUPPETVERSION !~ /0\.2/
4
+ describe 'boolean' do
5
+ let(:title) { 'bool.testing' }
6
+ let(:params) { { :bool => false } }
7
+
8
+ it { should create_notify("bool testing")\
9
+ .with_message("This will print when \$bool is false.") }
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'cycle::bad' do
4
+ it { should_not compile }
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'cycle::good' do
4
+ it { should compile }
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'escape' do
4
+ let(:params) { { :content => '$MSG foo' } }
5
+
6
+ it { should contain_file('/tmp/escape').with_content(/\$MSG foo/) }
7
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'structured_data' do
4
+ describe "with a single level hash of strings" do
5
+ let(:params) do
6
+ {'data' => {'foo' => 'bar', 'baz' => 'quux'}}
7
+ end
8
+
9
+ it {
10
+ should contain_structured_data__def('thing').with(
11
+ {'data' => {'foo' => 'bar', 'baz' => 'quux'}}
12
+ )
13
+ }
14
+ end
15
+
16
+ describe "with integers as keys" do
17
+ let(:params) do
18
+ { 'data' => {1 => 'uno', 2 => 'dos'}}
19
+ end
20
+
21
+ it {
22
+ should contain_structured_data__def('thing').with(
23
+ { 'data' => {1 => 'uno', 2 => 'dos'}}
24
+ )
25
+ }
26
+ end
27
+
28
+ describe 'with integers as values' do
29
+ let(:params) do
30
+ { 'data' => {'first' => 1, 'second' => 2}}
31
+ end
32
+
33
+ it {
34
+ should contain_structured_data__def('thing').with(
35
+ { 'data' => {'first' => 1, 'second' => 2}}
36
+ )
37
+ }
38
+ end
39
+
40
+ describe 'with nested hashes' do
41
+ let(:params) do
42
+ { 'data' => {
43
+ 'first' => 1,
44
+ 'second' => 2,
45
+ 'third' => {
46
+ 'alpha' => 'a',
47
+ 'beta' => 'b',
48
+ }
49
+ }
50
+ }
51
+ end
52
+
53
+ it {
54
+ should contain_structured_data__def('thing').with(
55
+ { 'data' => {
56
+ 'first' => 1,
57
+ 'second' => 2,
58
+ 'third' => {
59
+ 'alpha' => 'a',
60
+ 'beta' => 'b',
61
+ }
62
+ }
63
+ }
64
+ )
65
+ }
66
+ end
67
+ end
68
+
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'sysctl::common' do
4
+ it { should contain_exec('sysctl/reload') \
5
+ .with_command('/sbin/sysctl -p /etc/sysctl.conf').with_returns([0, 2]) }
6
+ it { should_not create_augeas('foo') }
7
+ describe 'when using with to specify a hash of parameters' do
8
+ it 'should fail if the parameter is not contained in the resource' do
9
+ expect do
10
+ subject.should contain_exec('sysctl/reload').with('foo' => 'bar')
11
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
12
+ end
13
+ it 'should pass if the parameters are contained in the resource' do
14
+ subject.should contain_exec('sysctl/reload').with(
15
+ 'refreshonly' => 'true',
16
+ 'returns' => [0, 2]
17
+ )
18
+ end
19
+ end
20
+ describe 'when using without to specify parameter name(s)' do
21
+ it 'should pass if the parameter name is not contained in the resource' do
22
+ subject.should contain_exec('sysctl/reload').without('foo')
23
+ end
24
+ it 'should pass if the parameter names are not contained in the resource' do
25
+ subject.should contain_exec('sysctl/reload').without(['foo', 'bar'])
26
+ end
27
+ it 'should fail if any of the parameter names are contained in the resource' do
28
+ expect do
29
+ subject.should contain_exec('sysctl/reload').without(['foo', 'returns'])
30
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
31
+ end
32
+ end
33
+ describe 'when using without to specify parameter value(s)' do
34
+ it 'should pass if the parameter value is not contained in the resource' do
35
+ subject.should contain_exec('sysctl/reload').without_refreshonly('false')
36
+ end
37
+ it 'should fail if the parameter value is contained in the resource' do
38
+ expect do
39
+ subject.should contain_exec('sysctl/reload').without_refreshonly('true')
40
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe 'sysctl::common' do
46
+ let(:params) { { :test_param => "yes" } }
47
+
48
+ it { should create_class("sysctl::common")\
49
+ .with_test_param("yes") }
50
+ it { should have_class_count(1) }
51
+ it { should have_exec_resource_count(1) }
52
+ it { should have_resource_count(1) }
53
+ end
54
+
55
+ describe 'sysctl::common' do
56
+ it { should contain_exec('sysctl/reload').only_with(
57
+ :command => '/sbin/sysctl -p /etc/sysctl.conf',
58
+ :refreshonly => true,
59
+ :returns => [0, 2]
60
+ )}
61
+ it { should contain_exec('sysctl/reload') \
62
+ .only_with_command('/sbin/sysctl -p /etc/sysctl.conf') \
63
+ .only_with_refreshonly(true) \
64
+ .only_with_returns([0, 2])
65
+ }
66
+ it 'should fail if not enough parameters are contained in the resource' do
67
+ expect do
68
+ subject.should contain_exec('sysctl/reload').only_with(
69
+ :command => '/sbin/sysctl -p /etc/sysctl.conf',
70
+ :returns => [0, 2]
71
+ )
72
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
73
+ end
74
+ it 'should fail if different parameters are contained in the resource' do
75
+ expect do
76
+ subject.should contain_exec('sysctl/reload').only_with(
77
+ :command => '/sbin/sysctl -p /etc/sysctl.conf',
78
+ :refreshonly => true,
79
+ :creates => '/tmp/bla'
80
+ )
81
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
82
+ end
83
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'escape::def' do
4
+ let(:title) { '/tmp/bla' }
5
+ let(:params) { {:content => 'bar $BLA'} }
6
+
7
+ it { should contain_file('/tmp/bla').with_content(/bar \$BLA/) }
8
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'sysctl::before' do
4
+ let(:title) { 'sysctl::before' }
5
+ let(:params) { { :value => "title" } }
6
+
7
+ it "Should raise an error about needing the sysctl::common class" do
8
+ expect { should create_notify("message-title")\
9
+ .with_message("This should print if the class is here first.") }\
10
+ .to raise_error(Puppet::Error, /Could not find resource 'Class\[Sysctl::Common\]/)
11
+ end
12
+ end
13
+
14
+ describe 'sysctl::before' do
15
+ let(:title) { 'test define' }
16
+ let(:pre_condition) {
17
+ [ '# we need sysctl common',
18
+ 'class {"sysctl::common":}' ] }
19
+ let(:params) { { :value => "title" } }
20
+
21
+ it { should create_sysctl__before('test define').with_value("title") }
22
+
23
+ it { should include_class("sysctl::common") }
24
+
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ nodoublequotes = Proc.new do |x|
4
+ not x =~ /"/
5
+ end
6
+
7
+ describe 'sysctl' do
8
+ let(:title) { 'vm.swappiness' }
9
+ let(:params) { {:value => '60'} }
10
+ let(:pre_condition) { }
11
+
12
+ it { should include_class('sysctl::common') }
13
+ it { should create_augeas('sysctl/vm.swappiness') \
14
+ .with_context('/files/etc/sysctl.conf') \
15
+ .with_changes("set vm.swappiness '60'") \
16
+ .with_changes(nodoublequotes) \
17
+ .with_onlyif("match vm.swappiness[.='60'] size == 0") \
18
+ .with_notify('Exec[sysctl/reload]')\
19
+ .without_foo }
20
+ it { should have_sysctl_resource_count(1) }
21
+ end
@@ -0,0 +1,26 @@
1
+ node default {
2
+ notify { 'test': }
3
+ }
4
+
5
+ node /testhost/ {
6
+ include sysctl::common
7
+ }
8
+
9
+ node 'good_dep_host' {
10
+ file { 'tmpdir':
11
+ alias => '/tmp',
12
+ path => '/tmp',
13
+ }
14
+ file { '/tmp/deptest1':
15
+ require => File['tmpdir'],
16
+ }
17
+ file { '/tmp/deptest2':
18
+ require => File['/tmp'],
19
+ }
20
+ }
21
+
22
+ node 'bad_dep_host' {
23
+ file { '/tmp':
24
+ require => File['/'],
25
+ }
26
+ }
@@ -0,0 +1,12 @@
1
+ class boolean($bool) {
2
+ $real_bool = $bool ? {
3
+ true => false,
4
+ false => true,
5
+ }
6
+
7
+ if ($real_bool) {
8
+ notify {"bool testing":
9
+ message => "This will print when \$bool is false."
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,8 @@
1
+ class cycle::bad {
2
+ notify {
3
+ 'foo':
4
+ require => Notify['bar'];
5
+ 'bar':
6
+ require => Notify['foo'];
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ class cycle::good {
2
+ notify {
3
+ 'foo':
4
+ require => Notify['bar'];
5
+ 'bar': ;
6
+ }
7
+ }
File without changes
@@ -0,0 +1,6 @@
1
+ define escape::def($content = '') {
2
+ file { $title :
3
+ ensure => file,
4
+ content => $content
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ class escape($content = '') {
2
+ file { '/tmp/escape':
3
+ ensure => file,
4
+ content => $content
5
+ }
6
+ }
@@ -0,0 +1,5 @@
1
+ define structured_data::def($data = {}) {
2
+ $template = inline_template('<%= data.inspect %>')
3
+
4
+ notify { "$template": }
5
+ }